Skip to content

Commit fdfba85

Browse files
committed
Convert to new pull model
1 parent ea10aeb commit fdfba85

File tree

9 files changed

+169
-29321
lines changed

9 files changed

+169
-29321
lines changed

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
"eslintignore",
3737
"eslintr",
3838
"mydirectory",
39+
"onsave",
40+
"ontype",
3941
"pnpm"
4042
]
4143
}

client/package-lock.json

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

client/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
"url": "https://github.com/Microsoft/vscode-eslint/issues"
1515
},
1616
"engines": {
17-
"vscode": "^1.52.0"
17+
"vscode": "^1.53.0"
1818
},
1919
"devDependencies": {
20-
"@types/vscode": "1.52.0"
20+
"@types/vscode": "1.53.0"
2121
},
2222
"dependencies": {
23-
"vscode-languageclient": "7.0.0"
23+
"vscode-languageclient": "7.1.0-next.3"
2424
},
2525
"scripts": {
2626
"test": "node ../node_modules/mocha/bin/_mocha"

client/src/extension.ts

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ import {
1616
LanguageClient, LanguageClientOptions, RequestType, TransportKind, TextDocumentIdentifier, NotificationType, ErrorHandler,
1717
ErrorAction, CloseAction, State as ClientState, RevealOutputChannelOn, VersionedTextDocumentIdentifier, ExecuteCommandRequest,
1818
ExecuteCommandParams, ServerOptions, DocumentFilter, DidCloseTextDocumentNotification, DidOpenTextDocumentNotification,
19-
WorkspaceFolder, DidChangeConfigurationNotification, NotificationType0
19+
WorkspaceFolder, DidChangeConfigurationNotification, NotificationType0, Middleware, Proposed
2020
} from 'vscode-languageclient/node';
2121

22+
import { DiagnosticProviderMiddleware, VDiagnosticResult } from 'vscode-languageclient/lib/common/proposed.diagnostic';
23+
2224
import { findEslint, convert2RegExp, toOSPath, toPosixPath, Semaphore } from './utils';
2325
import { TaskProvider } from './tasks';
2426

@@ -109,6 +111,40 @@ namespace PatternItem {
109111
}
110112

111113
type RunValues = 'onType' | 'onSave';
114+
namespace RunValues {
115+
export function from(value: unknown): RunValues {
116+
if (!Is.string(value)) {
117+
return 'onType';
118+
}
119+
switch (value.toLowerCase()) {
120+
case 'ontype':
121+
return 'onType';
122+
case 'onsave':
123+
return 'onSave';
124+
default:
125+
return 'onType';
126+
}
127+
}
128+
}
129+
130+
type DiagnosticMode = 'push' | 'pull';
131+
namespace DiagnosticMode {
132+
export const push = 'push';
133+
export const pull = 'pull';
134+
export function from(value: unknown): DiagnosticMode {
135+
if (!Is.string(value)) {
136+
return 'push';
137+
}
138+
switch(value.toLowerCase()) {
139+
case 'push':
140+
return push;
141+
case 'pull':
142+
return pull;
143+
default:
144+
return push;
145+
}
146+
}
147+
}
112148

113149
interface CodeActionSettings {
114150
disableRuleComment: {
@@ -193,6 +229,7 @@ interface ConfigurationSettings {
193229
run: RunValues;
194230
nodePath: string | null;
195231
workspaceFolder: WorkspaceFolder | undefined;
232+
diagnosticMode: DiagnosticMode;
196233
workingDirectory: ModeItem | DirectoryItem | undefined;
197234
}
198235

@@ -1355,6 +1392,21 @@ function realActivate(context: ExtensionContext): void {
13551392
const newContext: CodeActionContext = Object.assign({}, context, { diagnostics: eslintDiagnostics } as CodeActionContext);
13561393
return next(document, range, newContext, token);
13571394
},
1395+
provideDiagnostics: (document, context, token, next): ProviderResult<VDiagnosticResult> => {
1396+
// If the document is not sync return early
1397+
if (!syncedDocuments.has(document.uri.toString())) {
1398+
return { unmodified: true };
1399+
}
1400+
if (context.triggerKind === Proposed.DiagnosticTriggerKind.Opened || context.triggerKind === Proposed.DiagnosticTriggerKind.Invoked) {
1401+
return next(document, context, token);
1402+
}
1403+
const config = Workspace.getConfiguration('eslint', document.uri);
1404+
const runMode = RunValues.from(config.get<RunValues>('run', 'onType'));
1405+
if (runMode === 'onType' && context.triggerKind === Proposed.DiagnosticTriggerKind.Saved || runMode === 'onSave' && context.triggerKind === Proposed.DiagnosticTriggerKind.Typed) {
1406+
return { unmodified: true };
1407+
}
1408+
return next(document, context, token);
1409+
},
13581410
workspace: {
13591411
didChangeWatchedFile: (event, next) => {
13601412
probeFailed.clear();
@@ -1441,10 +1493,11 @@ function realActivate(context: ExtensionContext): void {
14411493
quiet: config.get('quiet', false),
14421494
onIgnoredFiles: ESLintSeverity.from(config.get<string>('onIgnoredFiles', ESLintSeverity.off)),
14431495
options: config.get('options', {}),
1444-
run: config.get('run', 'onType'),
1496+
run: RunValues.from(config.get('run', 'onType')),
14451497
nodePath: config.get('nodePath', null),
14461498
workingDirectory: undefined,
14471499
workspaceFolder: undefined,
1500+
diagnosticMode: DiagnosticMode.from(config.get<DiagnosticMode>('experimental.diagnosticMode', 'push')),
14481501
codeAction: {
14491502
disableRuleComment: config.get('codeAction.disableRuleComment', { enable: true, location: 'separateLine' as 'separateLine' }),
14501503
showDocumentation: config.get('codeAction.showDocumentation', { enable: true })
@@ -1547,7 +1600,7 @@ function realActivate(context: ExtensionContext): void {
15471600
return result;
15481601
}
15491602
}
1550-
}
1603+
} as Middleware & DiagnosticProviderMiddleware
15511604
};
15521605

15531606
let client: LanguageClient;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"extensionKind": [
3131
"workspace"
3232
],
33+
"enableProposedApi": true,
3334
"main": "./client/out/extension",
3435
"contributes": {
3536
"configuration": {

server/package-lock.json

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

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"dependencies": {
1818
"vscode-uri": "^2.1.2",
19-
"vscode-languageserver": "7.0.0",
19+
"vscode-languageserver": "7.1.0-next.3",
2020
"vscode-languageserver-textdocument": "1.0.1"
2121
},
2222
"scripts": {}

server/server.lsif

Lines changed: 0 additions & 29237 deletions
This file was deleted.

0 commit comments

Comments
 (0)