diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b88f67..6a98bc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/src/server.ts b/src/server.ts index d346994..be6e3f4 100644 --- a/src/server.ts +++ b/src/server.ts @@ -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'; @@ -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 @@ -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 { diff --git a/test/server.test.ts b/test/server.test.ts index 8a12c35..e61d2ef 100644 --- a/test/server.test.ts +++ b/test/server.test.ts @@ -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'; @@ -43,6 +43,9 @@ function initialize(): number { completionItem: { snippetSupport: true } + }, + hover: { + contentFormat: [ MarkupKind.PlainText ] } }, workspace: { @@ -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(); + } + }); + }); });