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>pull/237656/head
parent
0e20692aaf
commit
7bfaf73501
|
@ -14,7 +14,8 @@
|
|||
"Other"
|
||||
],
|
||||
"enabledApiProposals": [
|
||||
"terminalCompletionProvider"
|
||||
"terminalCompletionProvider",
|
||||
"terminalShellEnv"
|
||||
],
|
||||
"scripts": {
|
||||
"compile": "npx gulp compile-extension:terminal-suggest",
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
"src/**/*",
|
||||
"src/completions/index.d.ts",
|
||||
"../../src/vscode-dts/vscode.d.ts",
|
||||
"../../src/vscode-dts/vscode.proposed.terminalCompletionProvider.d.ts"
|
||||
"../../src/vscode-dts/vscode.proposed.terminalCompletionProvider.d.ts",
|
||||
"../../src/vscode-dts/vscode.proposed.terminalShellEnv.d.ts"
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue