Implements linting configuration#599
Implements linting configuration#599MikhailArkhipov merged 83 commits intomicrosoft:masterfrom MikhailArkhipov:lint
Conversation
Codecov Report
@@ Coverage Diff @@
## master #599 +/- ##
=========================================
- Coverage 60.67% 60.6% -0.07%
=========================================
Files 228 231 +3
Lines 10125 10478 +353
Branches 1753 1827 +74
=========================================
+ Hits 6143 6350 +207
- Misses 3977 4122 +145
- Partials 5 6 +1
Continue to review full report at Codecov.
|
.vscode/settings.json
Outdated
| "python.workspaceSymbols.enabled": false, | ||
| "python.formatting.provider": "none", | ||
| "files.insertFinalNewline": true | ||
| "files.insertFinalNewline": true, |
| "python.command.jupyter.gotToNextCell.title": "Go to Next Cell", | ||
| "python.command.python.goToPythonObject.title": "Go to Python Object", | ||
| "python.command.python.setLinter.title": "Select Linter", | ||
| "python.command.python.enableLinting.title": "Enable Linting", |
There was a problem hiding this comment.
Can we use this command to disable linting as well?
Three buttons, last being the default VS Code button.
E.g. Enable or disable linting [Enable Linting] [Disable Linting] [Close]
There was a problem hiding this comment.
It currently shows on/off list
src/client/common/configSettings.ts
Outdated
| export interface IPythonSettingsProvider { | ||
| getInstance(resource?: Uri): IPythonSettings; | ||
| // tslint:disable-next-line:no-any | ||
| updateSettingAsync(setting: string, value: any, resource?: Uri): Promise<void>; |
There was a problem hiding this comment.
Please change setting to a strongly typed value, we need to ensure only valid items are being set in here.
Similar to what has been done here https://github.com/Microsoft/vscode-python/blob/master/src/test/common.ts#L20
We also need a configuration target for this. Are we setting in:
- Global
- Workspace
- Workspace folder
Again, please check https://github.com/Microsoft/vscode-python/blob/master/src/test/common.ts#L20.
src/client/extension.ts
Outdated
| const deprecationMgr = new FeatureDeprecationManager(persistentStateFactory, !!jupyterExtInstalled); | ||
| deprecationMgr.initialize(); | ||
| context.subscriptions.push(new FeatureDeprecationManager(persistentStateFactory, !!jupyterExtInstalled)); | ||
| function configureIndentActions(): void { |
There was a problem hiding this comment.
Question: Should we move this into a separate folder, languages or formatters?
| return settings.linting[this.enabledSettingName] as boolean; | ||
| } | ||
|
|
||
| public pathName(resource?: Uri): string { |
There was a problem hiding this comment.
should this be named getPathName as its a method (verb)
| const settings = this.settingsProvider.getInstance(resource); | ||
| return settings.linting[this.pathSettingName] as string; | ||
| } | ||
| public linterArgs(resource?: Uri): string[] { |
There was a problem hiding this comment.
should this be named getLinterArgs as its a method (verb)
src/client/linters/linterCommands.ts
Outdated
| constructor(private serviceContainer: IServiceContainer, registerCommands: boolean) { | ||
| this.linterManager = this.serviceContainer.get<ILinterManager>(ILinterManager); | ||
| this.appShell = this.serviceContainer.get<IApplicationShell>(IApplicationShell); | ||
| if (registerCommands) { |
There was a problem hiding this comment.
FYI - No need to change, but I've introduced a ICommandManager to wrap the vscode.scommands namespace
|
|
||
| private async verifySetting(pythonConfig: WorkspaceConfiguration, target: ConfigurationTarget, settingName: string, value: {}): Promise<void> { | ||
| if (isTestExecution()) { | ||
| let retries = 0; |
There was a problem hiding this comment.
Can't we mock this? I have started moving this settings with the creation of workspacemanager to wrap vscode.wor
There was a problem hiding this comment.
This basically for test stability. It guarantees that the setting has actually updated (rather than waiting 5 seconds as in a few other places)
There was a problem hiding this comment.
Agreed, but I'm still reluctant to have this test specific code in the (production code) extension. Can't we move this into just the tests?
|
|
||
| await pythonConfig.update(setting, value, settingsInfo.target); | ||
| await this.verifySetting(pythonConfig, settingsInfo.target, setting, value); | ||
| PythonSettings.dispose(); |
There was a problem hiding this comment.
Do we need the check verify setting, I am reluctant to have it just for our tests. This should always work in production, hence not necessary, and mocking it should work.
| "python.command.jupyter.gotToNextCell.title": "Go to Next Cell", | ||
| "python.command.python.goToPythonObject.title": "Go to Python Object", | ||
| "python.command.python.setLinter.title": "Select Linter", | ||
| "python.command.python.enableLinting.title": "Enable Linting", |
| } | ||
|
|
||
| public static getSettingsUriAndTarget(resource?: Uri): { uri: Uri | undefined, target: ConfigurationTarget } { | ||
| const workspaceFolder = resource ? vscode.workspace.getWorkspaceFolder(resource) : undefined; |
There was a problem hiding this comment.
Please use IWorkspaceService instead of the vscode.workspace namespace. You should be able to mock the settings this way and be able to remove test specific code from the extension as well.
There was a problem hiding this comment.
Actually, I prefer to use actual objects where possible since they work same way in tests as they do at run time. Mocking is more for something that cannot be instantiated easily for whatever reason (ex project system in big VS) or simulate things that are hard to change (such as registry data - which requires Windows and admin rights).
|
|
||
| private async verifySetting(pythonConfig: WorkspaceConfiguration, target: ConfigurationTarget, settingName: string, value?: {}): Promise<void> { | ||
| if (isTestExecution()) { | ||
| let retries = 0; |
There was a problem hiding this comment.
Can we get rid of this, and use the mocked vscode.workspace namespace.
I'm very reluctant to have test specific code in here.
There was a problem hiding this comment.
What I've done in such situations is avoided updating settings, and just using a specific workspace with hardcoded settings in the settings.json file (if you look at the testMultiRootWkspace folder, you can see multiple workspace folders in there, some have settings.json with specific settings in there.
There was a problem hiding this comment.
It works at runtime, just not instantly. I observed actual value change in ~500-1000ms (and the config change event to fire). In tests it often ends up reading value that is stale. So it is not necessary to delay action in production but in tests it improves stability.
There was a problem hiding this comment.
So it is not necessary to delay action in production but in tests it improves stability.
If thats the case, why not move this delay into the tests itself. As this block of code never gets used in production, i.e. its test specific?
My only concern about this is the proliferation of if isTetExecution() in our code, just for tests.
There was a problem hiding this comment.
The problem here is that test would need to know that code it is calling might update the settings. For example, LinterManager.enableLinting and friends - and to know what key to use for ensuring the updated value. Since updating setting is rarely performance-critical (if ever), we can simple get it called in all cases. I'd reduce step to, say, 200ms and have 25 retries. It most cases operation completes in ~500ms so it should not be a big deal anyway.
| const pythonSettings = this.configurationService.getSettings(file); | ||
|
|
||
| this.setCwdForFileExecution(file); | ||
| await this.setCwdForFileExecution(file); |
…nto lint Fix Windows terminal tests
Fixes #572
Tests pass, merger with @DonJayamanne TS changes.