Skip to content

Commit 9ffc625

Browse files
committed
enable glint config and use specified path
1 parent ed4996d commit 9ffc625

File tree

2 files changed

+64
-12
lines changed

2 files changed

+64
-12
lines changed

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

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

33
import com.dmarcotte.handlebars.file.HbFileType
4+
import com.emberjs.gts.GlintConfiguration
45
import com.emberjs.gts.GtsFileType
56
import com.emberjs.utils.emberRoot
67
import com.emberjs.utils.parentEmberModule
@@ -26,20 +27,25 @@ import com.intellij.openapi.application.ApplicationManager
2627
import com.intellij.openapi.components.Service
2728
import com.intellij.openapi.project.Project
2829
import com.intellij.openapi.util.NlsSafe
30+
import com.intellij.openapi.vfs.VfsUtil
2931
import com.intellij.openapi.vfs.VfsUtilCore
3032
import com.intellij.openapi.vfs.VirtualFile
3133
import com.intellij.openapi.vfs.isFile
3234
import com.intellij.platform.lsp.api.LspServerDescriptor
3335
import com.intellij.platform.lsp.api.LspServerManager
3436
import com.intellij.platform.lsp.api.LspServerSupportProvider
37+
import com.intellij.psi.PsiFile
3538
import com.intellij.psi.PsiManager
39+
import com.intellij.psi.impl.file.impl.FileManager
3640
import com.intellij.util.FileContentUtil
3741
import org.eclipse.lsp4j.ServerInfo
3842
import java.io.File
43+
import java.net.URL
3944
import java.net.URLEncoder
4045
import java.nio.charset.StandardCharsets
4146
import java.util.*
4247
import kotlin.concurrent.schedule
48+
import kotlin.io.path.Path
4349

4450
class GlintLspSupportProvider : LspServerSupportProvider {
4551
var willStart = false
@@ -93,6 +99,15 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri
9399
}
94100

