[html] add hover for tags and embedded css

This commit is contained in:
Martin Aeschlimann
2016-10-21 22:02:27 +02:00
parent 893ced4314
commit 1b2478dd2b
6 changed files with 62 additions and 7 deletions

View File

@@ -3,9 +3,9 @@
"version": "1.0.0",
"dependencies": {
"vscode-html-languageservice": {
"version": "1.0.0-next.8",
"version": "1.0.0-next.9",
"from": "vscode-html-languageservice@next",
"resolved": "https://registry.npmjs.org/vscode-html-languageservice/-/vscode-html-languageservice-1.0.0-next.8.tgz"
"resolved": "https://registry.npmjs.org/vscode-html-languageservice/-/vscode-html-languageservice-1.0.0-next.9.tgz"
},
"vscode-jsonrpc": {
"version": "2.4.0",

View File

@@ -8,7 +8,7 @@
"node": "*"
},
"dependencies": {
"vscode-html-languageservice": "^1.0.0-next.8",
"vscode-html-languageservice": "^1.0.0-next.9",
"vscode-languageserver": "^2.6.0-next.3",
"vscode-nls": "^1.0.4",
"vscode-uri": "^1.0.0"

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { createConnection, IConnection, TextDocuments, InitializeParams, InitializeResult, FormattingOptions, RequestType, CompletionList, Position } from 'vscode-languageserver';
import { createConnection, IConnection, TextDocuments, InitializeParams, InitializeResult, FormattingOptions, RequestType, CompletionList, Position, Hover } from 'vscode-languageserver';
import { HTMLDocument, getLanguageService, CompletionConfiguration, HTMLFormatConfiguration, DocumentContext } from 'vscode-html-languageservice';
import { getLanguageModelCache } from './languageModelCache';
@@ -27,6 +27,17 @@ namespace EmbeddedCompletionRequest {
export const type: RequestType<EmbeddedCompletionParams, CompletionList, any> = { get method() { return 'embedded/completion'; } };
}
interface EmbeddedHoverParams {
uri: string;
version: number;
embeddedLanguageId: string;
position: Position;
}
namespace EmbeddedHoverRequest {
export const type: RequestType<EmbeddedCompletionParams, Hover, any> = { get method() { return 'embedded/hover'; } };
}
interface EmbeddedContentParams {
uri: string;
embeddedLanguageId: string;
@@ -73,6 +84,7 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
// Tell the client that the server works in FULL text document sync mode
textDocumentSync: documents.syncKind,
completionProvider: { resolveProvider: false, triggerCharacters: ['.', ':', '<', '"', '=', '/'] },
hoverProvider: true,
documentHighlightProvider: true,
documentRangeFormattingProvider: params.initializationOptions['format.enable'],
documentLinkProvider: true
@@ -115,6 +127,19 @@ connection.onCompletion(textDocumentPosition => {
return list;
});
connection.onHover(textDocumentPosition => {
let document = documents.get(textDocumentPosition.textDocument.uri);
let htmlDocument = htmlDocuments.get(document);
let hover = languageService.doHover(document, textDocumentPosition.position, htmlDocument);
if (!hover) {
let embeddedLanguageId = getEmbeddedLanguageAtPosition(languageService, document, htmlDocument, textDocumentPosition.position);
if (embeddedLanguageId) {
return connection.sendRequest(EmbeddedHoverRequest.type, { uri: document.uri, version: document.version, embeddedLanguageId, position: textDocumentPosition.position });
}
}
return hover;
});
connection.onRequest(EmbeddedContentRequest.type, parms => {
let document = documents.get(parms.uri);
if (document) {