Skip to content

Commit 5a9d8e8

Browse files
authored
Merge pull request #133 from code-yeongyu/sync-lsp-with-opencode
feat(lsp): sync with OpenCode LSP implementation
2 parents a195b7c + 9e490d3 commit 5a9d8e8

File tree

3 files changed

+157
-44
lines changed

3 files changed

+157
-44
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export const DEFAULT_THRESHOLD = 0.80
1+
export const DEFAULT_THRESHOLD = 0.85
22
export const MIN_TOKENS_FOR_COMPACTION = 50_000
33
export const COMPACTION_COOLDOWN_MS = 60_000

src/tools/lsp/config.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,31 @@ export function isServerInstalled(command: string[]): boolean {
147147
if (command.length === 0) return false
148148

149149
const cmd = command[0]
150+
const isWindows = process.platform === "win32"
151+
const ext = isWindows ? ".exe" : ""
152+
150153
const pathEnv = process.env.PATH || ""
151-
const paths = pathEnv.split(":")
154+
const pathSeparator = isWindows ? ";" : ":"
155+
const paths = pathEnv.split(pathSeparator)
152156

153157
for (const p of paths) {
154-
if (existsSync(join(p, cmd))) {
158+
if (existsSync(join(p, cmd)) || existsSync(join(p, cmd + ext))) {
159+
return true
160+
}
161+
}
162+
163+
const cwd = process.cwd()
164+
const additionalPaths = [
165+
join(cwd, "node_modules", ".bin", cmd),
166+
join(cwd, "node_modules", ".bin", cmd + ext),
167+
join(homedir(), ".config", "opencode", "bin", cmd),
168+
join(homedir(), ".config", "opencode", "bin", cmd + ext),
169+
join(homedir(), ".config", "opencode", "node_modules", ".bin", cmd),
170+
join(homedir(), ".config", "opencode", "node_modules", ".bin", cmd + ext),
171+
]
172+
173+
for (const p of additionalPaths) {
174+
if (existsSync(p)) {
155175
return true
156176
}
157177
}

src/tools/lsp/constants.ts

Lines changed: 134 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export const DEFAULT_MAX_REFERENCES = 200
4040
export const DEFAULT_MAX_SYMBOLS = 200
4141
export const DEFAULT_MAX_DIAGNOSTICS = 200
4242

43+
// Synced with OpenCode's server.ts
44+
// https://github.com/sst/opencode/blob/main/packages/opencode/src/lsp/server.ts
4345
export const BUILTIN_SERVERS: Record<string, Omit<LSPServerConfig, "id">> = {
4446
typescript: {
4547
command: ["typescript-language-server", "--stdio"],
@@ -57,6 +59,17 @@ export const BUILTIN_SERVERS: Record<string, Omit<LSPServerConfig, "id">> = {
5759
command: ["vscode-eslint-language-server", "--stdio"],
5860
extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".vue"],
5961
},
62+
oxlint: {
63+
command: ["oxlint", "--lsp"],
64+
extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".vue", ".astro", ".svelte"],
65+
},
66+
biome: {
67+
command: ["biome", "lsp-proxy", "--stdio"],
68+
extensions: [
69+
".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts",
70+
".json", ".jsonc", ".vue", ".astro", ".svelte", ".css", ".graphql", ".gql", ".html",
71+
],
72+
},
6073
gopls: {
6174
command: ["gopls"],
6275
extensions: [".go"],
@@ -73,6 +86,10 @@ export const BUILTIN_SERVERS: Record<string, Omit<LSPServerConfig, "id">> = {
7386
command: ["pyright-langserver", "--stdio"],
7487
extensions: [".py", ".pyi"],
7588
},
89+
ty: {
90+
command: ["ty", "server"],
91+
extensions: [".py", ".pyi"],
92+
},
7693
ruff: {
7794
command: ["ruff", "server"],
7895
extensions: [".py", ".pyi"],
@@ -89,6 +106,10 @@ export const BUILTIN_SERVERS: Record<string, Omit<LSPServerConfig, "id">> = {
89106
command: ["csharp-ls"],
90107
extensions: [".cs"],
91108
},
109+
fsharp: {
110+
command: ["fsautocomplete"],
111+
extensions: [".fs", ".fsi", ".fsx", ".fsscript"],
112+
},
92113
"sourcekit-lsp": {
93114
command: ["sourcekit-lsp"],
94115
extensions: [".swift", ".objc", ".objcpp"],
@@ -133,64 +154,136 @@ export const BUILTIN_SERVERS: Record<string, Omit<LSPServerConfig, "id">> = {
133154
command: ["dart", "language-server", "--lsp"],
134155
extensions: [".dart"],
135156
},
157+
"terraform-ls": {
158+
command: ["terraform-ls", "serve"],
159+
extensions: [".tf", ".tfvars"],
160+
},
136161
}
137162

163+
// Synced with OpenCode's language.ts
164+
// https://github.com/sst/opencode/blob/main/packages/opencode/src/lsp/language.ts
138165
export const EXT_TO_LANG: Record<string, string> = {
166+
".abap": "abap",
167+
".bat": "bat",
168+
".bib": "bibtex",
169+
".bibtex": "bibtex",
170+
".clj": "clojure",
171+
".cljs": "clojure",
172+
".cljc": "clojure",
173+
".edn": "clojure",
174+
".coffee": "coffeescript",
175+
".c": "c",
176+
".cpp": "cpp",
177+
".cxx": "cpp",
178+
".cc": "cpp",
179+
".c++": "cpp",
180+
".cs": "csharp",
181+
".css": "css",
182+
".d": "d",
183+
".pas": "pascal",
184+
".pascal": "pascal",
185+
".diff": "diff",
186+
".patch": "diff",
187+
".dart": "dart",
188+
".dockerfile": "dockerfile",
189+
".ex": "elixir",
190+
".exs": "elixir",
191+
".erl": "erlang",
192+
".hrl": "erlang",
193+
".fs": "fsharp",
194+
".fsi": "fsharp",
195+
".fsx": "fsharp",
196+
".fsscript": "fsharp",
197+
".gitcommit": "git-commit",
198+
".gitrebase": "git-rebase",
199+
".go": "go",
200+
".groovy": "groovy",
201+
".gleam": "gleam",
202+
".hbs": "handlebars",
203+
".handlebars": "handlebars",
204+
".hs": "haskell",
205+
".html": "html",
206+
".htm": "html",
207+
".ini": "ini",
208+
".java": "java",
209+
".js": "javascript",
210+
".jsx": "javascriptreact",
211+
".json": "json",
212+
".jsonc": "jsonc",
213+
".tex": "latex",
214+
".latex": "latex",
215+
".less": "less",
216+
".lua": "lua",
217+
".makefile": "makefile",
218+
makefile: "makefile",
219+
".md": "markdown",
220+
".markdown": "markdown",
221+
".m": "objective-c",
222+
".mm": "objective-cpp",
223+
".pl": "perl",
224+
".pm": "perl",
225+
".pm6": "perl6",
226+
".php": "php",
227+
".ps1": "powershell",
228+
".psm1": "powershell",
229+
".pug": "jade",
230+
".jade": "jade",
139231
".py": "python",
140232
".pyi": "python",
233+
".r": "r",
234+
".cshtml": "razor",
235+
".razor": "razor",
236+
".rb": "ruby",
237+
".rake": "ruby",
238+
".gemspec": "ruby",
239+
".ru": "ruby",
240+
".erb": "erb",
241+
".html.erb": "erb",
242+
".js.erb": "erb",
243+
".css.erb": "erb",
244+
".json.erb": "erb",
245+
".rs": "rust",
246+
".scss": "scss",
247+
".sass": "sass",
248+
".scala": "scala",
249+
".shader": "shaderlab",
250+
".sh": "shellscript",
251+
".bash": "shellscript",
252+
".zsh": "shellscript",
253+
".ksh": "shellscript",
254+
".sql": "sql",
255+
".svelte": "svelte",
256+
".swift": "swift",
141257
".ts": "typescript",
142258
".tsx": "typescriptreact",
143259
".mts": "typescript",
144260
".cts": "typescript",
145-
".js": "javascript",
146-
".jsx": "javascriptreact",
261+
".mtsx": "typescriptreact",
262+
".ctsx": "typescriptreact",
263+
".xml": "xml",
264+
".xsl": "xsl",
265+
".yaml": "yaml",
266+
".yml": "yaml",
147267
".mjs": "javascript",
148268
".cjs": "javascript",
149-
".go": "go",
150-
".rs": "rust",
151-
".c": "c",
152-
".cpp": "cpp",
153-
".cc": "cpp",
154-
".cxx": "cpp",
155-
".c++": "cpp",
269+
".vue": "vue",
270+
".zig": "zig",
271+
".zon": "zig",
272+
".astro": "astro",
273+
".ml": "ocaml",
274+
".mli": "ocaml",
275+
".tf": "terraform",
276+
".tfvars": "terraform-vars",
277+
".hcl": "hcl",
278+
// Additional extensions not in OpenCode
156279
".h": "c",
157280
".hpp": "cpp",
158281
".hh": "cpp",
159282
".hxx": "cpp",
160283
".h++": "cpp",
161284
".objc": "objective-c",
162285
".objcpp": "objective-cpp",
163-
".java": "java",
164-
".rb": "ruby",
165-
".rake": "ruby",
166-
".gemspec": "ruby",
167-
".ru": "ruby",
168-
".lua": "lua",
169-
".swift": "swift",
170-
".cs": "csharp",
171-
".php": "php",
172-
".dart": "dart",
173-
".ex": "elixir",
174-
".exs": "elixir",
175-
".zig": "zig",
176-
".zon": "zig",
177-
".vue": "vue",
178-
".svelte": "svelte",
179-
".astro": "astro",
180-
".yaml": "yaml",
181-
".yml": "yaml",
182-
".json": "json",
183-
".jsonc": "jsonc",
184-
".html": "html",
185-
".htm": "html",
186-
".css": "css",
187-
".scss": "scss",
188-
".less": "less",
189-
".sh": "shellscript",
190-
".bash": "shellscript",
191-
".zsh": "shellscript",
192286
".fish": "fish",
193-
".md": "markdown",
194-
".tf": "terraform",
195-
".tfvars": "terraform",
287+
".graphql": "graphql",
288+
".gql": "graphql",
196289
}

0 commit comments

Comments
 (0)