JSON completion contributors

This commit is contained in:
Martin Aeschlimann
2016-01-25 14:46:25 +01:00
parent 1a7316771f
commit 0587f20cd7
9 changed files with 712 additions and 50 deletions

View File

@@ -7,15 +7,18 @@
import Parser = require('./jsonParser');
import SchemaService = require('./jsonSchemaService');
import {IJSONWorkerContribution} from './jsonContributions';
import {Hover, ITextDocument, TextDocumentPosition, Range, MarkedString, RemoteConsole} from 'vscode-languageserver';
export class JSONHover {
private schemaService: SchemaService.IJSONSchemaService;
private contributions: IJSONWorkerContribution[];
constructor(schemaService: SchemaService.IJSONSchemaService) {
constructor(schemaService: SchemaService.IJSONSchemaService, contributions: IJSONWorkerContribution[] = []) {
this.schemaService = schemaService;
this.contributions = contributions;
}
public doHover(document: ITextDocument, textDocumentPosition: TextDocumentPosition, doc: Parser.JSONDocument): Thenable<Hover> {
@@ -52,15 +55,28 @@ export class JSONHover {
}
return true;
});
if (description) {
function createHover(contents: MarkedString[]) {
let range = Range.create(document.positionAt(node.start), document.positionAt(node.end));
let result: Hover = {
contents: [description],
contents: contents,
range: range
};
return result;
}
let location = node.getNodeLocation();
for (let i = this.contributions.length - 1; i >= 0; i--) {
let contribution = this.contributions[i];
let promise = contribution.getInfoContribution(textDocumentPosition.uri, location);
if (promise) {
return promise.then(htmlContent => createHover(htmlContent));
}
}
if (description) {
return createHover([description]);
}
}
return void 0;
});