mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Add python.analysis.autoImportCompletions to control auto-import completions (#917)
This commit is contained in:
parent
1c396ac436
commit
b89504d593
@ -67,6 +67,12 @@
|
||||
"type": "object",
|
||||
"title": "Pyright",
|
||||
"properties": {
|
||||
"python.analysis.autoImportCompletions": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "Offer auto-import completions.",
|
||||
"scope": "resource"
|
||||
},
|
||||
"python.analysis.autoSearchPaths": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
|
@ -10,6 +10,8 @@ The Pyright VS Code extension honors the following settings.
|
||||
|
||||
**pyright.useLibraryCodeForTypes** [boolean]: This setting is deprecated in favor of python.analysis.useLibraryCodeForTypes. It will be removed at a future time.
|
||||
|
||||
**python.analysis.autoImportCompletions** [boolean]: Determines whether pyright offers auto-import completions.
|
||||
|
||||
**python.analysis.autoSearchPaths** [boolean]: Determines whether pyright automatically adds common search paths like "src" if there are no execution environments defined in the config file.
|
||||
|
||||
**python.analysis.diagnosticMode** ["openFilesOnly", "workspace"]: Determines whether pyright analyzes (and reports errors for) all files in the workspace, as indicated by the config file. If this option is set to "openFilesOnly", pyright analyzes only open files.
|
||||
|
@ -504,6 +504,7 @@ export class AnalyzerService {
|
||||
configOptions.verboseOutput = !!commandLineOptions.verboseOutput;
|
||||
configOptions.checkOnlyOpenFiles = !!commandLineOptions.checkOnlyOpenFiles;
|
||||
configOptions.useLibraryCodeForTypes = !!commandLineOptions.useLibraryCodeForTypes;
|
||||
configOptions.autoImportCompletions = !!commandLineOptions.autoImportCompletions;
|
||||
|
||||
// If there was no stub path specified, use a default path.
|
||||
if (commandLineOptions.stubPath) {
|
||||
|
@ -434,6 +434,7 @@ function createConfigOptionsFrom(jsonObject: any): ConfigOptions {
|
||||
configOptions.defaultPythonPlatform = jsonObject.defaultPythonPlatform;
|
||||
configOptions.diagnosticRuleSet = jsonObject.diagnosticRuleSet;
|
||||
configOptions.executionEnvironments = jsonObject.executionEnvironments;
|
||||
configOptions.autoImportCompletions = jsonObject.autoImportCompletions;
|
||||
configOptions.include = jsonObject.include.map((f: any) => getFileSpec(f));
|
||||
configOptions.exclude = jsonObject.exclude.map((f: any) => getFileSpec(f));
|
||||
configOptions.ignore = jsonObject.ignore.map((f: any) => getFileSpec(f));
|
||||
|
@ -100,4 +100,7 @@ export class CommandLineOptions {
|
||||
|
||||
// Indicates diagnostic severity overrides
|
||||
diagnosticSeverityOverrides?: DiagnosticSeverityOverridesMap;
|
||||
|
||||
// Offer auto-import completions.
|
||||
autoImportCompletions?: boolean;
|
||||
}
|
||||
|
@ -488,6 +488,9 @@ export class ConfigOptions {
|
||||
// type information?
|
||||
useLibraryCodeForTypes: boolean;
|
||||
|
||||
// Offer auto-import completions.
|
||||
autoImportCompletions = true;
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Diagnostics Rule Set
|
||||
|
||||
@ -1110,6 +1113,15 @@ export class ConfigOptions {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Read the "autoImportCompletions" setting.
|
||||
if (configObj.autoImportCompletions !== undefined) {
|
||||
if (typeof configObj.autoImportCompletions !== 'boolean') {
|
||||
console.info(`Config "autoImportCompletions" field must be true or false.`);
|
||||
} else {
|
||||
this.autoImportCompletions = configObj.autoImportCompletions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ensureDefaultPythonPlatform(console: ConsoleInterface) {
|
||||
|
@ -95,6 +95,7 @@ export interface ServerSettings {
|
||||
watchForLibraryChanges?: boolean;
|
||||
diagnosticSeverityOverrides?: DiagnosticSeverityOverridesMap;
|
||||
logLevel?: LogLevel;
|
||||
autoImportCompletions?: boolean;
|
||||
}
|
||||
|
||||
export interface WorkspaceServiceInstance {
|
||||
|
@ -44,6 +44,7 @@ function getEffectiveCommandLineOptions(
|
||||
commandLineOptions.checkOnlyOpenFiles = serverSettings.openFilesOnly;
|
||||
commandLineOptions.useLibraryCodeForTypes = serverSettings.useLibraryCodeForTypes;
|
||||
commandLineOptions.typeCheckingMode = serverSettings.typeCheckingMode;
|
||||
commandLineOptions.autoImportCompletions = serverSettings.autoImportCompletions;
|
||||
|
||||
if (!trackFiles) {
|
||||
commandLineOptions.watchForSourceChanges = false;
|
||||
|
@ -592,7 +592,7 @@ export class CompletionProvider {
|
||||
|
||||
// Add auto-import suggestions from other modules.
|
||||
// Ignore this check for privates, since they are not imported.
|
||||
if (!priorWord.startsWith('_') && !this._itemToResolve) {
|
||||
if (this._configOptions.autoImportCompletions && !priorWord.startsWith('_') && !this._itemToResolve) {
|
||||
this._getAutoImportCompletions(priorWord, completionList);
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,7 @@ class PyrightServer extends LanguageServerBase {
|
||||
typeCheckingMode: 'basic',
|
||||
diagnosticSeverityOverrides: {},
|
||||
logLevel: LogLevel.Info,
|
||||
autoImportCompletions: true,
|
||||
};
|
||||
|
||||
try {
|
||||
@ -116,6 +117,10 @@ class PyrightServer extends LanguageServerBase {
|
||||
if (pythonAnalysisSection.typeCheckingMode !== undefined) {
|
||||
serverSettings.typeCheckingMode = pythonAnalysisSection.typeCheckingMode;
|
||||
}
|
||||
|
||||
if (pythonAnalysisSection.autoImportCompletions !== undefined) {
|
||||
serverSettings.autoImportCompletions = pythonAnalysisSection.autoImportCompletions;
|
||||
}
|
||||
} else {
|
||||
serverSettings.autoSearchPaths = true;
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @filename: mspythonconfig.json
|
||||
//// {
|
||||
//// "autoImportCompletions": false
|
||||
//// }
|
||||
|
||||
// @filename: test1.py
|
||||
//// Test[|/*marker*/|]
|
||||
|
||||
// @filename: test2.py
|
||||
//// class Test:
|
||||
//// pass
|
||||
|
||||
// @ts-ignore
|
||||
await helper.verifyCompletion('excluded', {
|
||||
marker: {
|
||||
completions: [
|
||||
{
|
||||
label: 'Test',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
@ -62,6 +62,7 @@ export class TestLanguageService implements LanguageServerInterface {
|
||||
openFilesOnly: this._workspace.serviceInstance.getConfigOptions().checkOnlyOpenFiles,
|
||||
useLibraryCodeForTypes: this._workspace.serviceInstance.getConfigOptions().useLibraryCodeForTypes,
|
||||
disableLanguageServices: this._workspace.disableLanguageServices,
|
||||
autoImportCompletions: this._workspace.serviceInstance.getConfigOptions().autoImportCompletions,
|
||||
};
|
||||
|
||||
return settings;
|
||||
|
Loading…
Reference in New Issue
Block a user