Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/kotlin/com/emberjs/glint/GlintLanguageService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Stream<JSFunctionType>?>? = null

Expand Down
55 changes: 41 additions & 14 deletions src/main/kotlin/com/emberjs/glint/GlintLspSupportProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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
}

Expand All @@ -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
}
}
Expand Down Expand Up @@ -142,28 +156,28 @@ 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 {
val config = GlintConfiguration.getInstance(myProject)
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
Expand All @@ -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
}

Expand All @@ -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)
Expand Down
Loading