Skip to content

Commit 122c569

Browse files
authored
Deprecate the use of the setting python.autoComplete.preloadModules (#2646)
For DonJayamanne#1704
1 parent e7f7aed commit 122c569

8 files changed

Lines changed: 94 additions & 23 deletions

File tree

.github/test_plan.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ foo = 42 # Marked as a blacklisted name.
149149
Please also test for general accuracy on the most "interesting" code you can find.
150150

151151
- [ ] `"python.autoComplete.extraPaths"` works
152-
- [ ] `"python.autoComplete.preloadModules"` works (e.g. listing `numpy` should visibly speed up completing on the module's contents)
153152
- [ ] `"python.autocomplete.addBrackets": true` causes auto-completion of functions to append `()`
154153

155154
#### [Formatting](https://code.visualstudio.com/docs/python/editing#_formatting)

news/2 Fixes/1704.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecate the use of the setting `python.autoComplete.preloadModules`. Recommendation is to utilize the new language server (change the setting `"python.jediEnabled" = false`).

package.json

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -718,15 +718,6 @@
718718
"description": "List of paths to libraries and the like that need to be imported by auto complete engine. E.g. when using Google App SDK, the paths are not in system path, hence need to be added into this list.",
719719
"scope": "resource"
720720
},
721-
"python.autoComplete.preloadModules": {
722-
"type": "array",
723-
"items": {
724-
"type": "string"
725-
},
726-
"default": [],
727-
"description": "Comma delimited list of modules preloaded to speed up Auto Complete (e.g. add Numpy, Pandas, etc, items slow to load when autocompleting).",
728-
"scope": "resource"
729-
},
730721
"python.autoComplete.showAdvancedMembers": {
731722
"type": "boolean",
732723
"default": true,
@@ -1526,7 +1517,7 @@
15261517
"compile": "tsc -watch -p ./",
15271518
"postinstall": "node ./node_modules/vscode/bin/install",
15281519
"test": "node ./out/test/standardTest.js && node ./out/test/multiRootTest.js",
1529-
"test:unittests": "node ./out/test/unittests.js",
1520+
"test:unittests": "node ./out/test/unittests.js grep='Feature Deprecation Manager Tests'",
15301521
"testDebugger": "node ./out/test/debuggerTest.js",
15311522
"testSingleWorkspace": "node ./out/test/standardTest.js",
15321523
"testMultiWorkspace": "node ./out/test/multiRootTest.js",

src/client/common/configSettings.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
245245
this.autoComplete = this.autoComplete ? this.autoComplete : {
246246
extraPaths: [],
247247
addBrackets: false,
248-
preloadModules: [],
249248
showAdvancedMembers: false,
250249
typeshedPaths: []
251250
};

src/client/common/featureDeprecationManager.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ const deprecatedFeatures: DeprecatedFeatureInfo[] = [
2424
message: 'The setting \'python.linting.lintOnTextChange\' is deprecated, please enable \'python.linting.lintOnSave\' and \'files.autoSave\'.',
2525
moreInfoUrl: 'https://github.com/Microsoft/vscode-python/issues/313',
2626
setting: { setting: 'linting.lintOnTextChange', values: ['true', true] }
27+
},
28+
{
29+
doNotDisplayPromptStateKey: 'SHOW_DEPRECATED_FEATURE_PROMPT_FOR_AUTO_COMPLETE_PRELOAD_MODULES',
30+
message: 'The setting \'python.autoComplete.preloadModules\' is deprecated, please consider using the new Language Server (\'python.jediEnabled = false\').',
31+
moreInfoUrl: 'https://github.com/Microsoft/vscode-python/issues/1704',
32+
setting: { setting: 'autoComplete.preloadModules' }
2733
}
2834
];
2935

@@ -56,7 +62,7 @@ export class FeatureDeprecationManager implements IFeatureDeprecationManager {
5662
}
5763
}
5864

59-
private async notifyDeprecation(deprecatedInfo: DeprecatedFeatureInfo): Promise<void> {
65+
public async notifyDeprecation(deprecatedInfo: DeprecatedFeatureInfo): Promise<void> {
6066
const notificationPromptEnabled = this.persistentStateFactory.createGlobalPersistentState(deprecatedInfo.doNotDisplayPromptStateKey, true);
6167
if (!notificationPromptEnabled.value) {
6268
return;
@@ -83,7 +89,7 @@ export class FeatureDeprecationManager implements IFeatureDeprecationManager {
8389
return;
8490
}
8591

86-
private checkAndNotifyDeprecatedSetting(deprecatedInfo: DeprecatedFeatureInfo) {
92+
public checkAndNotifyDeprecatedSetting(deprecatedInfo: DeprecatedFeatureInfo) {
8793
let notify = false;
8894
if (Array.isArray(this.workspace.workspaceFolders) && this.workspace.workspaceFolders.length > 0) {
8995
this.workspace.workspaceFolders.forEach(workspaceFolder => {
@@ -102,11 +108,26 @@ export class FeatureDeprecationManager implements IFeatureDeprecationManager {
102108
}
103109
}
104110

105-
private isDeprecatedSettingAndValueUsed(pythonConfig: WorkspaceConfiguration, deprecatedSetting: DeprecatedSettingAndValue) {
111+
public isDeprecatedSettingAndValueUsed(pythonConfig: WorkspaceConfiguration, deprecatedSetting: DeprecatedSettingAndValue) {
106112
if (!pythonConfig.has(deprecatedSetting.setting)) {
107113
return false;
108114
}
115+
const configValue = pythonConfig.get(deprecatedSetting.setting);
116+
if (!Array.isArray(deprecatedSetting.values) || deprecatedSetting.values.length === 0) {
117+
if (Array.isArray(configValue)) {
118+
return configValue.length > 0;
119+
}
120+
return true;
121+
}
109122
if (!Array.isArray(deprecatedSetting.values) || deprecatedSetting.values.length === 0) {
123+
if (configValue === undefined) {
124+
return false;
125+
}
126+
if (Array.isArray(configValue)) {
127+
// tslint:disable-next-line:no-any
128+
return (configValue as any[]).length > 0;
129+
}
130+
// If we have a value in the setting, then return.
110131
return true;
111132
}
112133
return deprecatedSetting.values.indexOf(pythonConfig.get(deprecatedSetting.setting)!) >= 0;

src/client/common/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ export interface IFormattingSettings {
226226
export interface IAutoCompleteSettings {
227227
readonly addBrackets: boolean;
228228
readonly extraPaths: string[];
229-
readonly preloadModules: string[];
230229
readonly showAdvancedMembers: boolean;
231230
readonly typeshedPaths: string[];
232231
}

src/client/providers/jediProxy.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,6 @@ export class JediProxy implements Disposable {
348348
args.push('custom');
349349
args.push(this.pythonSettings.jediPath);
350350
}
351-
if (this.pythonSettings.autoComplete &&
352-
Array.isArray(this.pythonSettings.autoComplete.preloadModules) &&
353-
this.pythonSettings.autoComplete.preloadModules.length > 0) {
354-
const modules = this.pythonSettings.autoComplete.preloadModules.filter(m => m.trim().length > 0).join(',');
355-
args.push(modules);
356-
}
357351
const result = pythonProcess.execObservable(args, { cwd });
358352
this.proc = result.proc;
359353
this.languageServerStarted.resolve();

src/test/common/featureDeprecationManager.unit.test.ts

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
'use strict';
55

6+
// tslint:disable:max-func-body-length no-any
7+
8+
import { expect } from 'chai';
69
import * as TypeMoq from 'typemoq';
710
import { Disposable, WorkspaceConfiguration } from 'vscode';
811
import {
@@ -12,7 +15,7 @@ import {
1215
FeatureDeprecationManager
1316
} from '../../client/common/featureDeprecationManager';
1417
import {
15-
IPersistentState, IPersistentStateFactory
18+
DeprecatedSettingAndValue, IPersistentState, IPersistentStateFactory
1619
} from '../../client/common/types';
1720

1821
suite('Feature Deprecation Manager Tests', () => {
@@ -66,4 +69,68 @@ suite('Feature Deprecation Manager Tests', () => {
6669

6770
featureDepMgr.initialize();
6871
});
72+
test('Ensure setting is checked', () => {
73+
const pythonConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
74+
const deprecatedSetting: DeprecatedSettingAndValue = { setting: 'autoComplete.preloadModules' };
75+
// tslint:disable-next-line:no-any
76+
const _ = {} as any;
77+
const featureDepMgr = new FeatureDeprecationManager(_, _, _, _);
78+
79+
pythonConfig
80+
.setup(p => p.has(TypeMoq.It.isValue(deprecatedSetting.setting)))
81+
.returns(() => false)
82+
.verifiable(TypeMoq.Times.atLeastOnce());
83+
84+
let isUsed = featureDepMgr.isDeprecatedSettingAndValueUsed(pythonConfig.object, deprecatedSetting);
85+
pythonConfig.verifyAll();
86+
expect(isUsed).to.be.equal(false, 'Setting should not be used');
87+
88+
type TestConfigs = { valueInSetting: any; expectedValue: boolean; valuesToLookFor?: any[] };
89+
let testConfigs: TestConfigs[] = [
90+
{ valueInSetting: [], expectedValue: false },
91+
{ valueInSetting: ['1'], expectedValue: true },
92+
{ valueInSetting: [1], expectedValue: true },
93+
{ valueInSetting: [{}], expectedValue: true }
94+
];
95+
96+
for (const config of testConfigs) {
97+
pythonConfig.reset();
98+
pythonConfig
99+
.setup(p => p.has(TypeMoq.It.isValue(deprecatedSetting.setting)))
100+
.returns(() => true)
101+
.verifiable(TypeMoq.Times.atLeastOnce());
102+
pythonConfig
103+
.setup(p => p.get(TypeMoq.It.isValue(deprecatedSetting.setting)))
104+
.returns(() => config.valueInSetting);
105+
106+
isUsed = featureDepMgr.isDeprecatedSettingAndValueUsed(pythonConfig.object, deprecatedSetting);
107+
108+
pythonConfig.verifyAll();
109+
expect(isUsed).to.be.equal(config.expectedValue, `Failed for config = ${JSON.stringify(config)}`);
110+
}
111+
112+
testConfigs = [
113+
{ valueInSetting: 'true', expectedValue: true, valuesToLookFor: ['true', true] },
114+
{ valueInSetting: true, expectedValue: true, valuesToLookFor: ['true', true] },
115+
{ valueInSetting: 'false', expectedValue: true, valuesToLookFor: ['false', false] },
116+
{ valueInSetting: false, expectedValue: true, valuesToLookFor: ['false', false] }
117+
];
118+
119+
for (const config of testConfigs) {
120+
pythonConfig.reset();
121+
pythonConfig
122+
.setup(p => p.has(TypeMoq.It.isValue(deprecatedSetting.setting)))
123+
.returns(() => true)
124+
.verifiable(TypeMoq.Times.atLeastOnce());
125+
pythonConfig
126+
.setup(p => p.get(TypeMoq.It.isValue(deprecatedSetting.setting)))
127+
.returns(() => config.valueInSetting);
128+
129+
deprecatedSetting.values = config.valuesToLookFor;
130+
isUsed = featureDepMgr.isDeprecatedSettingAndValueUsed(pythonConfig.object, deprecatedSetting);
131+
132+
pythonConfig.verifyAll();
133+
expect(isUsed).to.be.equal(config.expectedValue, `Failed for config = ${JSON.stringify(config)}`);
134+
}
135+
});
69136
});

0 commit comments

Comments
 (0)