Skip to content

Commit

Permalink
start glint from sub folder (#195)
Browse files Browse the repository at this point in the history
* start glint from sub folder

* start glint from sub folder

* fix version
  • Loading branch information
patricklx authored Oct 28, 2024
1 parent 3d266b9 commit 421245e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ dependencies {
// and https://www.jetbrains.com/intellij-repository/snapshots/
// https://plugins.jetbrains.com/plugin/6884-handlebars-mustache/versions/stable
intellijPlatform {
plugins(listOf("com.dmarcotte.handlebars:243.15521.24"))
plugins(listOf("com.dmarcotte.handlebars:242.21829.3"))
bundledPlugins(listOf("JavaScript", "com.intellij.css", "org.jetbrains.plugins.yaml"))
pluginVerifier()
zipSigner()
instrumentationTools()
testFramework(TestFrameworkType.Platform)
create(IntelliJPlatformType.IntellijIdeaUltimate, "243.15521.24")
create(IntelliJPlatformType.IntellijIdeaUltimate, "2024.2.4")
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/main/kotlin/com/emberjs/cli/EmberCliFrameworkDetector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.fileTypes.FileType
import com.intellij.openapi.module.ModuleUtilCore
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessModuleDir
import com.intellij.openapi.roots.ModifiableModelsProvider
import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.roots.ui.configuration.ModulesProvider
Expand Down Expand Up @@ -97,7 +98,7 @@ class EmberCliFrameworkDetector : FrameworkDetector("Ember", 2) {
} else if (rootDir != null) {
context.project?.let {
ApplicationManager.getApplication().invokeLaterOnWriteThread {
getGlintDescriptor(it).ensureStarted()
getGlintDescriptor(it).ensureStarted(rootDir)
}
}
frameworkDescriptions.add(EmberFrameworkDescription(rootDir, newFiles, context.project!!))
Expand Down Expand Up @@ -144,7 +145,9 @@ class EmberCliFrameworkDetector : FrameworkDetector("Ember", 2) {
val entry = MarkRootActionBase.findContentEntry(model, root)
if (entry != null) {
EmberCliProjectConfigurator.setupEmber(model.project, entry, root)
getGlintDescriptor(model.project).ensureStarted()
(module.guessModuleDir() ?: entry.file)?.let {
getGlintDescriptor(model.project).ensureStarted(it)
}
modifiableModelsProvider.commitModuleModifiableModel(model)
} else {
modifiableModelsProvider.disposeModuleModifiableModel(model)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/emberjs/glint/GlintLanguageService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class GlintTypeScriptService(project: Project) : BaseLspTypeScriptService(projec
override fun getSignatureHelp(file: PsiFile, context: CreateParameterInfoContext): Future<Stream<JSFunctionType>?>? = null

override fun isDisabledByContext(context: VirtualFile): Boolean {
return getDescriptor()?.isAvailable?.not() ?: return true
return getDescriptor()?.isAvailable(context)?.not() ?: return true
}

override fun highlight(file: PsiFile): CompletableFuture<List<JSAnnotationError>>? {
Expand Down
32 changes: 25 additions & 7 deletions src/main/kotlin/com/emberjs/glint/GlintLspSupportProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.emberjs.glint

import com.dmarcotte.handlebars.file.HbFileType
import com.emberjs.gts.GtsFileType
import com.emberjs.utils.parentModule
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.execution.process.OSProcessHandler
Expand All @@ -18,11 +19,13 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.vfs.VfsUtilCore
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.findPsiFile
import com.intellij.platform.lsp.api.LspServerDescriptor
import com.intellij.platform.lsp.api.LspServerManager
import com.intellij.platform.lsp.api.LspServerSupportProvider
import com.intellij.psi.PsiManager
import com.intellij.util.FileContentUtil
import java.io.File
import java.net.URLEncoder
import java.nio.charset.StandardCharsets
import java.util.*
Expand All @@ -31,7 +34,7 @@ import kotlin.concurrent.schedule
class GlintLspSupportProvider : LspServerSupportProvider {
var willStart = false
override fun fileOpened(project: Project, file: VirtualFile, serverStarter: LspServerSupportProvider.LspServerStarter) {
if (!getGlintDescriptor(project).isAvailable) return
if (!getGlintDescriptor(project).isAvailable(file)) return
serverStarter.ensureServerStarted(getGlintDescriptor(project))
}
}
Expand All @@ -48,24 +51,28 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri
val lspServerManager = LspServerManager.getInstance(project)
var isWsl = false
var wslDistro = ""
var lastDir = project.guessProjectDir()

public val server
get() =
lspServerManager.getServersForProvider(GlintLspSupportProvider::class.java).firstOrNull()

val isAvailable: Boolean get() {
val workingDir = project.guessProjectDir()!!
fun isAvailableFromDir(file: VirtualFile): Boolean {
val workingDir = file
var isWsl = false
if (workingDir.path.contains("wsl.localhost") || workingDir.path.contains("wsl\$")) {
isWsl = true
}
if (isWsl) {
val path = "./node_modules/@glint/core/bin/glint-language-server.js"
val builder = ProcessBuilder().command("wsl", "--", "test", "-f", "\"$path\"", "||", "echo", "\"true\"")
val builder = ProcessBuilder()
.directory(File(workingDir.path))
.command("wsl", "--", "test", "-f", "\"$path\"", "||", "echo", "\"true\"")
val p = builder.start()
p.waitFor()
val out = p.inputStream.reader().readText().trim()
if (out == "true") {
lastDir = workingDir
return true
}
}
Expand All @@ -74,16 +81,27 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri
return false
}
glintPkg.findFileByRelativePath("bin/glint-language-server.js") ?: return false
lastDir = workingDir
return true
}

fun ensureStarted() {
if (!isAvailable) return
fun isAvailable(vfile: VirtualFile): Boolean {
if (vfile.parentModule != null && isAvailableFromDir(vfile.parentModule!!)) {
return true
}
if (project.guessProjectDir() != null && isAvailableFromDir(project.guessProjectDir()!!)) {
return true
}
return false
}

fun ensureStarted(vfile: VirtualFile) {
if (!isAvailable(vfile)) return
lspServerManager.startServersIfNeeded(GlintLspSupportProvider::class.java)
}

override fun createCommandLine(): GeneralCommandLine {
val workingDir = myProject.guessProjectDir()!!
val workingDir = lastDir!!
val workDirectory = VfsUtilCore.virtualToIoFile(workingDir)
var path = workDirectory.path
path = path.replace("\\", "/")
Expand Down

0 comments on commit 421245e

Please sign in to comment.