Skip to content

Commit 2c3d198

Browse files
authored
Convert to pull model diagnostics and improve flat config support (#1799)
* WIP * WIP * More flat config work * Bump version numbers * WIP * Handle ignored files correctly * Disable inter file dependencies * Update readme * Update version * Integrate latest lsp libraries
1 parent d1b62df commit 2c3d198

31 files changed

+4094
-881
lines changed

$shared/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export type ConfigurationSettings = {
155155
validate: Validate;
156156
packageManager: PackageManagers;
157157
useESLintClass: boolean;
158+
useFlatConfig?: boolean | undefined;
158159
experimental: {
159160
useFlatConfig: boolean;
160161
};

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
},
2020
"eslint.enable": true,
2121
"eslint.useESLintClass": true,
22+
"eslint.useFlatConfig": true,
2223
"eslint.codeActionsOnSave.rules": [
2324
"@typescript-eslint/semi",
2425
"@typescript-eslint/indent",
@@ -29,7 +30,7 @@
2930
"./client",
3031
"./server"
3132
],
32-
"eslint.trace.server": "off",
33+
"eslint.trace.server": "messages",
3334
"eslint.debug": false,
3435
"eslint.lintTask.enable": false,
3536
"eslint.format.enable": true,

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### Version 3.0.1 - pre-release
2+
3+
- converted the server to use diagnostic pull instead of push.
4+
- files will be revalidated on focus gain.
5+
- Add a command `ESLint: Revalidate all open files` to revalidate all open files.
6+
- Probing support for [Astro](https://github.com/microsoft/vscode-eslint/pull/1795), [MDX](https://github.com/microsoft/vscode-eslint/pull/1794) and [JSON](https://github.com/microsoft/vscode-eslint/pull/1787)
7+
- various [bug fixes](https://github.com/microsoft/vscode-eslint/issues?q=is%3Aclosed+milestone%3ANext)
8+
19
### Version 2.4.4
210

311
- same as 2.4.3 - pre-release

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ On new folders you might also need to create an `.eslintrc` configuration file.
2121

2222
This section describes major releases and their improvements. For a detailed list of changes please refer to the [change log](./CHANGELOG.md).
2323

24-
From version 2.2.3 on forward odd major, minor or patch version numbers indicate an insider or pre-release. So versions `2.2.3`, `2.2.5`, `2.3.1` and `3.0.0` will all be pre-release versions. `2.2.10`, `2.4.10` and `4.0.0` will all be regular release versions.
24+
From version 2.2.3 on forward odd minor or patch version numbers indicate an insider or pre-release. So versions `2.2.3`, `2.2.5` and `2.3.1` will all be pre-release versions. `2.2.10`, `2.4.10` and `3.0.0` will all be regular release versions.
25+
26+
### Version 3.0.1 - pre-release
27+
28+
- converted the server to use diagnostic pull instead of push.
29+
- files will be revalidated on focus gain.
30+
- Add a command `ESLint: Revalidate all open files` to revalidate all open files.
31+
- Probing support for [Astro](https://github.com/microsoft/vscode-eslint/pull/1795), [MDX](https://github.com/microsoft/vscode-eslint/pull/1794) and [JSON](https://github.com/microsoft/vscode-eslint/pull/1787)
32+
- various [bug fixes](https://github.com/microsoft/vscode-eslint/issues?q=is%3Aclosed+milestone%3ANext)
2533

2634
### Version 2.4.4
2735

client/package-lock.json

Lines changed: 62 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "client",
33
"displayName": "ESLint",
44
"description": "Integrates ESLint into VS Code.",
5-
"version": "2.4.1",
5+
"version": "3.0.1",
66
"private": true,
77
"author": "Microsoft Corporation",
88
"license": "MIT",
@@ -14,13 +14,13 @@
1414
"url": "https://github.com/Microsoft/vscode-eslint/issues"
1515
},
1616
"engines": {
17-
"vscode": "^1.68.0"
17+
"vscode": "^1.86.0"
1818
},
1919
"devDependencies": {
20-
"@types/vscode": "1.68.0"
20+
"@types/vscode": "1.86.0"
2121
},
2222
"dependencies": {
23-
"vscode-languageclient": "9.0.1"
23+
"vscode-languageclient": "10.0.0-next.2"
2424
},
2525
"scripts": {
2626
"test": "node ../node_modules/mocha/bin/_mocha",

client/src/client.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import {
1616
LanguageClient, LanguageClientOptions, TransportKind, ErrorHandler, CloseAction, RevealOutputChannelOn, ServerOptions, DocumentFilter,
1717
DidCloseTextDocumentNotification, DidOpenTextDocumentNotification, State, VersionedTextDocumentIdentifier, ExecuteCommandParams,
18-
ExecuteCommandRequest, ConfigurationParams, NotebookDocumentSyncRegistrationType
18+
ExecuteCommandRequest, ConfigurationParams, NotebookDocumentSyncRegistrationType, DiagnosticPullMode, DocumentDiagnosticRequest
1919
} from 'vscode-languageclient/node';
2020

2121
import { LegacyDirectoryItem, Migration, PatternItem, ValidateItem } from './settings';
@@ -308,11 +308,14 @@ export namespace ESLintClient {
308308
});
309309

310310
client.onRequest(ProbeFailedRequest.type, (params) => {
311-
validator.add(client.protocol2CodeConverter.asUri(params.textDocument.uri));
311+
const uri = client.protocol2CodeConverter.asUri(params.textDocument.uri);
312+
validator.add(uri);
312313
const closeFeature = client.getFeature(DidCloseTextDocumentNotification.method);
314+
const diagnosticsFeature = client.getFeature(DocumentDiagnosticRequest.method);
313315
for (const document of Workspace.textDocuments) {
314-
if (document.uri.toString() === params.textDocument.uri) {
316+
if (document.uri.toString() === uri.toString()) {
315317
closeFeature.getProvider(document)?.send(document).catch((error) => client.error(`Sending close notification failed`, error));
318+
diagnosticsFeature?.getProvider(document)?.forget(document);
316319
}
317320
}
318321
});
@@ -416,7 +419,6 @@ export namespace ESLintClient {
416419
function createClientOptions(): LanguageClientOptions {
417420
const clientOptions: LanguageClientOptions = {
418421
documentSelector: [{ scheme: 'file' }, { scheme: 'untitled' }],
419-
diagnosticCollectionName: 'eslint',
420422
revealOutputChannelOn: RevealOutputChannelOn.Never,
421423
initializationOptions: {
422424
},
@@ -445,6 +447,22 @@ export namespace ESLintClient {
445447
return defaultErrorHandler.closed();
446448
}
447449
},
450+
diagnosticPullOptions: {
451+
onChange: true,
452+
onSave: true,
453+
onFocus: true,
454+
filter: (document, mode) => {
455+
const config = Workspace.getConfiguration('eslint', document);
456+
const run = config.get<RunValues>('run', 'onType');
457+
if (mode === DiagnosticPullMode.onType && run !== 'onType') {
458+
return true;
459+
} else if (mode === DiagnosticPullMode.onSave && run !== 'onSave') {
460+
return true;
461+
}
462+
return validator.check(document) === Validate.off;
463+
},
464+
onTabs: false
465+
},
448466
middleware: {
449467
didOpen: async (document, next) => {
450468
if (Languages.match(packageJsonFilter, document) || Languages.match(configFileFilter, document) || validator.check(document) !== Validate.off) {
@@ -584,12 +602,12 @@ export namespace ESLintClient {
584602

585603
async function getPackageManager(uri: Uri) {
586604
const userProvidedPackageManager:PackageManagers = Workspace.getConfiguration('eslint', uri).get('packageManager', 'npm');
587-
const detectedPackageMananger = await commands.executeCommand<PackageManagers>('npm.packageManager');
605+
const detectedPackageManager = await commands.executeCommand<PackageManagers>('npm.packageManager');
588606

589-
if (userProvidedPackageManager === detectedPackageMananger) {
590-
return detectedPackageMananger;
607+
if (userProvidedPackageManager === detectedPackageManager) {
608+
return detectedPackageManager;
591609
}
592-
client.warn(`Detected package manager(${detectedPackageMananger}) differs from the one in the deprecated packageManager setting(${userProvidedPackageManager}). We will honor this setting until it is removed.`, {}, true);
610+
client.warn(`Detected package manager(${detectedPackageManager}) differs from the one in the deprecated packageManager setting(${userProvidedPackageManager}). We will honor this setting until it is removed.`, {}, true);
593611
return userProvidedPackageManager;
594612
}
595613

@@ -656,12 +674,14 @@ export namespace ESLintClient {
656674
}
657675
}
658676
});
677+
const useFlatConfig = config.get<boolean | null>('useFlatConfig', null);
659678
const settings: ConfigurationSettings = {
660679
validate: Validate.off,
661680
packageManager: config.get<PackageManagers>('packageManager', 'npm'),
662681
useESLintClass: config.get<boolean>('useESLintClass', false),
682+
useFlatConfig: useFlatConfig === null ? undefined : useFlatConfig,
663683
experimental: {
664-
useFlatConfig: config.get<boolean>('experimental.useFlatConfig', false)
684+
useFlatConfig: config.get<boolean>('experimental.useFlatConfig', false),
665685
},
666686
codeActionOnSave: {
667687
mode: CodeActionsOnSaveMode.all

0 commit comments

Comments
 (0)