95101
fun isAvailable(vfile: VirtualFile): Boolean {
102+
val config = GlintConfiguration.getInstance(myProject)
103+
val pkg = config.getPackage()
104+
val path = pkg.`package`.constantPackage?.systemIndependentPath
105+
if (path != null && File(path).exists()) {
106+
val f = VfsUtil.findFile(Path(path), true)
107+
if (f != null) {
108+
return true
109+
}
110+
}
96111
var f: VirtualFile? = vfile
97112
while (true) {
98113
if (f?.isFile == true) {
@@ -133,6 +148,12 @@ class GlintLspServerDescriptor(private val myProject: Project) : LspServerDescri
133148
val workingDir = lastDir!!
134149
val workDirectory = VfsUtilCore.virtualToIoFile(workingDir)
135150
var path = workDirectory.path
151+
val config = GlintConfiguration.getInstance(myProject)
152+
val pkg = config.getPackage()
153+
val pkgPath = pkg.`package`.constantPackage?.systemIndependentPath
154+
if (pkgPath != null && File(pkgPath).exists()) {
155+
path = File(pkgPath).parentFile.parentFile.path
156+
}
136157
path = path.replace("\\", "/")
137158
this.isWsl = false
138159
if (path.startsWith("//wsl.localhost") || path.startsWith("//wsl\$")) {

src/main/kotlin/com/emberjs/gts/GlintExternalAnnotator.kt

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.emberjs.gts
22

3+
import TemplateLintState
34
import com.dmarcotte.handlebars.file.HbFileViewProvider
45
import com.emberjs.glint.GlintTypeScriptService
56
import com.emberjs.icons.EmberIcons
67
import com.intellij.CommonBundle
78
import com.intellij.ide.actionsOnSave.ActionOnSaveBackedByOwnConfigurable
89
import com.intellij.ide.actionsOnSave.ActionOnSaveContext
10+
import com.intellij.ide.actionsOnSave.ActionsOnSaveConfigurable
911
import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterField
1012
import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterRef
1113
import com.intellij.javascript.nodejs.util.JSLinterPackage
@@ -27,12 +29,17 @@ import com.intellij.psi.PsiFile
2729
import com.intellij.reference.SoftReference
2830
import com.intellij.ui.components.ActionLink
2931
import com.intellij.util.containers.ContainerUtil
32+
import com.intellij.util.ui.FormBuilder
33+
import com.intellij.util.ui.SwingHelper
3034
import org.jdom.Element
3135
import org.jetbrains.annotations.NonNls
3236
import org.jetbrains.annotations.PropertyKey
37+
import java.awt.Component
3338
import java.lang.ref.Reference
3439
import java.util.*
40+
import javax.swing.BorderFactory
3541
import javax.swing.JComponent
42+
import javax.swing.JPanel
3643

3744

3845
class GLintBundle {
@@ -88,7 +95,7 @@ data class GlintState(
8895
companion object {
8996
val DEFAULT = GlintState(
9097
NodeJsInterpreterRef.createProjectRef(),
91-
NodePackage("@glint/core"))
98+
NodePackage(""))
9299
}
93100
}
94101

@@ -97,8 +104,13 @@ data class GlintState(
97104
@State(name = "GlintConfiguration", storages = [Storage("emberLinters/glint.xml")])
98105
class GlintConfiguration(project: Project) : JSLinterConfiguration<GlintState>(project) {
99106
private val myPackage: JSLinterPackage = JSLinterPackage(project, "@glint/core")
107+
108+
public fun getPackage(): JSLinterPackage {
109+
return myPackage
110+
}
111+
100112
override fun savePrivateSettings(state: GlintState) {
101-
this.myPackage.force(NodePackageRef.create(state.interpreterRef.referenceName))
113+
this.myPackage.force(NodePackageRef.create(state.templateLintPackage))
102114
}
103115

104116
override fun loadPrivateSettings(state: GlintState): GlintState {
@@ -135,6 +147,10 @@ class GlintConfiguration(project: Project) : JSLinterConfiguration<GlintState>(p
135147
return parent
136148
}
137149

150+
companion object {
151+
fun getInstance(project: Project) = getInstance(project, GlintConfiguration::class.java)
152+
}
153+
138154
}
139155

140156

@@ -152,24 +168,39 @@ class GlintConfigurable(project: Project, fullModeDialog: Boolean = false) :
152168
return ID
153169
}
154170

155-
override fun createView(): JSLinterView<GlintState> {
156-
return object : JSLinterView<GlintState> {
171+
override fun createView(): JSLinterBaseView<GlintState> {
172+
return object : JSLinterBaseView<GlintState>() {
157173
private val myNodeInterpreterField: NodeJsInterpreterField = NodeJsInterpreterField(project, false)
158174
private val myTemplateLintPackageField: NodePackageField = NodePackageField(myNodeInterpreterField,
159175
"@glint/core"
160176
)
161-
var state: ExtendedLinterState<GlintState> = ExtendedLinterState(false, GlintState(
162-
myNodeInterpreterField.interpreterRef, myTemplateLintPackageField.selectedRef.constantPackage!!))
163-
override fun getComponent(): JComponent? {
164-
return null
177+
178+
private val panel = FormBuilder.createFormBuilder()
179+
.setHorizontalGap(10)
180+
.setVerticalGap(4)
181+
.setFormLeftIndent(10)
182+
.addLabeledComponent(GLintBundle.message("g.lint.node.path.label"), myNodeInterpreterField)
183+
.addLabeledComponent(GLintBundle.message("g.lint.package.label"), this.myTemplateLintPackageField)
184+
.panel
185+
186+
private val myCenterPanel: JPanel = SwingHelper.wrapWithHorizontalStretch(panel).apply {
187+
this.border = BorderFactory.createEmptyBorder(5, 0, 0, 0)
188+
}
189+
190+
override fun createCenterComponent(): Component {
191+
return myCenterPanel
165192
}
166193

167-
override fun getExtendedState(): ExtendedLinterState<GlintState> {
168-
return state
194+
override fun getState(): GlintState {
195+
return GlintState(
196+
myNodeInterpreterField.interpreterRef,
197+
myTemplateLintPackageField.selected
198+
)
169199
}
170200

171-
override fun setExtendedState(p0: ExtendedLinterState<GlintState>) {
172-
state = p0
201+
override fun setState(state: GlintState) {
202+
myNodeInterpreterField.interpreterRef = state.interpreterRef
203+
myTemplateLintPackageField.selected = state.nodePackageRef.constantPackage ?: GlintState.DEFAULT.nodePackageRef.constantPackage!!
173204
}
174205

175206
}

0 commit comments

Comments
 (0)