Skip to content

Commit 9deec1a

Browse files
karthiknadigkimadelinejakebailey
authored
Hot fixes for pylint and jediEnabled issues (#12556)
* Fix `linting.pylintEnabled` setting check (#12444) * Fix `linting.pylintEnabled` setting check * Use stub instead of handspun variable * Don't modify LS settings if jediEnabled does not exist (#12551) * Update change logs and version Co-authored-by: Kim-Adeline Miguel <[email protected]> Co-authored-by: Jake Bailey <[email protected]>
1 parent dd22ae9 commit 9deec1a

File tree

7 files changed

+73
-24
lines changed

7 files changed

+73
-24
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## 2020.6.2 (25 June 2020)
4+
5+
### Fixes
6+
7+
1. Fix `linting.pylintEnabled` setting check.
8+
([#12285](https://github.com/Microsoft/vscode-python/issues/12285))
9+
1. Don't modify LS settings if jediEnabled does not exist.
10+
([#12429](https://github.com/Microsoft/vscode-python/issues/12429))
11+
312
## 2020.6.1 (17 June 2020)
413

514
### Fixes

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "python",
33
"displayName": "Python",
44
"description": "Linting, Debugging (multi-threaded, remote), Intellisense, Jupyter Notebooks, code formatting, refactoring, unit tests, snippets, and more.",
5-
"version": "2020.6.1",
5+
"version": "2020.6.2",
66
"featureFlags": {
77
"usingNewInterpreterStorage": true
88
},

src/client/linters/linterInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class PylintLinterInfo extends LinterInfo {
9999
// If we're using LS, then by default Pylint is disabled unless user provided
100100
// the value. We have to resort to direct inspection of settings here.
101101
const configuration = this.workspaceService.getConfiguration('python', resource);
102-
const inspection = configuration.inspect<boolean>(this.enabledSettingName);
102+
const inspection = configuration.inspect<boolean>(`linting.${this.enabledSettingName}`);
103103
if (
104104
!inspection ||
105105
(inspection.globalValue === undefined &&

src/client/testing/common/updateTestSettings.ts

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'use strict';
55

66
import { inject, injectable } from 'inversify';
7-
import { applyEdits, Edit, findNodeAtLocation, FormattingOptions, getNodeValue, modify, parseTree } from 'jsonc-parser';
7+
import { applyEdits, findNodeAtLocation, getNodeValue, ModificationOptions, modify, parseTree } from 'jsonc-parser';
88
import * as path from 'path';
99
import { IExtensionActivationService, LanguageServerType } from '../../activation/types';
1010
import { IApplicationEnvironment, IWorkspaceService } from '../../common/application/types';
@@ -104,7 +104,8 @@ export class UpdateTestSettingService implements IExtensionActivationService {
104104

105105
private fixLanguageServerSettings(fileContent: string): string {
106106
// `python.jediEnabled` is deprecated:
107-
// - `true` or missing then set to `languageServer: Jedi`.
107+
// - If missing, do nothing.
108+
// - `true`, then set to `languageServer: Jedi`.
108109
// - `false` and `languageServer` is present, do nothing.
109110
// - `false` and `languageServer` is NOT present, set `languageServer` to `Microsoft`.
110111
// `jediEnabled` is NOT removed since JSONC parser may also remove comments.
@@ -113,28 +114,40 @@ export class UpdateTestSettingService implements IExtensionActivationService {
113114

114115
try {
115116
const ast = parseTree(fileContent);
117+
116118
const jediEnabledNode = findNodeAtLocation(ast, jediEnabledPath);
117-
const jediEnabled = jediEnabledNode ? getNodeValue(jediEnabledNode) : true;
118119
const languageServerNode = findNodeAtLocation(ast, languageServerPath);
119-
const formattingOptions: FormattingOptions = {
120-
tabSize: 4,
121-
insertSpaces: true
122-
};
123-
let edits: Edit[] = [];
124-
125-
if (!jediEnabledNode || jediEnabled) {
126-
// `jediEnabled` is missing or is true. Default is true, so assume Jedi.
127-
edits = modify(fileContent, languageServerPath, LanguageServerType.Jedi, { formattingOptions });
128-
} else {
129-
// `jediEnabled` is false. if languageServer is missing, set it to Microsoft.
130-
if (!languageServerNode) {
131-
edits = modify(fileContent, languageServerPath, LanguageServerType.Microsoft, {
132-
formattingOptions
133-
});
120+
121+
// If missing, do nothing.
122+
if (!jediEnabledNode) {
123+
return fileContent;
124+
}
125+
126+
const jediEnabled = getNodeValue(jediEnabledNode);
127+
128+
const modificationOptions: ModificationOptions = {
129+
formattingOptions: {
130+
tabSize: 4,
131+
insertSpaces: true
134132
}
133+
};
134+
135+
// `jediEnabled` is true, set it to Jedi.
136+
if (jediEnabled) {
137+
return applyEdits(
138+
fileContent,
139+
modify(fileContent, languageServerPath, LanguageServerType.Jedi, modificationOptions)
140+
);
141+
}
142+
143+
// `jediEnabled` is false. if languageServer is missing, set it to Microsoft.
144+
if (!languageServerNode) {
145+
return applyEdits(
146+
fileContent,
147+
modify(fileContent, languageServerPath, LanguageServerType.Microsoft, modificationOptions)
148+
);
135149
}
136150

137-
fileContent = applyEdits(fileContent, edits);
138151
// tslint:disable-next-line:no-empty
139152
} catch {}
140153
return fileContent;

src/test/application/diagnostics/checks/updateTestSettings.unit.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,14 @@ suite('Application Diagnostics - Check Test Settings', () => {
217217

218218
[
219219
{
220-
testTitle: 'No jediEnabled setting.',
220+
testTitle: 'No jediEnabled setting',
221221
contents: '{}',
222-
expectedContent: '{ "python.languageServer": "Jedi" }'
222+
expectedContent: '{}'
223+
},
224+
{
225+
testTitle: 'jediEnabled setting in comment',
226+
contents: '{\n // "python.jediEnabled": true\n }',
227+
expectedContent: '{\n // "python.jediEnabled": true\n }'
223228
},
224229
{
225230
testTitle: 'jediEnabled: true, no languageServer setting',
@@ -250,6 +255,11 @@ suite('Application Diagnostics - Check Test Settings', () => {
250255
testTitle: 'jediEnabled: false, languageServer is Jedi',
251256
contents: '{ "python.jediEnabled": false, "python.languageServer": "Jedi" }',
252257
expectedContent: '{ "python.jediEnabled": false, "python.languageServer": "Jedi"}'
258+
},
259+
{
260+
testTitle: 'jediEnabled not present, languageServer is Microsoft',
261+
contents: '{ "python.languageServer": "Microsoft" }',
262+
expectedContent: '{ "python.languageServer": "Microsoft" }'
253263
}
254264
].forEach((item) => {
255265
test(item.testTitle, async () => {

src/test/linters/linterinfo.unit.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// tslint:disable:chai-vague-errors no-unused-expression max-func-body-length no-any
77

88
import { expect } from 'chai';
9+
import * as sinon from 'sinon';
910
import { anything, instance, mock, when } from 'ts-mockito';
1011
import { LanguageServerType } from '../../client/activation/types';
1112
import { WorkspaceService } from '../../client/common/application/workspace';
@@ -62,6 +63,22 @@ suite('Linter Info - Pylint', () => {
6263

6364
expect(linterInfo.isEnabled()).to.be.false;
6465
});
66+
test('Should inspect the value of linting.pylintEnabled when using Language Server', async () => {
67+
const linterInfo = new PylintLinterInfo(instance(config), instance(workspace), []);
68+
const inspectStub = sinon.stub();
69+
const pythonConfig = {
70+
inspect: inspectStub
71+
};
72+
73+
when(config.getSettings(anything())).thenReturn({
74+
linting: { pylintEnabled: true },
75+
languageServer: LanguageServerType.Microsoft
76+
} as any);
77+
when(workspace.getConfiguration('python', anything())).thenReturn(pythonConfig as any);
78+
79+
expect(linterInfo.isEnabled()).to.be.false;
80+
expect(inspectStub.calledOnceWith('linting.pylintEnabled')).to.be.true;
81+
});
6582
const testsForisEnabled = [
6683
{
6784
testName: 'When workspaceFolder setting is provided',

0 commit comments

Comments
 (0)