Skip to content

Commit 91eafc5

Browse files
feat: Support new oxlint --lsp flag (#327)
1 parent 52867e6 commit 91eafc5

File tree

9 files changed

+90
-5
lines changed

9 files changed

+90
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- Added support for the upcoming 1.29.0 version of Oxlint which allows executing the language server through
10+
`oxlint --lsp`. When using automatic configuration, this will be accommodated without change when updating to
11+
a newer version of Oxlint. When using a manual configuration with a custom path to the language server, there is
12+
a new checkbox that will need to be checked after updating.
13+
714
## [0.0.19] - 2025-11-02
815

916
### Changed

sandbox/custom-config/.idea/OxcSettings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/kotlin/com/github/oxc/project/oxcintellijplugin/OxcPackage.kt

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.intellij.javascript.nodejs.util.NodePackage
77
import com.intellij.javascript.nodejs.util.NodePackageDescriptor
88
import com.intellij.openapi.project.Project
99
import com.intellij.openapi.vfs.VirtualFile
10+
import com.intellij.util.text.SemVer
1011
import java.nio.file.Paths
1112

1213
class OxcPackage(private val project: Project) {
@@ -59,22 +60,60 @@ class OxcPackage(private val project: Project) {
5960
}
6061
}
6162

63+
fun binaryParameters(virtualFile: VirtualFile): List<ProcessCommandParameter> {
64+
val settings = OxcSettings.getInstance(project)
65+
val configurationMode = settings.configurationMode
66+
67+
return when (configurationMode) {
68+
ConfigurationMode.DISABLED -> emptyList()
69+
ConfigurationMode.AUTOMATIC -> {
70+
findOxcParameters(virtualFile)
71+
}
72+
ConfigurationMode.MANUAL -> {
73+
if (settings.binaryPath.isBlank()) {
74+
findOxcParameters(virtualFile)
75+
} else {
76+
settings.binaryParameters.map { ProcessCommandParameter.Value(it) }
77+
}
78+
}
79+
}
80+
}
81+
6282
fun isEnabled(): Boolean {
6383
val settings = OxcSettings.getInstance(project)
6484
return settings.configurationMode != ConfigurationMode.DISABLED
6585
}
6686

67-
private fun findOxcExecutable(virtualFile: VirtualFile?): String? {
68-
val path = getPackage(virtualFile)?.getAbsolutePackagePathToRequire(project)
87+
private fun findOxcExecutable(virtualFile: VirtualFile): String? {
88+
val oxlintPackage = getPackage(virtualFile) ?: return null
89+
val path = oxlintPackage.getAbsolutePackagePathToRequire(project)
6990
if (path != null) {
70-
return Paths.get(path, "bin/oxc_language_server").toString()
91+
val version = oxlintPackage.getVersion(project)
92+
93+
return if (version?.isGreaterOrEqualThan(OXLINT_FIRST_LSP_VERSION) == true) {
94+
Paths.get(path, "bin/oxlint").toString()
95+
} else {
96+
Paths.get(path, "bin/oxc_language_server").toString()
97+
}
7198
}
7299

73100
return null
74101
}
75102

103+
private fun findOxcParameters(virtualFile: VirtualFile): List<ProcessCommandParameter> {
104+
val oxlintPackage = getPackage(virtualFile) ?: return emptyList()
105+
val version = oxlintPackage.getVersion(project)
106+
107+
return if (version?.isGreaterOrEqualThan(OXLINT_FIRST_LSP_VERSION) == true) {
108+
listOf(ProcessCommandParameter.Value("--lsp"))
109+
} else {
110+
emptyList()
111+
}
112+
}
113+
76114
companion object {
77115
const val CONFIG_NAME = ".oxlintrc"
116+
val OXLINT_FIRST_LSP_VERSION = SemVer("1.29.0", 1, 29, 0)
78117
val configValidExtensions = listOf("json")
79118
}
80119
}

src/main/kotlin/com/github/oxc/project/oxcintellijplugin/lsp/OxcLspServerDescriptor.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.github.oxc.project.oxcintellijplugin.lsp
33
import com.github.oxc.project.oxcintellijplugin.OxcPackage
44
import com.github.oxc.project.oxcintellijplugin.OxcTargetRun
55
import com.github.oxc.project.oxcintellijplugin.OxcTargetRunBuilder
6+
import com.github.oxc.project.oxcintellijplugin.ProcessCommandParameter
67
import com.github.oxc.project.oxcintellijplugin.settings.OxcSettings
78
import com.intellij.execution.configurations.GeneralCommandLine
89
import com.intellij.execution.process.OSProcessHandler
@@ -19,9 +20,10 @@ class OxcLspServerDescriptor(
1920
project: Project,
2021
root: VirtualFile,
2122
executable: String,
23+
executableParameters: List<ProcessCommandParameter>,
2224
) : LspServerDescriptor(project, "Oxc", root) {
2325
private val targetRun: OxcTargetRun = run {
24-
val builder = OxcTargetRunBuilder(project).getBuilder(executable).setWorkingDirectory(root.path)
26+
val builder = OxcTargetRunBuilder(project).getBuilder(executable).setWorkingDirectory(root.path).addParameters(executableParameters)
2527

2628
builder.build()
2729
}

src/main/kotlin/com/github/oxc/project/oxcintellijplugin/lsp/OxcLspServerSupportProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class OxcLspServerSupportProvider : LspServerSupportProvider {
3636
ProjectRootManager.getInstance(project).fileIndex.getContentRootForFile(file) ?: return
3737
}
3838

39-
serverStarter.ensureServerStarted(OxcLspServerDescriptor(project, root, executable))
39+
serverStarter.ensureServerStarted(OxcLspServerDescriptor(project, root, executable, oxc.binaryParameters(file)))
4040
}
4141

4242
override fun createLspServerWidgetItem(lspServer: LspServer,

src/main/kotlin/com/github/oxc/project/oxcintellijplugin/settings/OxcConfigurable.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,25 @@ class OxcConfigurable(private val project: Project) :
101101
project,
102102
) { it.path }.align(AlignX.FILL).bindText(settings::configPath)
103103
}.visibleIf(manualConfiguration.selected)
104+
105+
row {
106+
checkBox(OxcBundle.message("oxc.manual.add.lsp.argument")).bindSelected(
107+
{ settings.binaryParameters.contains("--lsp") },
108+
{ isChecked ->
109+
if (isChecked) {
110+
if (!settings.binaryParameters.contains("--lsp")) {
111+
settings.binaryParameters.add("--lsp")
112+
}
113+
} else {
114+
settings.binaryParameters.removeIf({ it == "--lsp" })
115+
}
116+
},
117+
)
118+
119+
val helpLabel = ContextHelpLabel.create(OxcBundle.message("oxc.manual.add.lsp.argument.help"))
120+
helpLabel.border = JBUI.Borders.emptyLeft(UIUtil.DEFAULT_HGAP)
121+
cell(helpLabel)
122+
}.visibleIf(manualConfiguration.selected)
104123
}
105124
}
106125

