Skip to content

Commit

Permalink
Fix #209 Use client's supported formats for hovers
Browse files Browse the repository at this point in the history
textDocument/hover results may be returned in plain text or in
Markdown depending on what the client has defined in its
capabilities. We now inspect the capabilities and return hover
results in plain text or Markdown depending on what has been set in
the client's capabilities.

Signed-off-by: Remy Suen <[email protected]>
  • Loading branch information
rcjsuen committed Mar 8, 2018
1 parent 88e5118 commit 9144d34
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ All notable changes to this project will be documented in this file.
- create docker.command.removeEmptyContinuationLine to remove empty continuation lines in instructions that span multiple lines ([#203](https://github.com/rcjsuen/dockerfile-language-server-nodejs/issues/203))
- textDocument/documentLink
- create links to hub.docker.com for base image names in FROM ([#204](https://github.com/rcjsuen/dockerfile-language-server-nodejs/issues/204))
- textDocument/hover
- inspect client's capabilities to decide what content format to use for hovers ([#209](https://github.com/rcjsuen/dockerfile-language-server-nodejs/issues/209))
- textDocument/publishDiagnostics
- flag HEALTHCHECK durations that include a hyphen as an error ([rcjsuen/dockerfile-utils#18](https://github.com/rcjsuen/dockerfile-utils/issues/18))
- warn if ADD has more than two arguments and its last argument is not a directory ([rcjsuen/dockerfile-utils#17](https://github.com/rcjsuen/dockerfile-utils/issues/17))
Expand Down
23 changes: 21 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
DocumentFormattingParams, DocumentRangeFormattingParams, DocumentOnTypeFormattingParams, DocumentHighlight,
RenameParams, WorkspaceEdit, Location,
DidChangeTextDocumentParams, DidOpenTextDocumentParams, DidCloseTextDocumentParams, TextDocumentContentChangeEvent,
DidChangeConfigurationNotification, ConfigurationItem, DocumentLinkParams, DocumentLink
DidChangeConfigurationNotification, ConfigurationItem, DocumentLinkParams, DocumentLink, MarkupKind
} from 'vscode-languageserver';
import { ValidatorSettings, ValidationSeverity } from 'dockerfile-utils';
import { CommandIds, DockerfileLanguageServiceFactory } from 'dockerfile-language-service';
Expand Down Expand Up @@ -56,6 +56,25 @@ function supportsSnippets(capabilities: ClientCapabilities): boolean {
&& capabilities.textDocument.completion.completionItem.snippetSupport;
}

function getHoverContentFormat(capabilities: ClientCapabilities): MarkupKind[] {
return capabilities.textDocument
&& capabilities.textDocument.hover
&& capabilities.textDocument.hover.contentFormat;
}

function setServiceCapabilities(capabilities: ClientCapabilities): void {
service.setCapabilities({
completion: {
completionItem: {
snippetSupport: supportsSnippets(capabilities)
}
},
hover: {
contentFormat: getHoverContentFormat(capabilities)
}
});
}

connection.onInitialized(() => {
if (configurationSupport) {
// listen for notification changes if the client supports workspace/configuration
Expand All @@ -64,7 +83,7 @@ connection.onInitialized(() => {
});

connection.onInitialize((params: InitializeParams): InitializeResult => {
service.setCapabilities({ completion: { completionItem: { snippetSupport: supportsSnippets(params.capabilities) }}});
setServiceCapabilities(params.capabilities);
applyEditSupport = params.capabilities.workspace && params.capabilities.workspace.applyEdit === true;
configurationSupport = params.capabilities.workspace && params.capabilities.workspace.configuration === true;
return {
Expand Down
24 changes: 23 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 } from 'vscode-languageserver';
import { TextDocumentSyncKind, MarkupKind } from 'vscode-languageserver';
import { CommandIds } from 'dockerfile-language-service';
import { ValidationCode } from 'dockerfile-utils';

Expand Down Expand Up @@ -43,6 +43,9 @@ function initialize(): number {
completionItem: {
snippetSupport: true
}
},
hover: {
contentFormat: [ MarkupKind.PlainText ]
}
},
workspace: {
Expand Down Expand Up @@ -129,4 +132,23 @@ describe("Dockerfile LSP Tests", function() {
};
lspProcess.on("message", executeCommandListener);
});

it("issue #209", function(finished) {
this.timeout(5000);
let id = sendRequest("textDocument/hover", {
textDocument: {
uri: "uri://dockerfile/x.txt"
},
position: {
line: 0,
character: 1
}
});
lspProcess.on("message", (json) => {
if (json.id === id) {
assert.equal(json.result.contents.kind, MarkupKind.PlainText);
finished();
}
});
});
});

0 comments on commit 9144d34

Please sign in to comment.