Skip to content

Commit 394dcb7

Browse files
committed
Add more languages!
1 parent bb4a3c5 commit 394dcb7

File tree

2 files changed

+201
-26
lines changed

2 files changed

+201
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Added
44

55
- Persistent sessions for running testcases and stress tester. Whenever the active editor changes, the previous session is saved and restored when the file is opened again
6+
- Default run and debug configurations for C++, Python, Java, Go, Rust, JavaScript, Haskell, Ruby, and C# (no default debug configurations for Kotlin due to breakpoints not functioning)
67
- Ctrl+Enter hotkey to save currently edited textarea
78
- Ctrl+Enter to append newline instead of sending current online input
89
- Automatically show notification to check changelog when extension is updated

src/extension/runSettingsCommands.ts

Lines changed: 200 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,60 @@ import * as vscode from "vscode";
44

55
import { deepMerge } from "./utils/vscode";
66

7+
// FIXME: Kotlin debugging doesn't work well with single files.
8+
// Remove all debugging configurations for Kotlin for now
9+
10+
const gdbAttachDebugConfig = {
11+
debugCommand: [
12+
"gdbserver",
13+
"localhost:${debugPort}",
14+
"${fileDirname}/${fileBasenameNoExtension}",
15+
],
16+
debugAttachConfig: "GDB: Attach",
17+
};
18+
const javaAttachDebugConfig = {
19+
debugCommand: [
20+
"java",
21+
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=${debugPort}",
22+
"-cp",
23+
"${fileDirname}",
24+
"${fileBasenameNoExtension}",
25+
],
26+
debugAttachConfig: "Java: Attach",
27+
};
28+
729
const languageTemplates: Record<string, object> = {
8-
"C++": {
30+
"C++ (GCC)": {
931
".cpp": {
10-
compileCommand: ["g++", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}"],
32+
compileCommand: ["g++", "${file}", "-g", "-o", "${fileDirname}/${fileBasenameNoExtension}"],
1133
runCommand: ["${fileDirname}/${fileBasenameNoExtension}"],
12-
debugCommand: [
13-
"gdbserver",
14-
"localhost:${debugPort}",
34+
...gdbAttachDebugConfig,
35+
},
36+
},
37+
"C++ (Clang)": {
38+
".cpp": {
39+
compileCommand: [
40+
"clang++",
41+
"${file}",
42+
"-g",
43+
"-o",
1544
"${fileDirname}/${fileBasenameNoExtension}",
1645
],
17-
debugAttachConfig: "C++: Attach",
46+
runCommand: ["${fileDirname}/${fileBasenameNoExtension}"],
47+
...gdbAttachDebugConfig,
48+
},
49+
},
50+
"C++ (MSVC)": {
51+
".cpp": {
52+
compileCommand: [
53+
"cl",
54+
"/EHsc",
55+
"${file}",
56+
"/Fe:${fileDirname}/${fileBasenameNoExtension}.exe",
57+
],
58+
runCommand: ["${fileDirname}/${fileBasenameNoExtension}.exe"],
59+
debugCommand: ["${fileDirname}/${fileBasenameNoExtension}.exe"],
60+
debugAttachConfig: "C++ (MSVC): Attach",
1861
},
1962
},
2063
Python: {
@@ -32,31 +75,127 @@ const languageTemplates: Record<string, object> = {
3275
debugAttachConfig: "Python: Attach",
3376
},
3477
},
78+
PyPy: {
79+
".py": {
80+
runCommand: ["pypy3", "${file}"],
81+
},
82+
},
3583
Java: {
3684
".java": {
37-
compileCommand: ["javac", "${file}"],
85+
compileCommand: ["javac", "-g", "${file}"],
3886
runCommand: ["java", "-cp", "${fileDirname}", "${fileBasenameNoExtension}"],
87+
...javaAttachDebugConfig,
88+
},
89+
},
90+
Go: {
91+
".go": {
92+
compileCommand: ["go", "build", "-o", "${fileDirname}/${fileBasenameNoExtension}", "${file}"],
93+
runCommand: ["${fileDirname}/${fileBasenameNoExtension}"],
94+
debugCommand: [
95+
"dlv",
96+
"debug",
97+
"--headless",
98+
"--listen=localhost:${debugPort}",
99+
"--api-version=2",
100+
"--accept-multiclient",
101+
"${file}",
102+
],
103+
debugAttachConfig: "Go: Attach",
104+
},
105+
},
106+
Rust: {
107+
".rs": {
108+
compileCommand: ["rustc", "${file}", "-g", "-o", "${fileDirname}/${fileBasenameNoExtension}"],
109+
runCommand: ["${fileDirname}/${fileBasenameNoExtension}"],
110+
...gdbAttachDebugConfig,
111+
},
112+
},
113+
JavaScript: {
114+
".js": {
115+
runCommand: ["node", "${file}"],
116+
debugCommand: ["node", "--inspect-brk=localhost:${debugPort}", "${file}"],
117+
debugAttachConfig: "JavaScript: Attach",
118+
},
119+
},
120+
Haskell: {
121+
".hs": {
122+
compileCommand: [
123+
"ghc",
124+
"${file}",
125+
"-O",
126+
"-g",
127+
"-o",
128+
"${fileDirname}/${fileBasenameNoExtension}",
129+
],
130+
runCommand: ["${fileDirname}/${fileBasenameNoExtension}"],
131+
...gdbAttachDebugConfig,
132+
},
133+
},
134+
Ruby: {
135+
".rb": {
136+
runCommand: ["ruby", "${file}"],
137+
debugCommand: ["rdbg", "--open", "--port", "${debugPort}", "--", "${file}"],
138+
debugAttachConfig: "Ruby: Attach",
139+
},
140+
},
141+
"C#": {
142+
".cs": {
143+
compileCommand: [
144+
"csc",
145+
"-debug",
146+
"/out:${fileDirname}/${fileBasenameNoExtension}.exe",
147+
"${file}",
148+
],
149+
runCommand: ["mono", "${fileDirname}/${fileBasenameNoExtension}.exe"],
39150
debugCommand: [
40-
"java",
41-
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=${debugPort}",
42-
"-cp",
43-
"${fileDirname}",
44-
"${fileBasenameNoExtension}",
151+
"mono",
152+
"--debug",
153+
"--debugger-agent=transport=dt_socket,server=y,address=127.0.0.1:${debugPort},suspend=y",
154+
"${fileDirname}/${fileBasenameNoExtension}.exe",
45155
],
46-
debugAttachConfig: "Java: Attach",
156+
debugAttachConfig: "C#: Attach",
47157
},
48158
},
159+
Kotlin: {
160+
".kt": {
161+
compileCommand: [
162+
"kotlinc",
163+
"${file}",
164+
"-include-runtime",
165+
"-d",
166+
"${fileDirname}/${fileBasenameNoExtension}.jar",
167+
],
168+
runCommand: ["java", "-jar", "${fileDirname}/${fileBasenameNoExtension}.jar"],
169+
},
170+
},
171+
};
172+
173+
const gdbAttachConfig = {
174+
name: "GDB: Attach",
175+
type: "gdb",
176+
request: "attach",
177+
executable: "${fileDirname}/${fileBasenameNoExtension}",
178+
target: ":${debugPort}",
179+
remote: true,
180+
cwd: "${workspaceFolder}",
181+
valuesFormatting: "prettyPrinters",
182+
};
183+
const javaAttachConfig = {
184+
name: "Java: Attach",
185+
type: "java",
186+
request: "attach",
187+
hostName: "localhost",
188+
port: "${debugPort}",
49189
};
50190

51191
const launchTemplates: Record<string, vscode.DebugConfiguration> = {
52-
"C++": {
53-
name: "C++: Attach",
54-
type: "cppdbg",
55-
request: "launch",
56-
MIMode: "gdb",
57-
miDebuggerServerAddress: "localhost:${debugPort}",
58-
program: "${fileDirname}/${fileBasenameNoExtension}",
59-
cwd: "${fileDirname}",
192+
"C++ (GCC)": gdbAttachConfig,
193+
"C++ (Clang)": gdbAttachConfig,
194+
"C++ (MSVC)": {
195+
name: "C++ (MSVC): Attach",
196+
type: "cppvsdbg",
197+
request: "attach",
198+
processId: "${debugPid}",
60199
},
61200
Python: {
62201
name: "Python: Attach",
@@ -67,19 +206,54 @@ const launchTemplates: Record<string, vscode.DebugConfiguration> = {
67206
port: "${debugPort}",
68207
},
69208
},
70-
Java: {
71-
name: "Java: Attach",
72-
type: "java",
209+
Java: javaAttachConfig,
210+
Go: {
211+
name: "Go: Attach",
212+
type: "go",
213+
request: "attach",
214+
mode: "remote",
215+
port: "${debugPort}",
216+
host: "localhost",
217+
},
218+
Rust: gdbAttachConfig,
219+
JavaScript: {
220+
name: "JavaScript: Attach",
221+
type: "node",
73222
request: "attach",
74-
hostName: "localhost",
75223
port: "${debugPort}",
224+
address: "localhost",
225+
continueOnAttach: true,
226+
},
227+
"C#": {
228+
name: "C#: Attach",
229+
type: "mono",
230+
request: "attach",
231+
address: "localhost",
232+
port: "${debugPort}",
233+
},
234+
Ruby: {
235+
name: "Ruby: Attach",
236+
type: "rdbg",
237+
request: "attach",
238+
debugPort: "${debugPort}",
239+
localfs: true,
76240
},
241+
Haskell: gdbAttachConfig,
77242
};
78243

79244
const recommendedDebugExtensions: Record<string, string> = {
80-
"C++": "webfreak.debug",
245+
"C++ (GCC)": "webfreak.debug",
246+
"C++ (Clang)": "webfreak.debug",
247+
"C++ (MSVC)": "ms-vscode.cpptools",
81248
Python: "ms-python.python",
249+
PyPy: "ms-python.python",
82250
Java: "redhat.java",
251+
Go: "golang.go",
252+
Rust: "webfreak.debug",
253+
JavaScript: "ms-vscode.js-debug",
254+
Haskell: "webfreak.debug",
255+
Ruby: "KoichiSasada.vscode-rdbg",
256+
"C#": "ms-vscode.mono-debug",
83257
};
84258

85259
function getDefaultTemplatesPreview(): Record<string, object> {

0 commit comments

Comments
 (0)