1616
1717import * as vscode from 'vscode' ;
1818import { logger } from '../../logger' ;
19- import { GDBTargetConfiguration } from '../gdbtarget-configuration' ;
19+ import { GDBTargetConfiguration , TargetConfiguration } from '../gdbtarget-configuration' ;
20+ import { BuiltinToolPath } from '../../desktop/builtin-tool-path' ;
2021
22+ const PYOCD_BUILTIN_PATH = 'tools/pyocd/pyocd' ;
23+ export const PYOCD_EXECUTABLE_ONLY_REGEXP = / ^ \s * p y o c d ( | .e x e ) \s * $ / i;
2124export const PYOCD_SERVER_TYPE_REGEXP = / .* p y o c d ( | .e x e ) \s * $ / i;
2225
2326export class PyocdConfigurationProvider implements vscode . DebugConfigurationProvider {
27+ protected builtinPyocd = new BuiltinToolPath ( PYOCD_BUILTIN_PATH ) ;
2428
2529 protected async hasCommand ( commandName : string ) : Promise < boolean > {
2630 const commands = await vscode . commands . getCommands ( ) ;
@@ -35,10 +39,22 @@ export class PyocdConfigurationProvider implements vscode.DebugConfigurationProv
3539 return ! this . hasParam ( paramName , params ) && ( ! commandName || await this . hasCommand ( commandName ) ) ;
3640 }
3741
42+ protected resolveServerPath ( target : TargetConfiguration ) : void {
43+ const targetServer = target . server ;
44+ const useBuiltin = ! targetServer || PYOCD_EXECUTABLE_ONLY_REGEXP . test ( targetServer ) ;
45+ const builtinUri = useBuiltin ? this . builtinPyocd . getAbsolutePath ( ) : undefined ;
46+ if ( builtinUri ) {
47+ target . server = builtinUri . fsPath ;
48+ }
49+ }
50+
3851 protected async resolveServerParameters ( debugConfiguration : GDBTargetConfiguration ) : Promise < GDBTargetConfiguration > {
3952 if ( ! debugConfiguration . target ) {
4053 return debugConfiguration ;
4154 }
55+ // server
56+ this . resolveServerPath ( debugConfiguration . target ) ;
57+ // serverParameters
4258 const parameters = debugConfiguration . target . serverParameters ??= [ ] ;
4359 // gdbserver
4460 if ( await this . shouldAppendParam ( parameters , 'gdbserver' ) ) {
0 commit comments