diff --git a/assets/oh-my-opencode.schema.json b/assets/oh-my-opencode.schema.json index b6d1505..b5f68ab 100644 --- a/assets/oh-my-opencode.schema.json +++ b/assets/oh-my-opencode.schema.json @@ -1220,6 +1220,14 @@ }, "auto_resume": { "type": "boolean" + }, + "preemptive_compaction": { + "type": "boolean" + }, + "preemptive_compaction_threshold": { + "type": "number", + "minimum": 0.5, + "maximum": 0.95 } } }, diff --git a/src/tools/lsp/config.ts b/src/tools/lsp/config.ts index 974d092..7bea891 100644 --- a/src/tools/lsp/config.ts +++ b/src/tools/lsp/config.ts @@ -147,11 +147,31 @@ export function isServerInstalled(command: string[]): boolean { if (command.length === 0) return false const cmd = command[0] + const isWindows = process.platform === "win32" + const ext = isWindows ? ".exe" : "" + const pathEnv = process.env.PATH || "" - const paths = pathEnv.split(":") + const pathSeparator = isWindows ? ";" : ":" + const paths = pathEnv.split(pathSeparator) 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 } } diff --git a/src/tools/lsp/constants.ts b/src/tools/lsp/constants.ts index fe92119..0e4ca1a 100644 --- a/src/tools/lsp/constants.ts +++ b/src/tools/lsp/constants.ts @@ -40,6 +40,8 @@ export const DEFAULT_MAX_REFERENCES = 200 export const DEFAULT_MAX_SYMBOLS = 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> = { typescript: { command: ["typescript-language-server", "--stdio"], @@ -57,6 +59,17 @@ export const BUILTIN_SERVERS: Record> = { 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"], @@ -73,6 +86,10 @@ export const BUILTIN_SERVERS: Record> = { command: ["pyright-langserver", "--stdio"], extensions: [".py", ".pyi"], }, + ty: { + command: ["ty", "server"], + extensions: [".py", ".pyi"], + }, ruff: { command: ["ruff", "server"], extensions: [".py", ".pyi"], @@ -89,6 +106,10 @@ export const BUILTIN_SERVERS: Record> = { command: ["csharp-ls"], extensions: [".cs"], }, + fsharp: { + command: ["fsautocomplete"], + extensions: [".fs", ".fsi", ".fsx", ".fsscript"], + }, "sourcekit-lsp": { command: ["sourcekit-lsp"], extensions: [".swift", ".objc", ".objcpp"], @@ -133,26 +154,128 @@ export const BUILTIN_SERVERS: Record> = { 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 = { + ".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", - ".js": "javascript", - ".jsx": "javascriptreact", + ".mtsx": "typescriptreact", + ".ctsx": "typescriptreact", + ".xml": "xml", + ".xsl": "xsl", + ".yaml": "yaml", + ".yml": "yaml", ".mjs": "javascript", ".cjs": "javascript", - ".go": "go", - ".rs": "rust", - ".c": "c", - ".cpp": "cpp", - ".cc": "cpp", - ".cxx": "cpp", - ".c++": "cpp", + ".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", @@ -160,37 +283,7 @@ export const EXT_TO_LANG: Record = { ".h++": "cpp", ".objc": "objective-c", ".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", - ".md": "markdown", - ".tf": "terraform", - ".tfvars": "terraform", + ".graphql": "graphql", + ".gql": "graphql", }