mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 17:25:39 +01:00
Initial release
This commit is contained in:
parent
08e7666e5c
commit
f26f3636d9
17 changed files with 1417 additions and 2 deletions
73
src/htmlWorker.ts
Normal file
73
src/htmlWorker.ts
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import IWorkerContext = monaco.worker.IWorkerContext;
|
||||
|
||||
import Thenable = monaco.Thenable;
|
||||
import Promise = monaco.Promise;
|
||||
|
||||
import * as htmlService from 'vscode-html-languageservice';
|
||||
import * as ls from 'vscode-languageserver-types';
|
||||
|
||||
|
||||
export class HTMLWorker {
|
||||
|
||||
private _ctx:IWorkerContext;
|
||||
private _languageService: htmlService.LanguageService;
|
||||
private _languageSettings: monaco.languages.html.Options;
|
||||
private _languageId: string;
|
||||
|
||||
constructor(ctx:IWorkerContext, createData: ICreateData) {
|
||||
this._ctx = ctx;
|
||||
this._languageSettings = createData.languageSettings;
|
||||
this._languageId = createData.languageId;
|
||||
this._languageService = htmlService.getLanguageService();
|
||||
}
|
||||
|
||||
doValidation(uri: string): Thenable<ls.Diagnostic[]> {
|
||||
// not yet suported
|
||||
return Promise.as([]);
|
||||
}
|
||||
doComplete(uri: string, position: ls.Position): Thenable<ls.CompletionList> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let htmlDocument = this._languageService.parseHTMLDocument(document);
|
||||
return Promise.as(this._languageService.doComplete(document, position, htmlDocument));
|
||||
}
|
||||
format(uri: string, range: ls.Range, options: ls.FormattingOptions): Thenable<ls.TextEdit[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let textEdits = this._languageService.format(document, range, this._languageSettings && this._languageSettings.format);
|
||||
return Promise.as(textEdits);
|
||||
}
|
||||
findDocumentHighlights(uri: string, position: ls.Position): Promise<ls.DocumentHighlight[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let htmlDocument = this._languageService.parseHTMLDocument(document);
|
||||
let highlights = this._languageService.findDocumentHighlights(document, position, htmlDocument);
|
||||
return Promise.as(highlights);
|
||||
}
|
||||
findDocumentLinks(uri: string, workspacePath: string): Promise<ls.DocumentLink[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let links = this._languageService.findDocumentLinks(document, workspacePath);
|
||||
return Promise.as(links);
|
||||
}
|
||||
private _getTextDocument(uri: string): ls.TextDocument {
|
||||
let models = this._ctx.getMirrorModels();
|
||||
for (let model of models) {
|
||||
if (model.uri.toString() === uri) {
|
||||
return ls.TextDocument.create(uri, this._languageId, model.version, model.getValue());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ICreateData {
|
||||
languageId: string;
|
||||
languageSettings: monaco.languages.html.Options;
|
||||
}
|
||||
|
||||
export function create(ctx:IWorkerContext, createData: ICreateData): HTMLWorker {
|
||||
return new HTMLWorker(ctx, createData);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue