Skip to content

Commit 9993384

Browse files
committed
fix #446
1 parent 68c313a commit 9993384

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/client/providers/setInterpreterProvider.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,21 @@ interface PythonPathQuickPickItem extends vscode.QuickPickItem {
2323

2424
function getSearchPaths(): Promise<string[]> {
2525
if (utils.IS_WINDOWS) {
26-
const lookupParentDirectories = ['PROGRAMFILES', 'PROGRAMFILES(X86)', 'LOCALAPPDATA', 'APPDATA', 'SystemDrive'];
26+
const localAppData = process.env['LOCALAPPDATA'];
27+
const appData = process.env['APPDATA'];
28+
const lookupParentDirectories = [process.env['PROGRAMFILES'], process.env['PROGRAMFILES(X86)'],
29+
localAppData, appData,
30+
process.env['SystemDrive']];
31+
if (appData){
32+
lookupParentDirectories.push(path.join(localAppData, 'Programs'))
33+
}
34+
if (localAppData){
35+
lookupParentDirectories.push(path.join(appData, 'Programs'))
36+
}
2737
const dirPromises = lookupParentDirectories.map(rootDir => {
38+
if (!rootDir) {
39+
return Promise.resolve([]);
40+
}
2841
const def = createDeferred<string[]>();
2942
fs.readdir(rootDir, (error, files) => {
3043
if (error) {
@@ -33,9 +46,13 @@ function getSearchPaths(): Promise<string[]> {
3346
const possiblePythonDirs = [];
3447
files.forEach(name => {
3548
const fullPath = path.join(rootDir, name);
36-
if (fs.statSync(fullPath).isDirectory() &&
37-
(name.toUpperCase().indexOf('PYTHON') >= 0 || name.toUpperCase().indexOf('ANACONDA') >= 0)) {
38-
possiblePythonDirs.push(fullPath);
49+
try {
50+
if ((name.toUpperCase().indexOf('PYTHON') >= 0 || name.toUpperCase().indexOf('ANACONDA') >= 0) &&
51+
fs.statSync(fullPath).isDirectory()) {
52+
possiblePythonDirs.push(fullPath);
53+
}
54+
}
55+
catch (ex) {
3956
}
4057
});
4158
def.resolve(possiblePythonDirs);
@@ -109,7 +126,7 @@ function suggestionsFromKnownPaths(): Promise<PythonPathSuggestion[]> {
109126
});
110127
return Promise.all<string[]>(promises).then(listOfInterpreters => {
111128
const suggestions: PythonPathSuggestion[] = [];
112-
const interpreters = listOfInterpreters.reduce((previous, current) => previous.concat(current));
129+
const interpreters = listOfInterpreters.reduce((previous, current) => previous.concat(current), []);
113130
interpreters.filter(interpter => interpter.length > 0).map(interpter => {
114131
suggestions.push({
115132
label: path.basename(interpter), path: interpter, type: ''

0 commit comments

Comments
 (0)