@@ -2,6 +2,7 @@ package com.emberjs.glint
22
33import com.dmarcotte.handlebars.file.HbFileType
44import com.emberjs.gts.GtsFileType
5+ import com.emberjs.utils.parentModule
56import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
67import com.intellij.execution.configurations.GeneralCommandLine
78import com.intellij.execution.process.OSProcessHandler
@@ -18,11 +19,13 @@ import com.intellij.openapi.project.Project
1819import com.intellij.openapi.project.guessProjectDir
1920import com.intellij.openapi.vfs.VfsUtilCore
2021import com.intellij.openapi.vfs.VirtualFile
22+ import com.intellij.openapi.vfs.findPsiFile
2123import com.intellij.platform.lsp.api.LspServerDescriptor
2224import com.intellij.platform.lsp.api.LspServerManager
2325import com.intellij.platform.lsp.api.LspServerSupportProvider
2426import com.intellij.psi.PsiManager
2527import com.intellij.util.FileContentUtil
28+ import java.io.File
2629import java.net.URLEncoder
2730import java.nio.charset.StandardCharsets
2831import java.util.*
@@ -31,7 +34,7 @@ import kotlin.concurrent.schedule
3134class GlintLspSupportProvider : LspServerSupportProvider {
3235 var willStart = false
3336 override fun fileOpened (project : Project , file : VirtualFile , serverStarter : LspServerSupportProvider .LspServerStarter ) {
34- if (! getGlintDescriptor(project).isAvailable) return
37+ if (! getGlintDescriptor(project).isAvailable(file) ) return
3538 serverStarter.ensureServerStarted(getGlintDescriptor(project))
3639 }
3740}
@@ -53,15 +56,17 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri
5356 get() =
5457 lspServerManager.getServersForProvider(GlintLspSupportProvider ::class .java).firstOrNull()
5558
56- val isAvailable : Boolean get() {
57- val workingDir = project.guessProjectDir() !!
59+ fun isAvailableFromDir ( file : VirtualFile ): Boolean {
60+ val workingDir = file
5861 var isWsl = false
5962 if (workingDir.path.contains(" wsl.localhost" ) || workingDir.path.contains(" wsl\$ " )) {
6063 isWsl = true
6164 }
6265 if (isWsl) {
6366 val path = " ./node_modules/@glint/core/bin/glint-language-server.js"
64- val builder = ProcessBuilder ().command(" wsl" , " --" , " test" , " -f" , " \" $path \" " , " ||" , " echo" , " \" true\" " )
67+ val builder = ProcessBuilder ()
68+ .directory(File (workingDir.path))
69+ .command(" wsl" , " --" , " test" , " -f" , " \" $path \" " , " ||" , " echo" , " \" true\" " )
6570 val p = builder.start()
6671 p.waitFor()
6772 val out = p.inputStream.reader().readText().trim()
@@ -77,8 +82,18 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri
7782 return true
7883 }
7984
80- fun ensureStarted () {
81- if (! isAvailable) return
85+ fun isAvailable (vfile : VirtualFile ): Boolean {
86+ if (vfile.parentModule != null && isAvailableFromDir(vfile.parentModule!! )) {
87+ return true
88+ }
89+ if (project.guessProjectDir() != null && isAvailableFromDir(project.guessProjectDir()!! )) {
90+ return true
91+ }
92+ return false
93+ }
94+
95+ fun ensureStarted (vfile : VirtualFile ) {
96+ if (! isAvailable(vfile)) return
8297 lspServerManager.startServersIfNeeded(GlintLspSupportProvider ::class .java)
8398 }
8499
0 commit comments