Skip to content

Commit

Permalink
Fix #224 Send back deprecated items if supported
Browse files Browse the repository at this point in the history
Items in responses to textDocument/completion will now indicate that
they are deprecated if the client states their support for it.

Signed-off-by: Remy Suen <[email protected]>
  • Loading branch information
rcjsuen committed Jul 8, 2018
1 parent 03187d3 commit 6f2cd01
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ All notable changes to this project will be documented in this file.
- versions prior to 4.x of Mocha dependended on Growl 1.9.2 which contained a [security vulnerability](https://github.com/tj/node-growl/issues/60)
- as Mocha is a `devDependencies` module, there is no reason to believe that consumers of the `dockerfile-language-server-nodejs` module itself was affected by this vulnerability

### Fixed
- textDocument/completion
- send back deprecated items for MAINTAINER if the client supports it ([#224](https://github.com/rcjsuen/dockerfile-language-server-nodejs/issues/224))

## [0.0.18] - 2018-06-30
### Added
- documentLink/resolve
Expand Down
60 changes: 31 additions & 29 deletions 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"dockerfile-language-service": "0.0.5",
"dockerfile-utils": "0.0.8",
"vscode-languageserver": "^4.0.0"
"vscode-languageserver": "^4.1.3"
},
"devDependencies": {
"@types/mocha": "^2.2.33",
Expand Down
8 changes: 8 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ function getDocument(uri: string): PromiseLike<TextDocument> {
});
}

function supportsDeprecatedItems(capabilities: ClientCapabilities): boolean {
return capabilities.textDocument
&& capabilities.textDocument.completion
&& capabilities.textDocument.completion.completionItem
&& capabilities.textDocument.completion.completionItem.deprecatedSupport;
}

function supportsSnippets(capabilities: ClientCapabilities): boolean {
return capabilities.textDocument
&& capabilities.textDocument.completion
Expand Down Expand Up @@ -109,6 +116,7 @@ function setServiceCapabilities(capabilities: ClientCapabilities): void {
service.setCapabilities({
completion: {
completionItem: {
deprecatedSupport: supportsDeprecatedItems(capabilities),
documentationFormat: getCompletionItemDocumentationFormat(capabilities),
snippetSupport: supportsSnippets(capabilities)
}
Expand Down
44 changes: 43 additions & 1 deletion test/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import * as child_process from "child_process";
import * as assert from "assert";

import { TextDocumentSyncKind, MarkupKind, SymbolKind } from 'vscode-languageserver';
import { TextDocumentSyncKind, MarkupKind, SymbolKind, InsertTextFormat, CompletionItemKind } from 'vscode-languageserver';
import { CommandIds } from 'dockerfile-language-service';
import { ValidationCode } from 'dockerfile-utils';

Expand Down Expand Up @@ -41,6 +41,7 @@ function initialize(applyEdit: boolean): number {
textDocument: {
completion: {
completionItem: {
deprecatedSupport: true,
documentationFormat: [ MarkupKind.Markdown ],
snippetSupport: true
}
Expand Down Expand Up @@ -464,6 +465,47 @@ describe("Dockerfile LSP Tests", function() {
lspProcess.on("message", listener221);
});

it("issue #224", function (finished) {
this.timeout(5000);
let document = {
languageId: "dockerfile",
version: 1,
uri: "uri://dockerfile/224.txt",
text: "FROM node\nMAIN"
};
sendNotification("textDocument/didOpen", {
textDocument: document
});

let completion = sendRequest("textDocument/completion", {
textDocument: {
uri: document.uri
},
position: {
line: 1,
character: 4
}
});
const listener224 = (json) => {
if (json.id === completion) {
lspProcess.removeListener("message", listener224);
assert.equal(json.result.length, 1);
assert.equal(json.result[0].data, "MAINTAINER");
assert.equal(json.result[0].deprecated, true);
assert.equal(json.result[0].insertTextFormat, InsertTextFormat.Snippet);
assert.equal(json.result[0].kind, CompletionItemKind.Keyword);
assert.equal(json.result[0].label, "MAINTAINER name");
assert.equal(json.result[0].textEdit.newText, "MAINTAINER ${1:name}");
assert.equal(json.result[0].textEdit.range.start.line, 1);
assert.equal(json.result[0].textEdit.range.start.character, 0);
assert.equal(json.result[0].textEdit.range.end.line, 1);
assert.equal(json.result[0].textEdit.range.end.character, 4);
finished();
}
};
lspProcess.on("message", listener224);
});

after(() => {
// terminate the forked LSP process after all the tests have been run
lspProcess.kill();
Expand Down

0 comments on commit 6f2cd01

Please sign in to comment.