Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite3365bb

Browse files
Run and Debug button updates (microsoft#9110)
1 parent71e9d23 commite3365bb

File tree

4 files changed

+89
-44
lines changed

4 files changed

+89
-44
lines changed

‎Extension/src/Debugger/configurationProvider.ts‎

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import * as Telemetry from '../telemetry';
1414
import{cppBuildTaskProvider,configPrefix}from'../LanguageServer/extension';
1515
import*asloggerfrom'../logger';
1616
import*asnlsfrom'vscode-nls';
17-
import{IConfiguration,IConfigurationSnippet,DebuggerType,DebuggerEvent,MIConfigurations,WindowsConfigurations,WSLConfigurations,PipeTransportConfigurations,TaskConfigStatus}from'./configurations';
17+
import{IConfiguration,IConfigurationSnippet,DebuggerType,DebuggerEvent,MIConfigurations,WindowsConfigurations,WSLConfigurations,PipeTransportConfigurations}from'./configurations';
1818
import{parse}from'comment-json';
1919
import{PlatformInformation}from'../platform';
2020
import{Environment,ParsedEnvironmentFile}from'./ParsedEnvironmentFile';
@@ -26,6 +26,26 @@ function isDebugLaunchStr(str: string): boolean {
2626
returnstr.startsWith("(gdb) ")||str.startsWith("(lldb) ")||str.startsWith("(Windows) ");
2727
}
2828

29+
interfaceMenuItemextendsvscode.QuickPickItem{
30+
configuration:vscode.DebugConfiguration;
31+
}
32+
33+
exportenumTaskConfigStatus{
34+
recentlyUsed="Recently Used Task",
35+
configured="Configured Task",// The tasks that are configured in tasks.json file.
36+
detected="Detected Task"// The tasks that are available based on detected compilers.
37+
}
38+
39+
constlocalizeConfigs=(items:MenuItem[]):MenuItem[]=>{
40+
items.map((item:MenuItem)=>{
41+
item.detail=(item.detail===TaskConfigStatus.recentlyUsed) ?localize("recently.used.task","Recently Used Task") :
42+
(item.detail===TaskConfigStatus.configured) ?localize("configured.task","Configured Task") :
43+
(item.detail===TaskConfigStatus.detected) ?localize("detected.task","Detected Task") :item.detail;
44+
45+
});
46+
returnitems;
47+
};
48+
2949
/*
3050
* Retrieves configurations from a provider and displays them in a quickpick menu to be selected.
3151
* Ensures that the selected configuration's preLaunchTask (if existent) is populated in the user's task.json.
@@ -60,9 +80,6 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
6080
if(!editor||!util.isCppOrCFile(editor.document.uri)||configs.length<=1){
6181
return[defaultConfig];
6282
}
63-
interfaceMenuItemextendsvscode.QuickPickItem{
64-
configuration:vscode.DebugConfiguration;
65-
}
6683

6784
// Find the recently used task and place it at the top of quickpick list.
6885
letrecentlyUsedConfig:vscode.DebugConfiguration|undefined;
@@ -92,7 +109,7 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
92109
returnmenuItem;
93110
});
94111

95-
constselection:MenuItem|undefined=awaitvscode.window.showQuickPick(items,{placeHolder:localize("select.configuration","Select a configuration")});
112+
constselection:MenuItem|undefined=awaitvscode.window.showQuickPick(localizeConfigs(items),{placeHolder:localize("select.configuration","Select a configuration")});
96113
if(!selection){
97114
Telemetry.logDebuggerEvent(DebuggerEvent.debugPanel,{"debugType":"debug","folderMode":folder ?"folder" :"singleFile","cancelled":"true"});
98115
return[];// User canceled it.
@@ -283,7 +300,7 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
283300

284301
// Generate new configurations for each build task.
285302
// Generating a task is async, therefore we must *await* *all* map(task => config) Promises to resolve.
286-
constconfigs:vscode.DebugConfiguration[]=awaitPromise.all(buildTasks.map<Promise<vscode.DebugConfiguration>>(asynctask=>{
303+
letconfigs:vscode.DebugConfiguration[]=awaitPromise.all(buildTasks.map<Promise<vscode.DebugConfiguration>>(asynctask=>{
287304
constdefinition:CppBuildTaskDefinition=task.definitionasCppBuildTaskDefinition;
288305
constcompilerPath:string=definition.command;
289306
constcompilerName:string=path.basename(compilerPath);
@@ -297,12 +314,15 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
297314
newConfig.console="externalTerminal";
298315
}
299316
constisWindows:boolean=platformInfo.platform==='win32';
300-
constexeName:string=path.join("${fileDirname}","${fileBasenameNoExtension}");
301-
newConfig.program=isWindows ?exeName+".exe" :exeName;
317+
// Extract the .exe path from the defined task.
318+
constdefinedExePath:string|undefined=util.findExePathInArgs(task.definition.args);
319+
newConfig.program=definedExePath ?definedExePath :util.defaultExePath();
302320
// Add the "detail" property to show the compiler path in QuickPickItem.
303321
// This property will be removed before writing the DebugConfiguration in launch.json.
304322
newConfig.detail=localize("pre.Launch.Task","preLaunchTask: {0}",task.name);
305-
newConfig.existing=(task.name===DebugConfigurationProvider.recentBuildTaskLabelStr) ?TaskConfigStatus.recentlyUsed :(task.existing ?TaskConfigStatus.configured :TaskConfigStatus.detected);
323+
newConfig.existing=(task.name===DebugConfigurationProvider.recentBuildTaskLabelStr) ?
324+
TaskConfigStatus.recentlyUsed :
325+
(task.existing ?TaskConfigStatus.configured :TaskConfigStatus.detected);
306326
if(task.isDefault){
307327
newConfig.isDefault=true;
308328
}
@@ -355,6 +375,33 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
355375
});
356376
}));
357377
configs.push(defaultConfig);
378+
// Get existing debug configurations from launch.json.
379+
if(folder){
380+
constexistingConfigs:vscode.DebugConfiguration[]|undefined=(awaitthis.getLaunchConfigs(folder,type))?.map(config=>({
381+
name:config.name,
382+
type:config.type,
383+
request:config.request,
384+
detail:config.detail ?config.detail :
385+
config.preLaunchTask ?localize("pre.Launch.Task","preLaunchTask: {0}",config.preLaunchTask) :undefined,
386+
existing:TaskConfigStatus.configured,
387+
preLaunchTask:config.preLaunchTask
388+
}));
389+
if(existingConfigs){
390+
constareEqual=(config1:vscode.DebugConfiguration,config2:vscode.DebugConfiguration):boolean=>
391+
(config1.preLaunchTask===config2.preLaunchTask
392+
&&config1.type===config2.type&&config1.request===config2.request);
393+
// Remove the detected configs that are already configured once in launch.json.
394+
constdedupExistingConfigs:vscode.DebugConfiguration[]=configs.filter(detectedConfig=>!existingConfigs.some(config=>{
395+
if(areEqual(config,detectedConfig)){
396+
// Carry the default task information.
397+
config.isDefault=detectedConfig.isDefault ?detectedConfig.isDefault :undefined;
398+
returntrue;
399+
}
400+
returnfalse;
401+
}));
402+
configs=existingConfigs.concat(dedupExistingConfigs);
403+
}
404+
}
358405
returnconfigs;
359406
}
360407

@@ -510,12 +557,12 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
510557
}
511558
}
512559

513-
publicasyncgetLaunchConfigs(folder:vscode.WorkspaceFolder|undefined):Promise<vscode.WorkspaceConfiguration[]|undefined>{
560+
publicasyncgetLaunchConfigs(folder:vscode.WorkspaceFolder|undefined,type:DebuggerType):Promise<vscode.WorkspaceConfiguration[]|undefined>{
514561
letconfigs:vscode.WorkspaceConfiguration[]|undefined=vscode.workspace.getConfiguration('launch',folder).get('configurations');
515562
if(!configs){
516563
returnundefined;
517564
}
518-
configs=configs.filter(config=>(config.name&&config.request==="launch"&&(config.type===DebuggerType.cppvsdbg||config.type===DebuggerType.cppdbg)));
565+
configs=configs.filter(config=>(config.name&&config.request==="launch"&&config.type===type));
519566
returnconfigs;
520567
}
521568

@@ -538,36 +585,14 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
538585
configs=configs.concat(awaitthis.provideDebugConfigurationsForType(DebuggerType.cppvsdbg,folder));
539586
}
540587

541-
if(folder){
542-
// Get existing debug configurations from launch.json.
543-
constexistingConfigs:vscode.DebugConfiguration[]|undefined=(awaitthis.getLaunchConfigs(folder))?.map(config=>({
544-
name:config.name,
545-
type:config.type,
546-
request:config.request,
547-
detail:config.detail ?config.detail :localize("pre.Launch.Task","preLaunchTask: {0}",config.preLaunchTask),
548-
preLaunchTask:config.preLaunchTask,
549-
existing:TaskConfigStatus.configured
550-
}));
551-
if(existingConfigs){
552-
constareEqual=(config1:vscode.DebugConfiguration,config2:vscode.DebugConfiguration):boolean=>
553-
(config1.name===config2.name&&config1.preLaunchTask===config2.preLaunchTask
554-
&&config1.type===config2.type&&config1.request===config2.request);
555-
// Remove the detected configs that are already configured once in launch.json.
556-
constdedupExistingConfigs:vscode.DebugConfiguration[]=configs.filter(detectedConfig=>!existingConfigs.some(config=>areEqual(config,detectedConfig)));
557-
configs=existingConfigs.concat(dedupExistingConfigs);
558-
}
559-
}
560-
561588
constdefaultConfig:vscode.DebugConfiguration[]=configs.filter((config:vscode.DebugConfiguration)=>(config.hasOwnProperty("isDefault")&&config.isDefault));
562-
interfaceMenuItemextendsvscode.QuickPickItem{
563-
configuration:vscode.DebugConfiguration;
564-
}
565589

566590
constitems:MenuItem[]=configs.map<MenuItem>(config=>({label:config.name,configuration:config,description:config.detail,detail:config.existing}));
567591

568592
letselection:MenuItem|undefined;
569593

570-
if(defaultConfig.length!==0){
594+
// if there was only one config for the default task, choose that config, otherwise ask the user to choose.
595+
if(defaultConfig.length===1){
571596
selection={label:defaultConfig[0].name,configuration:defaultConfig[0],description:defaultConfig[0].detail,detail:defaultConfig[0].existing};
572597
}else{
573598
letsortedItems:MenuItem[]=[];
@@ -579,7 +604,8 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
579604
}
580605
sortedItems=sortedItems.concat(items.filter(item=>item.detail===TaskConfigStatus.configured));
581606
sortedItems=sortedItems.concat(items.filter(item=>item.detail===TaskConfigStatus.detected));
582-
selection=awaitvscode.window.showQuickPick(sortedItems,{
607+
608+
selection=awaitvscode.window.showQuickPick(localizeConfigs(sortedItems),{
583609
placeHolder:(items.length===0 ?localize("no.compiler.found","No compiler found") :localize("select.debug.configuration","Select a debug configuration"))
584610
});
585611
}

‎Extension/src/Debugger/configurations.ts‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ export enum DebuggerEvent {
2121
launchPlayButton="launchPlayButton"
2222
}
2323

24-
exportenumTaskConfigStatus{
25-
recentlyUsed="Recently Used Task",
26-
configured="Configured Task",// The tasks that are configured in tasks.json file.
27-
detected="Detected Task"// The tasks that are available based on detected compilers.
28-
}
29-
3024
exportinterfaceIConfigurationSnippet{
3125
label:string;
3226
description:string;

‎Extension/src/LanguageServer/cppBuildTaskProvider.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ export class CppBuildTaskProvider implements TaskProvider {
172172
constisWindows:boolean=os.platform()==='win32';
173173
consttaskLabel:string=((appendSourceToName&&!compilerPathBase.startsWith(ext.configPrefix)) ?
174174
ext.configPrefix :"")+compilerPathBase+" "+localize("build_active_file","build active file");
175-
constfilePath:string=path.join('${fileDirname}','${fileBasenameNoExtension}');
176-
constprogramName:string=isWindows ?filePath+'.exe' :filePath;
175+
constprogramName:string=util.defaultExePath();
177176
letargs:string[]=isCl ?['/Zi','/EHsc','/nologo','/Fe:',programName,'${file}'] :['-fdiagnostics-color=always','-g','${file}','-o',programName];
178177
if(compilerArgs&&compilerArgs.length>0){
179178
args=args.concat(compilerArgs);
@@ -410,6 +409,11 @@ class CustomBuildTaskTerminal implements Pseudoterminal {
410409
}
411410

412411
this.writeEmitter.fire(activeCommand+this.endOfLine);
412+
413+
// Create the exe folder path if it doesn't exists.
414+
constexePath:string|undefined=util.findExePathInArgs(this.args);
415+
util.createDirIfNotExistsSync(exePath);
416+
413417
letchild:cp.ChildProcess|undefined;
414418
try{
415419
child=cp.spawn(command,this.args,this.options ?this.options :{});

‎Extension/src/common.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,16 @@ export function resolveCachePath(input: string | undefined, additionalEnvironmen
316316
returnresolvedPath;
317317
}
318318

319+
exportfunctiondefaultExePath():string{
320+
constisWindows:boolean=os.platform()==='win32';
321+
constexePath:string=path.join('${fileDirname}','${fileBasenameNoExtension}');
322+
returnisWindows ?exePath+'.exe' :exePath;
323+
}
324+
325+
exportfunctionfindExePathInArgs(args:string[]):string|undefined{
326+
returnargs.find((arg:string,index:number)=>(arg.includes(".exe")||(index>0&&args[index-1]==="-o")));
327+
}
328+
319329
// Pass in 'arrayResults' if a string[] result is possible and a delimited string result is undesirable.
320330
// The string[] result will be copied into 'arrayResults'.
321331
exportfunctionresolveVariables(input:string|undefined,additionalEnvironment?:{[key:string]:string|string[]},arrayResults?:string[]):string{
@@ -466,6 +476,16 @@ export function checkDirectoryExists(dirPath: string): Promise<boolean> {
466476
});
467477
}
468478

479+
exportfunctioncreateDirIfNotExistsSync(filePath:string|undefined):void{
480+
if(!filePath){
481+
return;
482+
}
483+
constdirPath:string=path.dirname(filePath);
484+
if(!checkDirectoryExistsSync(dirPath)){
485+
fs.mkdirSync(dirPath);
486+
}
487+
}
488+
469489
exportfunctioncheckFileExistsSync(filePath:string):boolean{
470490
try{
471491
returnfs.statSync(filePath).isFile();
@@ -1278,3 +1298,4 @@ export function isVsCodeInsiders(): boolean {
12781298
extensionPath.includes(".vscode-exploration")||
12791299
extensionPath.includes(".vscode-server-exploration");
12801300
}
1301+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp