Skip to content

Commit 4690e9d

Browse files
authored
Merge pull request #329 from ccagml/main
3.2.3
2 parents e3ed624 + 7022dd4 commit 4690e9d

File tree

6 files changed

+120
-34
lines changed

6 files changed

+120
-34
lines changed

.vscode/launch.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
],
2121
"trace": false,
2222
"preLaunchTask": "npm",
23+
"env": {
24+
"PATH": "${env:PATH}"
25+
}
2326
},
2427
{
2528
"type": "node",

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# version 3.2.3
2+
3+
- 添加 msvc 支持,使用 path 中的 clang,gcc 使用 c++20 标准
4+
15
# version 3.2.2
26

37
- 手气一下显示分数范围

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-leetcode-problem-rating",
33
"displayName": "LeetCode",
44
"description": "%main.description%",
5-
"version": "3.2.2",
5+
"version": "3.2.3",
66
"author": "ccagml",
77
"publisher": "ccagml",
88
"license": "MIT",
@@ -1196,11 +1196,13 @@
11961196
"default": "gdb",
11971197
"enum": [
11981198
"gdb",
1199-
"clang"
1199+
"clang",
1200+
"msvc"
12001201
],
12011202
"enumDescriptions": [
12021203
"%main.contributes.configuration.properties.leetcode-problem-rating.cppCompiler.enumDescriptions.0%",
1203-
"%main.contributes.configuration.properties.leetcode-problem-rating.cppCompiler.enumDescriptions.1%"
1204+
"%main.contributes.configuration.properties.leetcode-problem-rating.cppCompiler.enumDescriptions.1%",
1205+
"%main.contributes.configuration.properties.leetcode-problem-rating.cppCompiler.enumDescriptions.2%"
12041206
],
12051207
"scope": "resource"
12061208
}

package.nls.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@
104104
"main.contributes.configuration.properties.leetcode-problem-rating.openClearProblemCacheTime.description": "Open the app to clear the cache interval by default 3600 seconds",
105105
"main.contributes.configuration.properties.leetcode-problem-rating.cppCompiler.enumDescriptions": [
106106
"gdb compiler",
107-
"clang compiler"
107+
"clang compiler",
108+
"msvc compiler"
108109
],
109110
"main.contributes.configuration.properties.leetcode-problem-rating.problems.sortStrategy.enumDescriptions.0": "None",
110111
"main.contributes.configuration.properties.leetcode-problem-rating.problems.sortStrategy.enumDescriptions.1": "Acceptance Rate (Ascending)",
@@ -126,5 +127,6 @@
126127
"main.contributes.configuration.properties.leetcode-problem-rating.hideScore.enumDescriptions.2": "Hide questions with no scores",
127128
"main.contributes.configuration.properties.leetcode-problem-rating.hideScore.enumDescriptions.3": "Hide questions outside the range of scores [pickOneByRankRangeMin, pickOneByRankRangeMax]",
128129
"main.contributes.configuration.properties.leetcode-problem-rating.cppCompiler.enumDescriptions.0": "gdb compiler",
129-
"main.contributes.configuration.properties.leetcode-problem-rating.cppCompiler.enumDescriptions.1": "clang compiler"
130+
"main.contributes.configuration.properties.leetcode-problem-rating.cppCompiler.enumDescriptions.1": "clang compiler",
131+
"main.contributes.configuration.properties.leetcode-problem-rating.cppCompiler.enumDescriptions.2": "msvc compiler"
130132
}

package.nls.zh-cn.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@
104104
"main.contributes.configuration.properties.leetcode-problem-rating.openClearProblemCacheTime.description": "打开拓展时清除缓存间隔默认3600秒",
105105
"main.contributes.configuration.properties.leetcode-problem-rating.cppCompiler.enumDescriptions": [
106106
"gdb compiler",
107-
"clang compiler"
107+
"clang compiler",
108+
"msvc compiler"
108109
],
109110
"main.contributes.configuration.properties.leetcode-problem-rating.problems.sortStrategy.enumDescriptions.0": "默认题目编号排序",
110111
"main.contributes.configuration.properties.leetcode-problem-rating.problems.sortStrategy.enumDescriptions.1": "通过率升序",
@@ -126,5 +127,6 @@
126127
"main.contributes.configuration.properties.leetcode-problem-rating.hideScore.enumDescriptions.2": "隐藏没有分数的题目",
127128
"main.contributes.configuration.properties.leetcode-problem-rating.hideScore.enumDescriptions.3": "隐藏分数在配置[pickOneByRankRangeMin, pickOneByRankRangeMax]范围外的题目",
128129
"main.contributes.configuration.properties.leetcode-problem-rating.cppCompiler.enumDescriptions.0": "gdb编译",
129-
"main.contributes.configuration.properties.leetcode-problem-rating.cppCompiler.enumDescriptions.1": "clang编译"
130+
"main.contributes.configuration.properties.leetcode-problem-rating.cppCompiler.enumDescriptions.1": "clang编译",
131+
"main.contributes.configuration.properties.leetcode-problem-rating.cppCompiler.enumDescriptions.2": "msvc编译",
130132
}

