mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
[html] add hover for tags and embedded css
This commit is contained in:
parent
893ced4314
commit
1b2478dd2b
|
@ -6,9 +6,9 @@
|
|||
|
||||
import * as path from 'path';
|
||||
|
||||
import { languages, workspace, ExtensionContext, IndentAction, commands, CompletionList } from 'vscode';
|
||||
import { languages, workspace, ExtensionContext, IndentAction, commands, CompletionList, Hover } from 'vscode';
|
||||
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, Position, RequestType, Protocol2Code, Code2Protocol } from 'vscode-languageclient';
|
||||
import { CompletionList as LSCompletionList } from 'vscode-languageserver-types';
|
||||
import { CompletionList as LSCompletionList, Hover as LSHover } from 'vscode-languageserver-types';
|
||||
import { EMPTY_ELEMENTS } from './htmlEmptyTagsShared';
|
||||
import { initializeEmbeddedContentDocuments } from './embeddedContentDocuments';
|
||||
|
||||
|
@ -26,6 +26,17 @@ namespace EmbeddedCompletionRequest {
|
|||
export const type: RequestType<EmbeddedCompletionParams, LSCompletionList, any> = { get method() { return 'embedded/completion'; } };
|
||||
}
|
||||
|
||||
interface EmbeddedHoverParams {
|
||||
uri: string;
|
||||
version: number;
|
||||
embeddedLanguageId: string;
|
||||
position: Position;
|
||||
}
|
||||
|
||||
namespace EmbeddedHoverRequest {
|
||||
export const type: RequestType<EmbeddedHoverParams, LSHover, any> = { get method() { return 'embedded/hover'; } };
|
||||
}
|
||||
|
||||
export function activate(context: ExtensionContext) {
|
||||
|
||||
// The server is implemented in node
|
||||
|
@ -79,6 +90,24 @@ export function activate(context: ExtensionContext) {
|
|||
});
|
||||
});
|
||||
|
||||
client.onRequest(EmbeddedHoverRequest.type, params => {
|
||||
let position = Protocol2Code.asPosition(params.position);
|
||||
let virtualDocumentURI = embeddedDocuments.getVirtualDocumentUri(params.uri, params.embeddedLanguageId);
|
||||
return embeddedDocuments.openVirtualDocument(virtualDocumentURI, params.version).then(document => {
|
||||
if (document) {
|
||||
return commands.executeCommand<Hover[]>('vscode.executeHoverProvider', virtualDocumentURI, position).then(hover => {
|
||||
if (hover && hover.length > 0) {
|
||||
return <LSHover>{
|
||||
contents: hover[0].contents,
|
||||
range: Code2Protocol.asRange(hover[0].range)
|
||||
};
|
||||
}
|
||||
return void 0;
|
||||
});
|
||||
}
|
||||
return void 0;
|
||||
});
|
||||
});
|
||||
|
||||
let disposable = client.start();
|
||||
|
||||
|
|
|
@ -137,6 +137,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"vscode-languageclient": "^2.6.0-next.1",
|
||||
"vscode-languageserver-types": "^1.0.4",
|
||||
"vscode-nls": "^1.0.7"
|
||||
}
|
||||
}
|
4
extensions/html/server/npm-shrinkwrap.json
generated
4
extensions/html/server/npm-shrinkwrap.json
generated
|
@ -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",
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -599,7 +599,7 @@ export class Hover {
|
|||
|
||||
constructor(contents: vscode.MarkedString | vscode.MarkedString[], range?: Range) {
|
||||
if (!contents) {
|
||||
throw new Error('Illegal argument');
|
||||
throw new Error('Illegal argument, contents must be defined');
|
||||
}
|
||||
|
||||
if (Array.isArray(contents)) {
|
||||
|
|
Loading…
Reference in a new issue