Merge pull request #133 from code-yeongyu/sync-lsp-with-opencode

feat(lsp): sync with OpenCode LSP implementation
This commit is contained in:
YeonGyu-Kim
2025-12-20 14:04:49 +09:00
committed by GitHub
3 changed files with 157 additions and 44 deletions

View File

@@ -1,3 +1,3 @@
export const DEFAULT_THRESHOLD = 0.80 export const DEFAULT_THRESHOLD = 0.85
export const MIN_TOKENS_FOR_COMPACTION = 50_000 export const MIN_TOKENS_FOR_COMPACTION = 50_000
export const COMPACTION_COOLDOWN_MS = 60_000 export const COMPACTION_COOLDOWN_MS = 60_000

View File

@@ -147,11 +147,31 @@ export function isServerInstalled(command: string[]): boolean {
if (command.length === 0) return false if (command.length === 0) return false
const cmd = command[0] const cmd = command[0]
const isWindows = process.platform === "win32"
const ext = isWindows ? ".exe" : ""
const pathEnv = process.env.PATH || "" const pathEnv = process.env.PATH || ""
const paths = pathEnv.split(":") const pathSeparator = isWindows ? ";" : ":"
const paths = pathEnv.split(pathSeparator)
for (const p of paths) { for (const p of paths) {
if (existsSync(join(p, cmd))) { if (existsSync(join(p, cmd)) || existsSync(join(p, cmd + ext))) {
return true
}
}
const cwd = process.cwd()
const additionalPaths = [
join(cwd, "node_modules", ".bin", cmd),
join(cwd, "node_modules", ".bin", cmd + ext),
join(homedir(), ".config", "opencode", "bin", cmd),
join(homedir(), ".config", "opencode", "bin", cmd + ext),
join(homedir(), ".config", "opencode", "node_modules", ".bin", cmd),
join(homedir(), ".config", "opencode", "node_modules", ".bin", cmd + ext),
]
for (const p of additionalPaths) {
if (existsSync(p)) {
return true return true
} }
} }

View File

@@ -40,6 +40,8 @@ export const DEFAULT_MAX_REFERENCES = 200
export const DEFAULT_MAX_SYMBOLS = 200 export const DEFAULT_MAX_SYMBOLS = 200
export const DEFAULT_MAX_DIAGNOSTICS = 200 export const DEFAULT_MAX_DIAGNOSTICS = 200
// Synced with OpenCode's server.ts
// https://github.com/sst/opencode/blob/main/packages/opencode/src/lsp/server.ts
export const BUILTIN_SERVERS: Record<string, Omit<LSPServerConfig, "id">> = { export const BUILTIN_SERVERS: Record<string, Omit<LSPServerConfig, "id">> = {
typescript: { typescript: {
command: ["typescript-language-server", "--stdio"], command: ["typescript-language-server", "--stdio"],
@@ -57,6 +59,17 @@ export const BUILTIN_SERVERS: Record<string, Omit<LSPServerConfig, "id">> = {
command: ["vscode-eslint-language-server", "--stdio"], command: ["vscode-eslint-language-server", "--stdio"],
extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".vue"], extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".vue"],
}, },
oxlint: {
command: ["oxlint", "--lsp"],
extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".vue", ".astro", ".svelte"],
},
biome: {
command: ["biome", "lsp-proxy", "--stdio"],
extensions: [
".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts",
".json", ".jsonc", ".vue", ".astro", ".svelte", ".css", ".graphql", ".gql", ".html",
],
},
gopls: { gopls: {
command: ["gopls"], command: ["gopls"],
extensions: [".go"], extensions: [".go"],
@@ -73,6 +86,10 @@ export const BUILTIN_SERVERS: Record<string, Omit<LSPServerConfig, "id">> = {
command: ["pyright-langserver", "--stdio"], command: ["pyright-langserver", "--stdio"],
extensions: [".py", ".pyi"], extensions: [".py", ".pyi"],
}, },
ty: {
command: ["ty", "server"],
extensions: [".py", ".pyi"],
},
ruff: { ruff: {
command: ["ruff", "server"], command: ["ruff", "server"],
extensions: [".py", ".pyi"], extensions: [".py", ".pyi"],
@@ -89,6 +106,10 @@ export const BUILTIN_SERVERS: Record<string, Omit<LSPServerConfig, "id">> = {
command: ["csharp-ls"], command: ["csharp-ls"],
extensions: [".cs"], extensions: [".cs"],
}, },
fsharp: {
command: ["fsautocomplete"],
extensions: [".fs", ".fsi", ".fsx", ".fsscript"],
},
"sourcekit-lsp": { "sourcekit-lsp": {
command: ["sourcekit-lsp"], command: ["sourcekit-lsp"],
extensions: [".swift", ".objc", ".objcpp"], extensions: [".swift", ".objc", ".objcpp"],
@@ -133,26 +154,128 @@ export const BUILTIN_SERVERS: Record<string, Omit<LSPServerConfig, "id">> = {
command: ["dart", "language-server", "--lsp"], command: ["dart", "language-server", "--lsp"],
extensions: [".dart"], extensions: [".dart"],
}, },
"terraform-ls": {
command: ["terraform-ls", "serve"],
extensions: [".tf", ".tfvars"],
},
} }
// Synced with OpenCode's language.ts
// https://github.com/sst/opencode/blob/main/packages/opencode/src/lsp/language.ts
export const EXT_TO_LANG: Record<string, string> = { export const EXT_TO_LANG: Record<string, string> = {
".abap": "abap",
".bat": "bat",
".bib": "bibtex",
".bibtex": "bibtex",
".clj": "clojure",
".cljs": "clojure",
".cljc": "clojure",
".edn": "clojure",
".coffee": "coffeescript",
".c": "c",
".cpp": "cpp",
".cxx": "cpp",
".cc": "cpp",
".c++": "cpp",
".cs": "csharp",
".css": "css",
".d": "d",
".pas": "pascal",
".pascal": "pascal",
".diff": "diff",
".patch": "diff",
".dart": "dart",
".dockerfile": "dockerfile",
".ex": "elixir",
".exs": "elixir",
".erl": "erlang",
".hrl": "erlang",
".fs": "fsharp",
".fsi": "fsharp",
".fsx": "fsharp",
".fsscript": "fsharp",
".gitcommit": "git-commit",
".gitrebase": "git-rebase",
".go": "go",
".groovy": "groovy",
".gleam": "gleam",
".hbs": "handlebars",
".handlebars": "handlebars",
".hs": "haskell",
".html": "html",
".htm": "html",
".ini": "ini",
".java": "java",
".js": "javascript",
".jsx": "javascriptreact",
".json": "json",
".jsonc": "jsonc",
".tex": "latex",
".latex": "latex",
".less": "less",
".lua": "lua",
".makefile": "makefile",
makefile: "makefile",
".md": "markdown",
".markdown": "markdown",
".m": "objective-c",
".mm": "objective-cpp",
".pl": "perl",
".pm": "perl",
".pm6": "perl6",
".php": "php",
".ps1": "powershell",
".psm1": "powershell",
".pug": "jade",
".jade": "jade",
".py": "python", ".py": "python",
".pyi": "python", ".pyi": "python",
".r": "r",
".cshtml": "razor",
".razor": "razor",
".rb": "ruby",
".rake": "ruby",
".gemspec": "ruby",
".ru": "ruby",
".erb": "erb",
".html.erb": "erb",
".js.erb": "erb",
".css.erb": "erb",
".json.erb": "erb",
".rs": "rust",
".scss": "scss",
".sass": "sass",
".scala": "scala",
".shader": "shaderlab",
".sh": "shellscript",
".bash": "shellscript",
".zsh": "shellscript",
".ksh": "shellscript",
".sql": "sql",
".svelte": "svelte",
".swift": "swift",
".ts": "typescript", ".ts": "typescript",
".tsx": "typescriptreact", ".tsx": "typescriptreact",
".mts": "typescript", ".mts": "typescript",
".cts": "typescript", ".cts": "typescript",
".js": "javascript", ".mtsx": "typescriptreact",
".jsx": "javascriptreact", ".ctsx": "typescriptreact",
".xml": "xml",
".xsl": "xsl",
".yaml": "yaml",
".yml": "yaml",
".mjs": "javascript", ".mjs": "javascript",
".cjs": "javascript", ".cjs": "javascript",
".go": "go", ".vue": "vue",
".rs": "rust", ".zig": "zig",
".c": "c", ".zon": "zig",
".cpp": "cpp", ".astro": "astro",
".cc": "cpp", ".ml": "ocaml",
".cxx": "cpp", ".mli": "ocaml",
".c++": "cpp", ".tf": "terraform",
".tfvars": "terraform-vars",
".hcl": "hcl",
// Additional extensions not in OpenCode
".h": "c", ".h": "c",
".hpp": "cpp", ".hpp": "cpp",
".hh": "cpp", ".hh": "cpp",
@@ -160,37 +283,7 @@ export const EXT_TO_LANG: Record<string, string> = {
".h++": "cpp", ".h++": "cpp",
".objc": "objective-c", ".objc": "objective-c",
".objcpp": "objective-cpp", ".objcpp": "objective-cpp",
".java": "java",
".rb": "ruby",
".rake": "ruby",
".gemspec": "ruby",
".ru": "ruby",
".lua": "lua",
".swift": "swift",
".cs": "csharp",
".php": "php",
".dart": "dart",
".ex": "elixir",
".exs": "elixir",
".zig": "zig",
".zon": "zig",
".vue": "vue",
".svelte": "svelte",
".astro": "astro",
".yaml": "yaml",
".yml": "yaml",
".json": "json",
".jsonc": "jsonc",
".html": "html",
".htm": "html",
".css": "css",
".scss": "scss",
".less": "less",
".sh": "shellscript",
".bash": "shellscript",
".zsh": "shellscript",
".fish": "fish", ".fish": "fish",
".md": "markdown", ".graphql": "graphql",
".tf": "terraform", ".gql": "graphql",
".tfvars": "terraform",
} }