diff options
Diffstat (limited to 'packages/lsp/src/language.ts')
| -rw-r--r-- | packages/lsp/src/language.ts | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/packages/lsp/src/language.ts b/packages/lsp/src/language.ts new file mode 100644 index 0000000..214294e --- /dev/null +++ b/packages/lsp/src/language.ts @@ -0,0 +1,36 @@ +/** + * Language ID mapping from file extensions. + */ + +const extensionMap: Record<string, string> = { + ".ts": "typescript", + ".tsx": "typescriptreact", + ".mts": "typescript", + ".cts": "typescript", + ".js": "javascript", + ".jsx": "javascriptreact", + ".mjs": "javascript", + ".cjs": "javascript", + ".json": "json", + ".lua": "lua", + ".luau": "luau", + ".py": "python", + ".rs": "rust", + ".go": "go", + ".md": "markdown", + ".yaml": "yaml", + ".yml": "yaml", + ".toml": "toml", + ".css": "css", + ".html": "html", + ".sh": "shellscript", + ".bash": "shellscript", + ".zsh": "shellscript", +}; + +export function languageId(filePath: string): string { + const dotIdx = filePath.lastIndexOf("."); + if (dotIdx === -1) return "unknown"; + const ext = filePath.slice(dotIdx).toLowerCase(); + return extensionMap[ext] ?? "unknown"; +} |
