-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#1228 multiroot interpreter display #1339
Changes from 42 commits
aad5ca0
a819f69
3b48d84
b290a7e
1e979b9
0959155
5ad6d1f
26241f2
6f3aba4
35a9cbe
f5e4006
34aefa2
3c58408
252a52e
6acaa7a
d137b75
65076f8
630f83a
0dad286
9a283c7
9f90a42
31aa28f
63180f0
7bdc669
5956a47
7c8049f
0f6b142
8570b90
71f3507
c339fab
b0d29da
dfc7451
a8eda55
32b6d85
155e45f
df14e35
1b58b20
f9e8915
7d4f0f7
4f880a1
000a25a
665a233
22cc2e7
3cbc067
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Uri, workspace } from 'vscode'; | ||
|
||
type InterpreterCache = { | ||
pythonInterpreterDirectory?: string; | ||
pythonInterpreterPath?: string; | ||
pythonSettingsPath?: string; | ||
// tslint:disable-next-line:no-any | ||
customEnvVariables?: any; | ||
}; | ||
|
||
const cache = new Map<string, InterpreterCache>(); | ||
|
||
// tslint:disable-next-line:no-stateless-class | ||
export class InterpreterInfoCache { | ||
// tslint:disable-next-line:function-name | ||
public static clear(): void { | ||
cache.clear(); | ||
} | ||
// tslint:disable-next-line:function-name | ||
public static get(resource?: Uri) { | ||
const cacheKey = InterpreterInfoCache.getCacheKey(resource) || ''; | ||
return cache.has(cacheKey) ? cache.get(cacheKey) : {}; | ||
} | ||
// tslint:disable-next-line:function-name | ||
public static setPaths(resource?: Uri, pythonSettingsPath?: string, pythonInterpreterPath?: string, pythonInterpreterDirectory?: string) { | ||
InterpreterInfoCache.setCacheData('pythonInterpreterDirectory', resource, pythonInterpreterDirectory); | ||
InterpreterInfoCache.setCacheData('pythonInterpreterPath', resource, pythonInterpreterPath); | ||
InterpreterInfoCache.setCacheData('pythonSettingsPath', resource, pythonSettingsPath); | ||
} | ||
|
||
// tslint:disable-next-line:no-any function-name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So is this instead of declaring the variable as void? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No it's to treat a variable as one that has no type information. (Kind of like removing type hints when a variable has had type hints defined) |
||
public static setCustomEnvVariables(resource?: Uri, envVars?: any) { | ||
// tslint:disable-next-line:no-any | ||
InterpreterInfoCache.setCacheData('customEnvVariables', resource, envVars); | ||
} | ||
// tslint:disable-next-line:no-any function-name | ||
private static setCacheData(property: keyof InterpreterCache, resource?: Uri, value?: string | any) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does declaring the type as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh, can't understand why that was added. Yes you are right |
||
const cacheKey = InterpreterInfoCache.getCacheKey(resource) || ''; | ||
// tslint:disable-next-line:prefer-type-cast | ||
const data = cache.has(cacheKey) ? cache.get(cacheKey) : {} as InterpreterCache; | ||
data[property] = value; | ||
cache.set(cacheKey, data); | ||
} | ||
private static getCacheKey(resource?: Uri): string { | ||
if (!Array.isArray(workspace.workspaceFolders) || workspace.workspaceFolders.length === 0) { | ||
return ''; | ||
} | ||
if (!resource || workspace.workspaceFolders.length === 1) { | ||
return workspace.workspaceFolders[0].uri.fsPath; | ||
} | ||
const folder = workspace.getWorkspaceFolder(resource); | ||
return folder ? folder.uri.fsPath : ''; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Let's"