Skip to content

Commit 05f61cb

Browse files
committed
start glint from sub folder
1 parent 3d266b9 commit 05f61cb

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

src/main/kotlin/com/emberjs/cli/EmberCliFrameworkDetector.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.intellij.openapi.application.ApplicationManager
1515
import com.intellij.openapi.fileTypes.FileType
1616
import com.intellij.openapi.module.ModuleUtilCore
1717
import com.intellij.openapi.project.Project
18+
import com.intellij.openapi.project.guessModuleDir
1819
import com.intellij.openapi.roots.ModifiableModelsProvider
1920
import com.intellij.openapi.roots.ModuleRootManager
2021
import com.intellij.openapi.roots.ui.configuration.ModulesProvider
@@ -97,7 +98,7 @@ class EmberCliFrameworkDetector : FrameworkDetector("Ember", 2) {
9798
} else if (rootDir != null) {
9899
context.project?.let {
99100
ApplicationManager.getApplication().invokeLaterOnWriteThread {
100-
getGlintDescriptor(it).ensureStarted()
101+
getGlintDescriptor(it).ensureStarted(rootDir)
101102
}
102103
}
103104
frameworkDescriptions.add(EmberFrameworkDescription(rootDir, newFiles, context.project!!))
@@ -144,7 +145,9 @@ class EmberCliFrameworkDetector : FrameworkDetector("Ember", 2) {
144145
val entry = MarkRootActionBase.findContentEntry(model, root)
145146
if (entry != null) {
146147
EmberCliProjectConfigurator.setupEmber(model.project, entry, root)
147-
getGlintDescriptor(model.project).ensureStarted()
148+
(module.guessModuleDir() ?: entry.file)?.let {
149+
getGlintDescriptor(model.project).ensureStarted(it)
150+
}
148151
modifiableModelsProvider.commitModuleModifiableModel(model)
149152
} else {
150153
modifiableModelsProvider.disposeModuleModifiableModel(model)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class GlintTypeScriptService(project: Project) : BaseLspTypeScriptService(projec
177177
override fun getSignatureHelp(file: PsiFile, context: CreateParameterInfoContext): Future<Stream<JSFunctionType>?>? = null
178178

179179
override fun isDisabledByContext(context: VirtualFile): Boolean {
180-
return getDescriptor()?.isAvailable?.not() ?: return true
180+
return getDescriptor()?.isAvailable(context)?.not() ?: return true
181181
}
182182

183183
override fun highlight(file: PsiFile): CompletableFuture<List<JSAnnotationError>>? {

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

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

33
import com.dmarcotte.handlebars.file.HbFileType
44
import com.emberjs.gts.GtsFileType
5+
import com.emberjs.utils.parentModule
56
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
67
import com.intellij.execution.configurations.GeneralCommandLine
78
import com.intellij.execution.process.OSProcessHandler
@@ -18,11 +19,13 @@ import com.intellij.openapi.project.Project
1819
import com.intellij.openapi.project.guessProjectDir
1920
import com.intellij.openapi.vfs.VfsUtilCore
2021
import com.intellij.openapi.vfs.VirtualFile
22+
import com.intellij.openapi.vfs.findPsiFile
2123
import com.intellij.platform.lsp.api.LspServerDescriptor
2224
import com.intellij.platform.lsp.api.LspServerManager
2325
import com.intellij.platform.lsp.api.LspServerSupportProvider
2426
import com.intellij.psi.PsiManager
2527
import com.intellij.util.FileContentUtil
28+
import java.io.File
2629
import java.net.URLEncoder
2730
import java.nio.charset.StandardCharsets
2831
import java.util.*
@@ -31,7 +34,7 @@ import kotlin.concurrent.schedule
3134
class GlintLspSupportProvider : LspServerSupportProvider {
3235
var willStart = false
3336
override fun fileOpened(project: Project, file: VirtualFile, serverStarter: LspServerSupportProvider.LspServerStarter) {
34-
if (!getGlintDescriptor(project).isAvailable) return
37+
if (!getGlintDescriptor(project).isAvailable(file)) return
3538
serverStarter.ensureServerStarted(getGlintDescriptor(project))
3639
}
3740
}
@@ -53,15 +56,17 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri
5356
get() =
5457
lspServerManager.getServersForProvider(GlintLspSupportProvider::class.java).firstOrNull()
5558

56-
val isAvailable: Boolean get() {
57-
val workingDir = project.guessProjectDir()!!
59+
fun isAvailableFromDir(file: VirtualFile): Boolean {
60+
val workingDir = file
5861
var isWsl = false
5962
if (workingDir.path.contains("wsl.localhost") || workingDir.path.contains("wsl\$")) {
6063
isWsl = true
6164
}
6265
if (isWsl) {
6366
val path = "./node_modules/@glint/core/bin/glint-language-server.js"
64-
val builder = ProcessBuilder().command("wsl", "--", "test", "-f", "\"$path\"", "||", "echo", "\"true\"")
67+
val builder = ProcessBuilder()
68+
.directory(File(workingDir.path))
69+
.command("wsl", "--", "test", "-f", "\"$path\"", "||", "echo", "\"true\"")
6570
val p = builder.start()
6671
p.waitFor()
6772
val out = p.inputStream.reader().readText().trim()
@@ -77,8 +82,18 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri
7782
return true
7883
}
7984

80-
fun ensureStarted() {
81-
if (!isAvailable) return
85+
fun isAvailable(vfile: VirtualFile): Boolean {
86+
if (vfile.parentModule != null && isAvailableFromDir(vfile.parentModule!!)) {
87+
return true
88+
}
89+
if (project.guessProjectDir() != null && isAvailableFromDir(project.guessProjectDir()!!)) {
90+
return true
91+
}
92+
return false
93+
}
94+
95+
fun ensureStarted(vfile: VirtualFile) {
96+
if (!isAvailable(vfile)) return
8297
lspServerManager.startServersIfNeeded(GlintLspSupportProvider::class.java)
8398
}
8499

0 commit comments

Comments
 (0)