Skip to content

Convert to pull model diagnostics and improve flat config support #1799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions $shared/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export type ConfigurationSettings = {
validate: Validate;
packageManager: PackageManagers;
useESLintClass: boolean;
useFlatConfig?: boolean | undefined;
experimental: {
useFlatConfig: boolean;
};
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"eslint.enable": true,
"eslint.useESLintClass": true,
"eslint.useFlatConfig": true,
"eslint.codeActionsOnSave.rules": [
"@typescript-eslint/semi",
"@typescript-eslint/indent",
Expand All @@ -29,7 +30,7 @@
"./client",
"./server"
],
"eslint.trace.server": "off",
"eslint.trace.server": "messages",
"eslint.debug": false,
"eslint.lintTask.enable": false,
"eslint.format.enable": true,
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### Version 3.0.1 - pre-release

- converted the server to use diagnostic pull instead of push.
- files will be revalidated on focus gain.
- Add a command `ESLint: Revalidate all open files` to revalidate all open files.
- 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)
- various [bug fixes](https://github.com/microsoft/vscode-eslint/issues?q=is%3Aclosed+milestone%3ANext)

### Version 2.4.4

- same as 2.4.3 - pre-release
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ On new folders you might also need to create an `.eslintrc` configuration file.

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

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.
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.

### Version 3.0.1 - pre-release

- converted the server to use diagnostic pull instead of push.
- files will be revalidated on focus gain.
- Add a command `ESLint: Revalidate all open files` to revalidate all open files.
- 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)
- various [bug fixes](https://github.com/microsoft/vscode-eslint/issues?q=is%3Aclosed+milestone%3ANext)

### Version 2.4.4

Expand Down
121 changes: 62 additions & 59 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "client",
"displayName": "ESLint",
"description": "Integrates ESLint into VS Code.",
"version": "2.4.1",
"version": "3.0.1",
"private": true,
"author": "Microsoft Corporation",
"license": "MIT",
Expand All @@ -14,13 +14,13 @@
"url": "https://github.com/Microsoft/vscode-eslint/issues"
},
"engines": {
"vscode": "^1.68.0"
"vscode": "^1.86.0"
},
"devDependencies": {
"@types/vscode": "1.68.0"
"@types/vscode": "1.86.0"
},
"dependencies": {
"vscode-languageclient": "9.0.1"
"vscode-languageclient": "10.0.0-next.2"
},
"scripts": {
"test": "node ../node_modules/mocha/bin/_mocha",
Expand Down
38 changes: 29 additions & 9 deletions client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import {
LanguageClient, LanguageClientOptions, TransportKind, ErrorHandler, CloseAction, RevealOutputChannelOn, ServerOptions, DocumentFilter,
DidCloseTextDocumentNotification, DidOpenTextDocumentNotification, State, VersionedTextDocumentIdentifier, ExecuteCommandParams,
ExecuteCommandRequest, ConfigurationParams, NotebookDocumentSyncRegistrationType
ExecuteCommandRequest, ConfigurationParams, NotebookDocumentSyncRegistrationType, DiagnosticPullMode, DocumentDiagnosticRequest
} from 'vscode-languageclient/node';

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

client.onRequest(ProbeFailedRequest.type, (params) => {
validator.add(client.protocol2CodeConverter.asUri(params.textDocument.uri));
const uri = client.protocol2CodeConverter.asUri(params.textDocument.uri);
validator.add(uri);
const closeFeature = client.getFeature(DidCloseTextDocumentNotification.method);
const diagnosticsFeature = client.getFeature(DocumentDiagnosticRequest.method);
for (const document of Workspace.textDocuments) {
if (document.uri.toString() === params.textDocument.uri) {
if (document.uri.toString() === uri.toString()) {
closeFeature.getProvider(document)?.send(document).catch((error) => client.error(`Sending close notification failed`, error));
diagnosticsFeature?.getProvider(document)?.forget(document);
}
}
});
Expand Down Expand Up @@ -416,7 +419,6 @@ export namespace ESLintClient {
function createClientOptions(): LanguageClientOptions {
const clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: 'file' }, { scheme: 'untitled' }],
diagnosticCollectionName: 'eslint',
revealOutputChannelOn: RevealOutputChannelOn.Never,
initializationOptions: {
},
Expand Down Expand Up @@ -445,6 +447,22 @@ export namespace ESLintClient {
return defaultErrorHandler.closed();
}
},
diagnosticPullOptions: {
onChange: true,
onSave: true,
onFocus: true,
filter: (document, mode) => {
const config = Workspace.getConfiguration('eslint', document);
const run = config.get<RunValues>('run', 'onType');
if (mode === DiagnosticPullMode.onType && run !== 'onType') {
return true;
} else if (mode === DiagnosticPullMode.onSave && run !== 'onSave') {
return true;
}
return validator.check(document) === Validate.off;
},
onTabs: false
},
middleware: {
didOpen: async (document, next) => {
if (Languages.match(packageJsonFilter, document) || Languages.match(configFileFilter, document) || validator.check(document) !== Validate.off) {
Expand Down Expand Up @@ -584,12 +602,12 @@ export namespace ESLintClient {

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

if (userProvidedPackageManager === detectedPackageMananger) {
return detectedPackageMananger;
if (userProvidedPackageManager === detectedPackageManager) {
return detectedPackageManager;
}
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);
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);
return userProvidedPackageManager;
}

Expand Down Expand Up @@ -656,12 +674,14 @@ export namespace ESLintClient {
}
}
});
const useFlatConfig = config.get<boolean | null>('useFlatConfig', null);
const settings: ConfigurationSettings = {
validate: Validate.off,
packageManager: config.get<PackageManagers>('packageManager', 'npm'),
useESLintClass: config.get<boolean>('useESLintClass', false),
useFlatConfig: useFlatConfig === null ? undefined : useFlatConfig,
experimental: {
useFlatConfig: config.get<boolean>('experimental.useFlatConfig', false)
useFlatConfig: config.get<boolean>('experimental.useFlatConfig', false),
},
codeActionOnSave: {
mode: CodeActionsOnSaveMode.all
Expand Down
Loading