Skip to content

Commit 66b8747

Browse files
authored
fix random work dir for glint (#241)
1 parent 6aab13d commit 66b8747

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package com.emberjs.glint
22

33
import com.dmarcotte.handlebars.file.HbFileType
44
import com.emberjs.gts.GtsFileType
5+
import com.emberjs.utils.emberRoot
6+
import com.emberjs.utils.parentEmberModule
57
import com.emberjs.utils.parentModule
68
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
79
import com.intellij.execution.configurations.GeneralCommandLine
@@ -16,10 +18,9 @@ import com.intellij.openapi.Disposable
1618
import com.intellij.openapi.application.ApplicationManager
1719
import com.intellij.openapi.components.Service
1820
import com.intellij.openapi.project.Project
19-
import com.intellij.openapi.project.guessProjectDir
2021
import com.intellij.openapi.vfs.VfsUtilCore
2122
import com.intellij.openapi.vfs.VirtualFile
22-
import com.intellij.openapi.vfs.findPsiFile
23+
import com.intellij.openapi.vfs.isFile
2324
import com.intellij.platform.lsp.api.LspServerDescriptor
2425
import com.intellij.platform.lsp.api.LspServerManager
2526
import com.intellij.platform.lsp.api.LspServerSupportProvider
@@ -51,7 +52,7 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri
5152
val lspServerManager = LspServerManager.getInstance(project)
5253
var isWsl = false
5354
var wslDistro = ""
54-
var lastDir = project.guessProjectDir()
55+
var lastDir: VirtualFile? = null
5556

5657
public val server
5758
get() =
@@ -86,13 +87,20 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri
8687
}
8788

8889
fun isAvailable(vfile: VirtualFile): Boolean {
89-
if (vfile.parentModule != null && isAvailableFromDir(vfile.parentModule!!)) {
90-
return true
91-
}
92-
if (project.guessProjectDir() != null && isAvailableFromDir(project.guessProjectDir()!!)) {
93-
return true
90+
var f: VirtualFile? = vfile
91+
while (true) {
92+
if (f?.isFile == true) {
93+
f = f.parent
94+
}
95+
if (f?.path?.contains("node_modules") == true) {
96+
continue
97+
}
98+
if (f != null && isAvailableFromDir(f)) {
99+
return true
100+
}
101+
f = f?.parentEmberModule
102+
if (f == null) return false
94103
}
95-
return false
96104
}
97105

98106
fun ensureStarted(vfile: VirtualFile) {

0 commit comments

Comments
 (0)