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
81 lines (71 loc) · 2.68 KB
/
vscode_constants.py
File metadata and controls
81 lines (71 loc) · 2.68 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
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)
for section in VSCODE_CONFIG.values():
for key, value in section.items():
if key == 'typescript':
# Scan the bin dir to fine the cli.mjs path
value['command'][0] = find_cli_js(bin_dir) or value['command'][0]
if platform.system().lower() == 'windows':
# Use node to run the .mjs file on Windows
value['command'].insert(0, 'node')
elif "command" in value:
cmd = value["command"]
if isinstance(cmd, list) and cmd:
value["command"][0] = os.path.join(bin_path, cmd[0])
def find_cli_js(bin_dir, search_file='cli.mjs'):
for root, dirs, files in os.walk(bin_dir):
if search_file in files and 'typescript-language-server' 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": ["py-lsp", "--stdio"],
"languages": ["python"],
"file_extensions": [".py", ".pyi"],
"install_commands": "pip 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"
}
},
"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"
}
}
}