src/main/kotlin/com/github/oxc/project/oxcintellijplugin/settings/OxcSettings.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ class OxcSettings(private val project: Project) :
3838
state.binaryPath = value
3939
}
4040

41+
var binaryParameters: MutableList<String>
42+
get() = state.binaryParameters
43+
set(value) {
44+
state.binaryParameters.clear()
45+
state.binaryParameters.addAll(value)
46+
}
47+
4148
var configPath: String
4249
get() = state.configPath ?: ""
4350
set(value) {

src/main/kotlin/com/github/oxc/project/oxcintellijplugin/settings/OxcSettingsState.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class OxcSettingsState : BaseState() {
1717
@get:Attribute("binaryPath")
1818
var binaryPath by string()
1919

20+
@get:Attribute("binaryParameters")
21+
var binaryParameters by list<String>()
22+
2023
@get:Attribute("runTrigger")
2124
var runTrigger by enum(OxlintRunTrigger.ON_TYPE)
2225

src/main/resources/messages/OxcBundle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ oxc.type.aware.label=Enable type aware rules
3030
oxc.diagnostic.unknown.code=Unknown Code
3131
oxc.disable.nested.config.label=Disable nested config lookups
3232
oxc.fix.kind.label=Fix Kind
33+
oxc.manual.add.lsp.argument=Add --lsp CLI argument
34+
oxc.manual.add.lsp.argument.help=Oxlint 1.29.0 or newer had a change in architecture. As a result when manually configuring the LSP path to the `oxlint` executable (not the `oxc_language_server` executable), the IDE needs to know when to supply the new required --lsp flag. Checking this box will cause that flag to be supplied.

0 commit comments

Comments
 (0)