mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-03 06:51:53 +01:00
Use terminal shell env when resolving commands in path (#237588)
--------- Co-authored-by: Daniel Imms <Tyriar@users.noreply.github.com> Co-authored-by: Anthony Kim <62267334+anthonykim1@users.noreply.github.com>
This commit is contained in:
@@ -11,6 +11,7 @@ import codeInsidersCompletionSpec from './completions/code-insiders';
|
||||
import codeCompletionSpec from './completions/code';
|
||||
import cdSpec from './completions/cd';
|
||||
|
||||
let cachedAvailableCommandsPath: string | undefined;
|
||||
let cachedAvailableCommands: Set<string> | undefined;
|
||||
const cachedBuiltinCommands: Map<string, string[] | undefined> = new Map();
|
||||
|
||||
@@ -80,7 +81,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
return;
|
||||
}
|
||||
|
||||
const commandsInPath = await getCommandsInPath();
|
||||
const commandsInPath = await getCommandsInPath(terminal.shellIntegration?.env);
|
||||
const builtinCommands = getBuiltinCommands(shellPath);
|
||||
if (!commandsInPath || !builtinCommands) {
|
||||
return;
|
||||
@@ -129,6 +130,7 @@ export async function resolveCwdFromPrefix(prefix: string, currentCwd?: vscode.U
|
||||
|
||||
// Resolve the absolute path of the prefix
|
||||
const resolvedPath = path.resolve(currentCwd?.fsPath, relativeFolder);
|
||||
|
||||
const stat = await fs.stat(resolvedPath);
|
||||
|
||||
// Check if the resolved path exists and is a directory
|
||||
@@ -187,15 +189,30 @@ async function isExecutable(filePath: string): Promise<boolean> {
|
||||
}
|
||||
}
|
||||
|
||||
async function getCommandsInPath(): Promise<Set<string> | undefined> {
|
||||
if (cachedAvailableCommands) {
|
||||
return cachedAvailableCommands;
|
||||
async function getCommandsInPath(env: { [key: string]: string | undefined } = process.env): Promise<Set<string> | undefined> {
|
||||
// Get PATH value
|
||||
let pathValue: string | undefined;
|
||||
if (osIsWindows()) {
|
||||
const caseSensitivePathKey = Object.keys(env).find(key => key.toLowerCase() === 'path');
|
||||
if (caseSensitivePathKey) {
|
||||
pathValue = env[caseSensitivePathKey];
|
||||
}
|
||||
} else {
|
||||
pathValue = env.PATH;
|
||||
}
|
||||
const paths = osIsWindows() ? process.env.PATH?.split(';') : process.env.PATH?.split(':');
|
||||
if (!paths) {
|
||||
if (pathValue === undefined) {
|
||||
return;
|
||||
}
|
||||
const pathSeparator = osIsWindows() ? '\\' : '/';
|
||||
|
||||
// Check cache
|
||||
if (cachedAvailableCommands && cachedAvailableCommandsPath === pathValue) {
|
||||
return cachedAvailableCommands;
|
||||
}
|
||||
|
||||
// Extract executables from PATH
|
||||
const isWindows = osIsWindows();
|
||||
const paths = pathValue.split(isWindows ? ';' : ':');
|
||||
const pathSeparator = isWindows ? '\\' : '/';
|
||||
const executables = new Set<string>();
|
||||
for (const path of paths) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user