Files
oh-my-openagent/src/tools/lsp/constants.ts
Sisyphus 4d66ea9730 fix(lsp): improve error messages when LSP server is not installed (#305)
Previously, when an LSP server was configured but not installed, the error
message said "No LSP server configured" which was misleading. Now the
error message distinguishes between:

1. Server not configured at all
2. Server configured but not installed (with installation hints)

The new error messages include:
- Clear indication of whether server is configured vs installed
- Installation commands for each built-in server
- Supported file extensions
- Configuration examples for custom servers

Fixes #304

Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
2025-12-28 17:38:23 +09:00

321 lines
7.9 KiB
TypeScript

import type { LSPServerConfig } from "./types"
export const SYMBOL_KIND_MAP: Record<number, string> = {
1: "File",
2: "Module",
3: "Namespace",
4: "Package",
5: "Class",
6: "Method",
7: "Property",
8: "Field",
9: "Constructor",
10: "Enum",
11: "Interface",
12: "Function",
13: "Variable",
14: "Constant",
15: "String",
16: "Number",
17: "Boolean",
18: "Array",
19: "Object",
20: "Key",
21: "Null",
22: "EnumMember",
23: "Struct",
24: "Event",
25: "Operator",
26: "TypeParameter",
}
export const SEVERITY_MAP: Record<number, string> = {
1: "error",
2: "warning",
3: "information",
4: "hint",
}
export const DEFAULT_MAX_REFERENCES = 200
export const DEFAULT_MAX_SYMBOLS = 200
export const DEFAULT_MAX_DIAGNOSTICS = 200
export const LSP_INSTALL_HINTS: Record<string, string> = {
typescript: "npm install -g typescript-language-server typescript",
deno: "Install Deno from https://deno.land",
vue: "npm install -g @vue/language-server",
eslint: "npm install -g vscode-langservers-extracted",
oxlint: "npm install -g oxlint",
biome: "npm install -g @biomejs/biome",
gopls: "go install golang.org/x/tools/gopls@latest",
"ruby-lsp": "gem install ruby-lsp",
basedpyright: "pip install basedpyright",
pyright: "pip install pyright",
ty: "pip install ty",
ruff: "pip install ruff",
"elixir-ls": "See https://github.com/elixir-lsp/elixir-ls",
zls: "See https://github.com/zigtools/zls",
csharp: "dotnet tool install -g csharp-ls",
fsharp: "dotnet tool install -g fsautocomplete",
"sourcekit-lsp": "Included with Xcode or Swift toolchain",
rust: "rustup component add rust-analyzer",
clangd: "See https://clangd.llvm.org/installation",
svelte: "npm install -g svelte-language-server",
astro: "npm install -g @astrojs/language-server",
"bash-ls": "npm install -g bash-language-server",
jdtls: "See https://github.com/eclipse-jdtls/eclipse.jdt.ls",
"yaml-ls": "npm install -g yaml-language-server",
"lua-ls": "See https://github.com/LuaLS/lua-language-server",
php: "npm install -g intelephense",
dart: "Included with Dart SDK",
"terraform-ls": "See https://github.com/hashicorp/terraform-ls",
}
// 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">> = {
typescript: {
command: ["typescript-language-server", "--stdio"],
extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts"],
},
deno: {
command: ["deno", "lsp"],
extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs"],
},
vue: {
command: ["vue-language-server", "--stdio"],
extensions: [".vue"],
},
eslint: {
command: ["vscode-eslint-language-server", "--stdio"],
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: {
command: ["gopls"],
extensions: [".go"],
},
"ruby-lsp": {
command: ["rubocop", "--lsp"],
extensions: [".rb", ".rake", ".gemspec", ".ru"],
},
basedpyright: {
command: ["basedpyright-langserver", "--stdio"],
extensions: [".py", ".pyi"],
},
pyright: {
command: ["pyright-langserver", "--stdio"],
extensions: [".py", ".pyi"],
},
ty: {
command: ["ty", "server"],
extensions: [".py", ".pyi"],
},
ruff: {
command: ["ruff", "server"],
extensions: [".py", ".pyi"],
},
"elixir-ls": {
command: ["elixir-ls"],
extensions: [".ex", ".exs"],
},
zls: {
command: ["zls"],
extensions: [".zig", ".zon"],
},
csharp: {
command: ["csharp-ls"],
extensions: [".cs"],
},
fsharp: {
command: ["fsautocomplete"],
extensions: [".fs", ".fsi", ".fsx", ".fsscript"],
},
"sourcekit-lsp": {
command: ["sourcekit-lsp"],
extensions: [".swift", ".objc", ".objcpp"],
},
rust: {
command: ["rust-analyzer"],
extensions: [".rs"],
},
clangd: {
command: ["clangd", "--background-index", "--clang-tidy"],
extensions: [".c", ".cpp", ".cc", ".cxx", ".c++", ".h", ".hpp", ".hh", ".hxx", ".h++"],
},
svelte: {
command: ["svelteserver", "--stdio"],
extensions: [".svelte"],
},
astro: {
command: ["astro-ls", "--stdio"],
extensions: [".astro"],
},
"bash-ls": {
command: ["bash-language-server", "start"],
extensions: [".sh", ".bash", ".zsh", ".ksh"],
},
jdtls: {
command: ["jdtls"],
extensions: [".java"],
},
"yaml-ls": {
command: ["yaml-language-server", "--stdio"],
extensions: [".yaml", ".yml"],
},
"lua-ls": {
command: ["lua-language-server"],
extensions: [".lua"],
},
php: {
command: ["intelephense", "--stdio"],
extensions: [".php"],
},
dart: {
command: ["dart", "language-server", "--lsp"],
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> = {
".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",
".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",
".tsx": "typescriptreact",
".mts": "typescript",
".cts": "typescript",
".mtsx": "typescriptreact",
".ctsx": "typescriptreact",
".xml": "xml",
".xsl": "xsl",
".yaml": "yaml",
".yml": "yaml",
".mjs": "javascript",
".cjs": "javascript",
".vue": "vue",
".zig": "zig",
".zon": "zig",
".astro": "astro",
".ml": "ocaml",
".mli": "ocaml",
".tf": "terraform",
".tfvars": "terraform-vars",
".hcl": "hcl",
// Additional extensions not in OpenCode
".h": "c",
".hpp": "cpp",
".hh": "cpp",
".hxx": "cpp",
".h++": "cpp",
".objc": "objective-c",
".objcpp": "objective-cpp",
".fish": "fish",
".graphql": "graphql",
".gql": "graphql",
}