diff --git a/src/main/kotlin/com/emberjs/glint/GlintLanguageService.kt b/src/main/kotlin/com/emberjs/glint/GlintLanguageService.kt index fd7d939b..4eb5283f 100644 --- a/src/main/kotlin/com/emberjs/glint/GlintLanguageService.kt +++ b/src/main/kotlin/com/emberjs/glint/GlintLanguageService.kt @@ -158,6 +158,13 @@ class GlintTypeScriptService(project: Project) : BaseLspTypeScriptService(projec return getNavigationFor(document, elem, false) } + override fun supportsInlayHints(file: PsiFile): Boolean { + return this.canHighlight(file) + } + + override fun supportsTypeEvaluation(virtualFile: VirtualFile, element: PsiElement): Boolean { + return this.isAcceptable(virtualFile) + } override fun getSignatureHelp(file: PsiFile, offset: Int): Future?>? = null diff --git a/src/main/kotlin/com/emberjs/glint/GlintLspSupportProvider.kt b/src/main/kotlin/com/emberjs/glint/GlintLspSupportProvider.kt index 91a44fab..36f0fb5d 100644 --- a/src/main/kotlin/com/emberjs/glint/GlintLspSupportProvider.kt +++ b/src/main/kotlin/com/emberjs/glint/GlintLspSupportProvider.kt @@ -10,10 +10,14 @@ import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer import com.intellij.execution.configurations.GeneralCommandLine import com.intellij.execution.process.OSProcessHandler import com.intellij.execution.process.OSProcessUtil +import com.intellij.execution.wsl.WSLUtil +import com.intellij.execution.wsl.WslPath +import com.intellij.execution.wsl.ijent.nio.IjentWslNioPath import com.intellij.javascript.nodejs.NodePackageVersionUtil import com.intellij.javascript.nodejs.PackageJsonData import com.intellij.javascript.nodejs.interpreter.NodeCommandLineConfigurator import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterRef +import com.intellij.javascript.nodejs.interpreter.wsl.WslCommandLineConfigurator import com.intellij.javascript.nodejs.packages.NodePackageInfo import com.intellij.javascript.nodejs.packages.NodePackageUtil import com.intellij.javascript.nodejs.reference.NodeModuleManager @@ -30,6 +34,7 @@ import com.intellij.openapi.util.NlsSafe import com.intellij.openapi.vfs.VfsUtil import com.intellij.openapi.vfs.VfsUtilCore import com.intellij.openapi.vfs.VirtualFile +import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.openapi.vfs.isFile import com.intellij.platform.lsp.api.LspServerDescriptor import com.intellij.platform.lsp.api.LspServerManager @@ -43,6 +48,7 @@ import java.io.File import java.net.URL import java.net.URLEncoder import java.nio.charset.StandardCharsets +import java.nio.file.spi.FileSystemProvider import java.util.* import kotlin.concurrent.schedule import kotlin.io.path.Path @@ -75,9 +81,10 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri fun isAvailableFromDir(file: VirtualFile): Boolean { val workingDir = file - var isWsl = false - if (workingDir.path.contains("wsl.localhost") || workingDir.path.contains("wsl\$")) { + if (WslPath.isWslUncPath(workingDir.path)) { isWsl = true + val wsl = WslPath.parseWindowsUncPath(workingDir.path) + wslDistro = wsl?.wslRoot ?: "" } if (isWsl) { val path = "./node_modules/@glint/core/bin/glint-language-server.js" @@ -88,12 +95,13 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri p.waitFor() val out = p.inputStream.reader().readText().trim() if (out == "true") { - glintCoreDir = workingDir.findFileByRelativePath("node_modules/@glint/core") + glintCoreDir = workingDir.findFileByRelativePath("node_modules/@glint/core") ?: return false return true } } val glintPkg = workingDir.findFileByRelativePath("node_modules/@glint/core") ?: return false glintPkg.findFileByRelativePath("bin/glint-language-server.js") ?: return false + glintCoreDir = glintPkg return true } @@ -106,9 +114,15 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri pkg.readOrDetect() val path = pkg.`package`.constantPackage?.systemIndependentPath if (path != null) { - val f = VfsUtil.findFile(Path(path), true) + var f = VfsUtil.findFile(Path(path), true) + f = f?.findFileByRelativePath("bin/glint-language-server.js") - if (f != null) { + if (f != null && f.exists()) { + if (WslPath.isWslUncPath(f.path)) { + isWsl = true + val wsl = WslPath.parseWindowsUncPath(f.path) + wslDistro = wsl?.wslRoot ?: "" + } return true } } @@ -142,8 +156,11 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri } fun getGlintVersion(): String? { - var path = glintCoreDir!!.findFileByRelativePath("package.json") ?: return null - return PackageJsonData.getOrCreate(path).version?.rawVersion + val config = GlintConfiguration.getInstance(myProject) + val pkg = config.getPackage() + val path = pkg.`package`.constantPackage?.systemIndependentPath ?: glintCoreDir?.path ?: return null + val f = VirtualFileManager.getInstance().findFileByNioPath(Path(path).resolve("./package.json")) + return PackageJsonData.getOrCreate(f!!).version?.rawVersion } override fun createCommandLine(): GeneralCommandLine { @@ -151,19 +168,16 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri val pkg = config.getPackage() var path = pkg.`package`.constantPackage?.systemIndependentPath val dir = glintCoreDir ?: VfsUtil.findFile(Path(path!!), true) - this.isWsl = false var workDirectory = dir while (workDirectory != null && workDirectory.path.contains("node_modules")) { workDirectory = workDirectory.parent } - val wd = VfsUtilCore.virtualToIoFile(workDirectory!!) - val commandLine = GeneralCommandLine() .withCharset(StandardCharsets.UTF_8) .withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE) - .withWorkDirectory(wd) + .withWorkDirectory(workDirectory?.path) ApplicationManager.getApplication().runReadAction { // val glintPkg = NodeModuleManager.getInstance(project).collectVisibleNodeModules(workingDir).find { it.name == "@glint/core" }?.virtualFile @@ -178,10 +192,15 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri } } - - NodeCommandLineConfigurator + if (isWsl) { + WslCommandLineConfigurator .find(NodeJsInterpreterRef.createProjectRef().resolve(project)!!) .configure(commandLine) + } else { + NodeCommandLineConfigurator + .find(NodeJsInterpreterRef.createProjectRef().resolve(project)!!) + .configure(commandLine) + } return commandLine } @@ -198,9 +217,17 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri return r; } + override fun findLocalFileByPath(path: String): VirtualFile? { + if (this.isWsl && !path.startsWith(this.wslDistro.replace("\\", "/"))) { + val uri = this.wslDistro.replace("\\", "/") + path + return super.findLocalFileByPath(uri) + } + return super.findLocalFileByPath(path) + } + override fun findFileByUri(fileUri: String): VirtualFile? { if (this.isWsl) { - val uri = fileUri.replace("file://", "file://${this.wslDistro}") + val uri = fileUri.replace("file://", "file://${this.wslDistro.replace("\\", "/")}") return super.findFileByUri(uri) } return super.findFileByUri(fileUri)