Skip to content

Commit b7cb413

Browse files
authored
fix glint wsl (#334)
* fix glint wsl * fix glint wsl * fix glint wsl * fix glint wsl * fix glint wsl
1 parent 85466fc commit b7cb413

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ class GlintTypeScriptService(project: Project) : BaseLspTypeScriptService(projec
158158
return getNavigationFor(document, elem, false)
159159
}
160160

161+
override fun supportsInlayHints(file: PsiFile): Boolean {
162+
return this.canHighlight(file)
163+
}
164+
165+
override fun supportsTypeEvaluation(virtualFile: VirtualFile, element: PsiElement): Boolean {
166+
return this.isAcceptable(virtualFile)
167+
}
161168

162169
override fun getSignatureHelp(file: PsiFile, offset: Int): Future<Stream<JSFunctionType>?>? = null
163170

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

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
1010
import com.intellij.execution.configurations.GeneralCommandLine
1111
import com.intellij.execution.process.OSProcessHandler
1212
import com.intellij.execution.process.OSProcessUtil
13+
import com.intellij.execution.wsl.WSLUtil
14+
import com.intellij.execution.wsl.WslPath
15+
import com.intellij.execution.wsl.ijent.nio.IjentWslNioPath
1316
import com.intellij.javascript.nodejs.NodePackageVersionUtil
1417
import com.intellij.javascript.nodejs.PackageJsonData
1518
import com.intellij.javascript.nodejs.interpreter.NodeCommandLineConfigurator
1619
import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterRef
20+
import com.intellij.javascript.nodejs.interpreter.wsl.WslCommandLineConfigurator
1721
import com.intellij.javascript.nodejs.packages.NodePackageInfo
1822
import com.intellij.javascript.nodejs.packages.NodePackageUtil
1923
import com.intellij.javascript.nodejs.reference.NodeModuleManager
@@ -30,6 +34,7 @@ import com.intellij.openapi.util.NlsSafe
3034
import com.intellij.openapi.vfs.VfsUtil
3135
import com.intellij.openapi.vfs.VfsUtilCore
3236
import com.intellij.openapi.vfs.VirtualFile
37+
import com.intellij.openapi.vfs.VirtualFileManager
3338
import com.intellij.openapi.vfs.isFile
3439
import com.intellij.platform.lsp.api.LspServerDescriptor
3540
import com.intellij.platform.lsp.api.LspServerManager
@@ -43,6 +48,7 @@ import java.io.File
4348
import java.net.URL
4449
import java.net.URLEncoder
4550
import java.nio.charset.StandardCharsets
51+
import java.nio.file.spi.FileSystemProvider
4652
import java.util.*
4753
import kotlin.concurrent.schedule
4854
import kotlin.io.path.Path
@@ -75,9 +81,10 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri
7581

7682
fun isAvailableFromDir(file: VirtualFile): Boolean {
7783
val workingDir = file
78-
var isWsl = false
79-
if (workingDir.path.contains("wsl.localhost") || workingDir.path.contains("wsl\$")) {
84+
if (WslPath.isWslUncPath(workingDir.path)) {
8085
isWsl = true
86+
val wsl = WslPath.parseWindowsUncPath(workingDir.path)
87+
wslDistro = wsl?.wslRoot ?: ""
8188
}
8289
if (isWsl) {
8390
val path = "./node_modules/@glint/core/bin/glint-language-server.js"
@@ -88,7 +95,7 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri
8895
p.waitFor()
8996
val out = p.inputStream.reader().readText().trim()
9097
if (out == "true") {
91-
glintCoreDir = workingDir.findFileByRelativePath("node_modules/@glint/core")
98+
glintCoreDir = workingDir.findFileByRelativePath("node_modules/@glint/core") ?: return false
9299
return true
93100
}
94101
}
@@ -110,7 +117,12 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri
110117
var f = VfsUtil.findFile(Path(path), true)
111118
f = f?.findFileByRelativePath("bin/glint-language-server.js")
112119

113-
if (f != null) {
120+
if (f != null && f.exists()) {
121+
if (WslPath.isWslUncPath(f.path)) {
122+
isWsl = true
123+
val wsl = WslPath.parseWindowsUncPath(f.path)
124+
wslDistro = wsl?.wslRoot ?: ""
125+
}
114126
return true
115127
}
116128
}
@@ -144,28 +156,28 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri
144156
}
145157

146158
fun getGlintVersion(): String? {
147-
var path = glintCoreDir!!.findFileByRelativePath("package.json") ?: return null
148-
return PackageJsonData.getOrCreate(path).version?.rawVersion
159+
val config = GlintConfiguration.getInstance(myProject)
160+
val pkg = config.getPackage()
161+
val path = pkg.`package`.constantPackage?.systemIndependentPath ?: glintCoreDir?.path ?: return null
162+
val f = VirtualFileManager.getInstance().findFileByNioPath(Path(path).resolve("./package.json"))
163+
return PackageJsonData.getOrCreate(f!!).version?.rawVersion
149164
}
150165

151166
override fun createCommandLine(): GeneralCommandLine {
152167
val config = GlintConfiguration.getInstance(myProject)
153168
val pkg = config.getPackage()
154169
var path = pkg.`package`.constantPackage?.systemIndependentPath
155170
val dir = glintCoreDir ?: VfsUtil.findFile(Path(path!!), true)
156-
this.isWsl = false
157171

158172
var workDirectory = dir
159173
while (workDirectory != null && workDirectory.path.contains("node_modules")) {
160174
workDirectory = workDirectory.parent
161175
}
162176

163-
val wd = VfsUtilCore.virtualToIoFile(workDirectory!!)
164-
165177
val commandLine = GeneralCommandLine()
166178
.withCharset(StandardCharsets.UTF_8)
167179
.withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE)
168-
.withWorkDirectory(wd)
180+
.withWorkDirectory(workDirectory?.path)
169181

170182
ApplicationManager.getApplication().runReadAction {
171183
// val glintPkg = NodeModuleManager.getInstance(project).collectVisibleNodeModules(workingDir).find { it.name == "@glint/core" }?.virtualFile
@@ -180,10 +192,15 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri
180192
}
181193
}
182194

183-
184-
NodeCommandLineConfigurator
195+
if (isWsl) {
196+
WslCommandLineConfigurator
185197
.find(NodeJsInterpreterRef.createProjectRef().resolve(project)!!)
186198
.configure(commandLine)
199+
} else {
200+
NodeCommandLineConfigurator
201+
.find(NodeJsInterpreterRef.createProjectRef().resolve(project)!!)
202+
.configure(commandLine)
203+
}
187204
return commandLine
188205
}
189206

@@ -200,9 +217,17 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri
200217
return r;
201218
}
202219

220+
override fun findLocalFileByPath(path: String): VirtualFile? {
221+
if (this.isWsl && !path.startsWith(this.wslDistro.replace("\\", "/"))) {
222+
val uri = this.wslDistro.replace("\\", "/") + path
223+
return super.findLocalFileByPath(uri)
224+
}
225+
return super.findLocalFileByPath(path)
226+
}
227+
203228
override fun findFileByUri(fileUri: String): VirtualFile? {
204229
if (this.isWsl) {
205-
val uri = fileUri.replace("file://", "file://${this.wslDistro}")
230+
val uri = fileUri.replace("file://", "file://${this.wslDistro.replace("\\", "/")}")
206231
return super.findFileByUri(uri)
207232
}
208233
return super.findFileByUri(fileUri)

0 commit comments

Comments
 (0)