forked from CodeBoarding/CodeBoarding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvscode_constants.py
More file actions
143 lines (130 loc) · 5.69 KB
/
Copy pathvscode_constants.py
File metadata and controls
143 lines (130 loc) · 5.69 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import os
import platform
def get_bin_path(bin_dir):
system = platform.system().lower()
subdirs = {"windows": "win", "darwin": "macos", "linux": "linux"}
if system not in subdirs:
raise RuntimeError(
f"Unsupported platform: {system}. The extension currently supports Windows, macOS, and Linux."
)
return os.path.join(bin_dir, "bin", subdirs[system])
def update_command_paths(bin_dir):
bin_path = get_bin_path(bin_dir)
is_windows = platform.system().lower() == "windows"
# Languages that need 'node' prefix on Windows
node_languages = {"typescript", "python", "php"}
for section in VSCODE_CONFIG.values():
for key, value in section.items():
cmd: list[str] = value["command"] # type: ignore[assignment]
if key == "typescript":
# Scan the bin dir to find the cli.mjs path
cmd[0] = (
find_runnable(bin_dir, "cli.mjs", "typescript-language-server")
or find_runnable(bin_dir, "typescript-language-server", "node_modules")
or cmd[0]
)
elif key == "python":
cmd[0] = (
find_runnable(bin_dir, "langserver.index.js", "pyright")
or find_runnable(bin_dir, "pyright", "node_modules")
or cmd[0]
)
elif key == "php":
cmd[0] = (
find_runnable(bin_dir, "intelephense.js", "intelephense")
or find_runnable(bin_dir, "intelephense", "node_modules")
or cmd[0]
)
elif key == "java":
# Find JDTLS root directory
jdtls_dir = os.path.join(bin_dir, "bin", "jdtls")
if os.path.exists(jdtls_dir):
# Store the JDTLS root path for JavaClient to use
# The actual command will be constructed dynamically in JavaClient
value["jdtls_root"] = jdtls_dir
# Keep command as "java" - it will be constructed by JavaClient
cmd[0] = "java"
elif "command" in value:
if isinstance(cmd, list) and cmd:
cmd[0] = os.path.join(bin_path, cmd[0])
# Apply Windows-specific node prefix for specified languages
# Use VSCode's bundled Node.js (passed via CODEBOARDING_NODE_PATH) so users
# don't need a separate Node.js/npm installation on Windows.
if is_windows and key in node_languages:
node_path = os.environ.get("CODEBOARDING_NODE_PATH", "node")
cmd.insert(0, node_path)
def find_runnable(bin_dir, search_file, part_of_dir):
for root, _, files in os.walk(bin_dir):
if search_file in files and part_of_dir in root:
return os.path.join(root, search_file)
return None
def update_config(bin_dir=None):
if bin_dir:
update_command_paths(bin_dir)
VSCODE_CONFIG = {
"lsp_servers": {
"python": {
"name": "Pyright Language Server",
"command": ["pyright-langserver", "--stdio"],
"languages": ["python"],
"file_extensions": [".py", ".pyi"],
"install_commands": "npm install pyright",
},
"typescript": {
"name": "TypeScript Language Server",
"command": ["cli.mjs", "--stdio", "--log-level=2"],
"languages": ["typescript", "javascript"],
"file_extensions": [".ts", ".tsx", ".js", ".jsx"],
"install_commands": "npm install --save-dev typescript-language-server typescript",
},
"go": {
"name": "Go Language Server (gopls)",
"command": ["gopls", "serve"],
"languages": ["go"],
"file_extensions": [".go"],
"install_commands": "go install golang.org/x/tools/gopls@latest",
},
"php": {
"name": "Intelephense",
"command": ["intelephense", "--stdio"],
"languages": ["php"],
"file_extensions": [".php"],
"install_commands": "npm install intelephense",
},
"csharp": {
"name": "csharp-ls Language Server",
"command": ["csharp-ls"],
"languages": ["csharp"],
"file_extensions": [".cs"],
# csharp-ls is installed via `dotnet tool install --tool-path` by
# tool_registry. Full migration mode targets .NET 10.
"install_commands": "codeboarding-setup (installs csharp-ls automatically; requires .NET SDK 10.0+)",
},
"java": {
"name": "Eclipse JDT Language Server",
"command": ["java"], # Placeholder - will be resolved by update_command_paths()
"languages": ["java"],
"file_extensions": [".java"],
"install_commands": "null",
},
"rust": {
"name": "rust-analyzer",
"command": ["rust-analyzer"],
"languages": ["rust"],
"file_extensions": [".rs"],
# rust-analyzer is downloaded from rust-lang/rust-analyzer releases
# by tool_registry; the install_commands string is informational only
# and surfaces in error messages when the binary cannot be located.
"install_commands": "codeboarding-setup (downloads rust-analyzer automatically)",
},
},
"tools": {
"tokei": {
"name": "tokei",
"command": ["tokei", "-o", "json"],
"description": "Analyze repository languages and file types",
"install_command": "conda install -c conda-forge tokei",
"output_format": "json",
}
},
}