Skip to content

Commit

Permalink
Upgrade to latest LSP version. Make use of new CodeAction. Fixes #437
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaeumer committed Jun 4, 2018
1 parent 978c056 commit 572da96
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 66 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### 1.4.12

- Upgrade to latest version of the LSP libraries
- Fixes [eslint server crashed 5 times in the last 3 minutes. the server will not be restarted.](https://github.com/Microsoft/vscode-eslint/issues/437)

### 1.4.11

Internal version to track down [eslint server crashed 5 times in the last 3 minutes. the server will not be restarted.](https://github.com/Microsoft/vscode-eslint/issues/437)

### 1.4.10

- [Add Command to create a YAML configuration](https://github.com/Microsoft/vscode-eslint/issues/409)
Expand Down
32 changes: 16 additions & 16 deletions client/package-lock.json

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

2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"vscode": "^1.1.17"
},
"dependencies": {
"vscode-languageclient": "^4.1.4"
"vscode-languageclient": "^4.2.1"
}
}
14 changes: 2 additions & 12 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as path from 'path';
import * as fs from 'fs';
import {
workspace as Workspace, window as Window, commands as Commands, languages as Languages, Disposable, ExtensionContext, Uri, StatusBarAlignment, TextDocument,
CodeActionContext, Diagnostic, ProviderResult, Command, QuickPickItem, WorkspaceFolder as VWorkspaceFolder
CodeActionContext, Diagnostic, ProviderResult, Command, QuickPickItem, WorkspaceFolder as VWorkspaceFolder, CodeAction
} from 'vscode';
import {
LanguageClient, LanguageClientOptions, RequestType, TransportKind,
Expand Down Expand Up @@ -373,16 +373,6 @@ export function realActivate(context: ExtensionContext) {
Workspace.createFileSystemWatcher('**/package.json')
]
},
initializationOptions: () => {
let configuration = Workspace.getConfiguration('eslint');
let folders = Workspace.workspaceFolders;
return {
legacyModuleResolve: configuration ? configuration.get('_legacyModuleResolve', false) : false,
nodePath: configuration ? configuration.get('nodePath', undefined) : undefined,
languageIds: configuration ? configuration.get('valiadate', defaultLanguages) : defaultLanguages,
workspaceFolders: folders ? folders.map(folder => folder.toString()) : []
};
},
initializationFailedHandler: (error) => {
client.error('Server initialization failed.', error);
client.outputChannel.show(true);
Expand Down Expand Up @@ -436,7 +426,7 @@ export function realActivate(context: ExtensionContext) {
next(document);
}
},
provideCodeActions: (document, range, context, token, next): ProviderResult<Command[]> => {
provideCodeActions: (document, range, context, token, next): ProviderResult<(Command | CodeAction)[]> => {
if (!syncedDocuments.has(document.uri.toString()) || !context.diagnostics || context.diagnostics.length === 0) {
return [];
}
Expand Down
14 changes: 7 additions & 7 deletions 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-eslint",
"displayName": "ESLint",
"description": "Integrates ESLint JavaScript into VS Code.",
"version": "1.4.10",
"version": "1.4.12",
"author": "Microsoft Corporation",
"license": "MIT",
"repository": {
Expand All @@ -22,7 +22,7 @@
"multi-root ready"
],
"engines": {
"vscode": "^1.16.0"
"vscode": "^1.23.0"
},
"activationEvents": [
"*"
Expand Down Expand Up @@ -212,7 +212,7 @@
"postinstall": "cd client && npm install && cd ../server && npm install && cd .."
},
"devDependencies": {
"typescript": "^2.8.3",
"@types/node": "^6.0.90"
"typescript": "^2.9.1",
"@types/node": "^8.0.0"
}
}
39 changes: 22 additions & 17 deletions server/package-lock.json

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

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"vscode-uri": "^1.0.1",
"vscode-languageserver": "^4.1.3"
"vscode-languageserver": "^4.2.1"
},
"scripts": {}
}
29 changes: 21 additions & 8 deletions server/src/eslintServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
Command, WorkspaceChange,
CodeActionRequest, VersionedTextDocumentIdentifier,
ExecuteCommandRequest, DidChangeWatchedFilesNotification, DidChangeConfigurationNotification,
WorkspaceFolder, DidChangeWorkspaceFoldersNotification
WorkspaceFolder, DidChangeWorkspaceFoldersNotification, CodeAction, CodeActionKind
} from 'vscode-languageserver';

import URI from 'vscode-uri';
Expand Down Expand Up @@ -293,13 +293,13 @@ function getFilePath(documentOrUri: string | TextDocument): string {
const exitCalled = new NotificationType<[number, string], void>('eslint/exitCalled');

const nodeExit = process.exit;
process.exit = (code?: number) => {
process.exit = ((code?: number): void => {
let stack = new Error('stack');
connection.sendNotification(exitCalled, [code ? code : 0, stack.stack]);
setTimeout(() => {
nodeExit(code);
}, 1000);
}
}) as any;
process.on('uncaughtException', (error: any) => {
let message: string;
if (error) {
Expand Down Expand Up @@ -1014,7 +1014,7 @@ class Fixes {
let commands: Map<string, WorkspaceChange>;
messageQueue.registerRequest(CodeActionRequest.type, (params) => {
commands = new Map<string, WorkspaceChange>();
let result: Command[] = [];
let result: CodeAction[] = [];
let uri = params.textDocument.uri;
let edits = codeActions.get(uri);
if (!edits) {
Expand Down Expand Up @@ -1048,14 +1048,17 @@ messageQueue.registerRequest(CodeActionRequest.type, (params) => {
let workspaceChange = new WorkspaceChange();
workspaceChange.getTextEditChange({uri, version: documentVersion}).add(createTextEdit(editInfo));
commands.set(CommandIds.applySingleFix, workspaceChange);
result.push(Command.create(editInfo.label, CommandIds.applySingleFix));
result.push(CodeAction.create(
editInfo.label,
Command.create(editInfo.label, CommandIds.applySingleFix),
CodeActionKind.QuickFix
));
};

if (result.length > 0) {
let same: AutoFix[] = [];
let all: AutoFix[] = [];


for (let editInfo of fixes.getAllSorted()) {
if (documentVersion === -1) {
documentVersion = editInfo.documentVersion;
Expand All @@ -1072,14 +1075,24 @@ messageQueue.registerRequest(CodeActionRequest.type, (params) => {
let sameTextChange = sameFixes.getTextEditChange({uri, version: documentVersion});
same.map(createTextEdit).forEach(edit => sameTextChange.add(edit));
commands.set(CommandIds.applySameFixes, sameFixes);
result.push(Command.create(`Fix all ${ruleId} problems`, CommandIds.applySameFixes));
let title = `Fix all ${ruleId} problems`;
result.push(CodeAction.create(
title,
Command.create(title, CommandIds.applySameFixes),
CodeActionKind.QuickFix
));
}
if (all.length > 1) {
let allFixes: WorkspaceChange = new WorkspaceChange();
let allTextChange = allFixes.getTextEditChange({uri, version: documentVersion});
all.map(createTextEdit).forEach(edit => allTextChange.add(edit));
commands.set(CommandIds.applyAllFixes, allFixes);
result.push(Command.create(`Fix all auto-fixable problems`, CommandIds.applyAllFixes));
let title = `Fix all auto-fixable problems`;
result.push(CodeAction.create(
title,
Command.create(title, CommandIds.applyAllFixes),
CodeActionKind.QuickFix
));
}
}
return result;
Expand Down

0 comments on commit 572da96

Please sign in to comment.