src/debug/DoCpp.ts

Lines changed: 100 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ function getGdbDefaultConfig(): IDebugConfig {
3636

3737
function getClangDefaultConfig(): IDebugConfig {
3838
return {
39-
type: "cppdbg",
40-
MIMode: "lldb",
41-
externalConsole: false,
39+
type: "lldb",
40+
};
41+
}
42+
43+
function getMSVCDefaultConfig(): IDebugConfig {
44+
return {
45+
type: "cppvsdbg",
4246
};
4347
}
4448

@@ -240,28 +244,44 @@ export class DebugCpp {
240244

241245
const compiler = vscode.workspace.getConfiguration("leetcode-problem-rating").get<string>("cppCompiler") ?? "gdb";
242246
let debugConfig: any;
243-
if (compiler === "clang") {
244-
debugConfig = await this.getClangDebugConfig({
245-
program,
246-
exePath,
247-
commonDestPath,
248-
jsonPath,
249-
thirdPartyPath,
250-
filePath,
251-
newSourceFilePath,
252-
});
253-
} else {
254-
debugConfig = await this.getGdbDebugConfig({
255-
program,
256-
exePath,
257-
commonDestPath,
258-
jsonPath,
259-
thirdPartyPath,
260-
filePath,
261-
newSourceFilePath,
262-
});
263-
}
264-
247+
switch (compiler) {
248+
case "clang": {
249+
debugConfig = await this.getClangDebugConfig({
250+
program,
251+
exePath,
252+
commonDestPath,
253+
jsonPath,
254+
thirdPartyPath,
255+
filePath,
256+
newSourceFilePath,
257+
});
258+
break;
259+
}
260+
case "gdb": {
261+
debugConfig = await this.getGdbDebugConfig({
262+
program,
263+
exePath,
264+
commonDestPath,
265+
jsonPath,
266+
thirdPartyPath,
267+
filePath,
268+
newSourceFilePath,
269+
});
270+
break;
271+
}
272+
case "msvc": {
273+
debugConfig = await this.getMSVCDebugConfig({
274+
program,
275+
exePath,
276+
commonDestPath,
277+
jsonPath,
278+
thirdPartyPath,
279+
filePath,
280+
newSourceFilePath,
281+
});
282+
break;
283+
}
284+
}
265285
if (debugConfig == null) {
266286
return;
267287
}
@@ -398,7 +418,7 @@ export class DebugCpp {
398418
const includePath: string = path.dirname(exePath);
399419
await sysCall(
400420
"g++",
401-
["-g", program, commonDestPath, jsonPath, "-o", exePath, "-I", includePath, "-I", thirdPartyPath],
421+
["-std=c++20","-g", program, commonDestPath, jsonPath, "-o", exePath, "-I", includePath, "-I", thirdPartyPath],
402422
{ shell: false }
403423
);
404424
} catch (e) {
@@ -438,7 +458,7 @@ export class DebugCpp {
438458
try {
439459
const includePath: string = path.dirname(exePath);
440460
await sysCall(
441-
"/usr/bin/clang++",
461+
"clang++",
442462
[
443463
"-std=c++20",
444464
"-stdlib=libc++",
@@ -470,4 +490,57 @@ export class DebugCpp {
470490
};
471491
return debugConfig;
472492
}
493+
494+
private async getMSVCDebugConfig({
495+
program,
496+
exePath,
497+
commonDestPath,
498+
jsonPath,
499+
thirdPartyPath,
500+
filePath,
501+
newSourceFilePath,
502+
}: {
503+
program: string;
504+
exePath: string;
505+
commonDestPath: string;
506+
jsonPath: string;
507+
thirdPartyPath: string;
508+
filePath: string;
509+
newSourceFilePath: string;
510+
}) {
511+
const debugConfig = getMSVCDefaultConfig();
512+
try {
513+
const includePath: string = path.dirname(exePath);
514+
await sysCall(
515+
"cl",
516+
[
517+
"-std:c++20",
518+
"-Zi",
519+
"-EHsc",
520+
program,
521+
commonDestPath,
522+
jsonPath,
523+
`-Fe${exePath}`,
524+
"-I",
525+
includePath,
526+
"-I",
527+
thirdPartyPath,
528+
],
529+
{ shell: false }
530+
);
531+
} catch (e) {
532+
ShowMessage(e, OutPutType.error);
533+
BABA.getProxy(BabaStr.LogOutputProxy).get_log().append(e.stack);
534+
BABA.getProxy(BabaStr.LogOutputProxy).get_log().show();
535+
return;
536+
}
537+
538+
debugConfig.program = exePath;
539+
debugConfig.cwd = extensionState.cachePath;
540+
// map build source file to user source file
541+
debugConfig.sourceFileMap = {
542+
[newSourceFilePath]: filePath,
543+
};
544+
return debugConfig;
545+
}
473546
}

0 commit comments

Comments
 (0)