Skip to content

Commit 9f31dd7

Browse files
authored
* prepend pyOCD path instead of replace entire variable (#152)
* check if old collection mutator type and if path already included Signed-off-by: Jens Reinecke <jens.reinecke@arm.com>
1 parent 9a0a79f commit 9f31dd7

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/desktop/add-to-path.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ export function addPyocdToPath(context: vscode.ExtensionContext): void {
2929
logger.debug('pyOCD is not available');
3030
return;
3131
}
32-
//get PATH variable
33-
const pathVariable = process.env.PATH;
34-
if (!pathVariable) {
35-
logger.debug('pyOCD is not available');
32+
const delimiter = isWindows ? ';' : ':';
33+
const updatePath = `${pathPyOCD}${delimiter}`;
34+
//get current environment variable collection
35+
const mutator = context.environmentVariableCollection.get('PATH');
36+
// Path included and previously used type was 'Prepend'. Change mutator
37+
// if other type (we previously used 'Replace' which caused trouble).
38+
if (mutator?.type === vscode.EnvironmentVariableMutatorType.Prepend && mutator?.value.includes(updatePath)) {
39+
// Nothing to update
3640
return;
3741
}
38-
const delimiter = isWindows ? ';' : ':';
39-
const updatePath = pathPyOCD.concat(delimiter, pathVariable);
4042
//add updated path to PATH variable, but only for the terminal inside of vscode
41-
context.environmentVariableCollection.replace('PATH', updatePath);
43+
context.environmentVariableCollection.prepend('PATH', updatePath);
4244
}

0 commit comments

Comments
 (0)