Skip to content

Commit eb2b719

Browse files
committed
show glint version
1 parent 2e44489 commit eb2b719

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/main/kotlin/com/emberjs/glint/GlintLanguageService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class GlintTypeScriptService(project: Project) : BaseLspTypeScriptService(projec
8383
return if (EmberUtils.isEnabledEmberProject(project)) getGlintDescriptor(project) else null
8484
}
8585

86-
override val name = "Glint TypeScript LSP"
86+
override val name = "Glint"
8787

8888
override fun getCompletionMergeStrategy(parameters: CompletionParameters, file: PsiFile, context: PsiElement): TypeScriptService.CompletionMergeStrategy {
8989
return TypeScriptLanguageServiceUtil.getCompletionMergeStrategy(parameters, file, context)

src/main/kotlin/com/emberjs/glint/GlintLspSupportProvider.kt

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,23 @@ import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
99
import com.intellij.execution.configurations.GeneralCommandLine
1010
import com.intellij.execution.process.OSProcessHandler
1111
import com.intellij.execution.process.OSProcessUtil
12+
import com.intellij.javascript.nodejs.NodePackageVersionUtil
13+
import com.intellij.javascript.nodejs.PackageJsonData
1214
import com.intellij.javascript.nodejs.interpreter.NodeCommandLineConfigurator
1315
import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterRef
16+
import com.intellij.javascript.nodejs.packages.NodePackageInfo
17+
import com.intellij.javascript.nodejs.packages.NodePackageUtil
1418
import com.intellij.javascript.nodejs.reference.NodeModuleManager
19+
import com.intellij.javascript.nodejs.settings.NodePackageInfoManager
20+
import com.intellij.javascript.nodejs.util.NodePackage
21+
import com.intellij.javascript.nodejs.util.NodePackageDescriptor
1522
import com.intellij.lang.javascript.JavaScriptFileType
1623
import com.intellij.lang.javascript.TypeScriptFileType
1724
import com.intellij.openapi.Disposable
1825
import com.intellij.openapi.application.ApplicationManager
1926
import com.intellij.openapi.components.Service
2027
import com.intellij.openapi.project.Project
28+
import com.intellij.openapi.util.NlsSafe
2129
import com.intellij.openapi.vfs.VfsUtilCore
2230
import com.intellij.openapi.vfs.VirtualFile
2331
import com.intellij.openapi.vfs.isFile
@@ -26,6 +34,7 @@ import com.intellij.platform.lsp.api.LspServerManager
2634
import com.intellij.platform.lsp.api.LspServerSupportProvider
2735
import com.intellij.psi.PsiManager
2836
import com.intellij.util.FileContentUtil
37+
import org.eclipse.lsp4j.ServerInfo
2938
import java.io.File
3039
import java.net.URLEncoder
3140
import java.nio.charset.StandardCharsets
@@ -36,7 +45,7 @@ class GlintLspSupportProvider : LspServerSupportProvider {
3645
var willStart = false
3746
override fun fileOpened(project: Project, file: VirtualFile, serverStarter: LspServerSupportProvider.LspServerStarter) {
3847
if (!getGlintDescriptor(project).isAvailable(file)) return
39-
serverStarter.ensureServerStarted(getGlintDescriptor(project))
48+
getGlintDescriptor(project).ensureStarted(file)
4049
}
4150
}
4251

@@ -46,7 +55,7 @@ fun getGlintDescriptor(project: Project): GlintLspServerDescriptor {
4655
}
4756

4857

49-
@Service
58+
@Service(Service.Level.PROJECT)
5059
class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescriptor(myProject, "Glint"), Disposable {
5160
val psiManager = PsiManager.getInstance(myProject)
5261
val lspServerManager = LspServerManager.getInstance(project)
@@ -103,7 +112,21 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri
103112

104113
fun ensureStarted(vfile: VirtualFile) {
105114
if (!isAvailable(vfile)) return
106-
lspServerManager.startServersIfNeeded(GlintLspSupportProvider::class.java)
115+
lspServerManager.ensureServerStarted(GlintLspSupportProvider::class.java, getGlintDescriptor(project))
116+
server?.let {
117+
if (it.initializeResult?.serverInfo == null) {
118+
it.initializeResult?.serverInfo = ServerInfo()
119+
}
120+
it.initializeResult?.serverInfo?.name = "Glint"
121+
it.initializeResult?.serverInfo?.version = getGlintVersion()
122+
}
123+
}
124+
125+
fun getGlintVersion(): String? {
126+
val workingDir = lastDir!!
127+
val workDirectory = VfsUtilCore.virtualToIoFile(workingDir)
128+
var path = workingDir.findFileByRelativePath("node_modules/@glint/core/package.json") ?: return null
129+
return PackageJsonData.getOrCreate(path).version?.rawVersion
107130
}
108131

109132
override fun createCommandLine(): GeneralCommandLine {

0 commit comments

Comments
 (0)