summaryrefslogtreecommitdiffhomepage
path: root/packages/lsp/src/language.ts
blob: cd5b5fd635ae2692d2467b761657e345d2d4e6a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
 * 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",
  ".rb": "ruby",
  ".rbs": "ruby",
  ".c": "c",
  ".h": "c",
  ".cpp": "cpp",
  ".cc": "cpp",
  ".cxx": "cpp",
  ".hpp": "cpp",
  ".hxx": "cpp",
  ".java": "java",
  ".kt": "kotlin",
  ".swift": "swift",
  ".php": "php",
  ".cs": "csharp",
  ".sql": "sql",
  ".dockerfile": "dockerfile",
};

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";
}