mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 23:13:02 +01:00
add selection range provider
This commit is contained in:
parent
b445fa011e
commit
16f88ea8e7
5 changed files with 110 additions and 83 deletions
|
|
@ -8,7 +8,6 @@ import Thenable = monaco.Thenable;
|
|||
import IWorkerContext = monaco.worker.IWorkerContext;
|
||||
|
||||
import * as cssService from 'vscode-css-languageservice';
|
||||
import * as ls from 'vscode-languageserver-types';
|
||||
|
||||
export class CSSWorker {
|
||||
|
||||
|
|
@ -41,7 +40,7 @@ export class CSSWorker {
|
|||
|
||||
// --- language service host ---------------
|
||||
|
||||
doValidation(uri: string): Thenable<ls.Diagnostic[]> {
|
||||
doValidation(uri: string): Thenable<cssService.Diagnostic[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
if (document) {
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
|
|
@ -50,76 +49,82 @@ export class CSSWorker {
|
|||
}
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
doComplete(uri: string, position: ls.Position): Thenable<ls.CompletionList> {
|
||||
doComplete(uri: string, position: cssService.Position): Thenable<cssService.CompletionList> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let completions = this._languageService.doComplete(document, position, stylesheet);
|
||||
return Promise.resolve(completions);
|
||||
}
|
||||
doHover(uri: string, position: ls.Position): Thenable<ls.Hover> {
|
||||
doHover(uri: string, position: cssService.Position): Thenable<cssService.Hover> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let hover = this._languageService.doHover(document, position, stylesheet);
|
||||
return Promise.resolve(hover);
|
||||
}
|
||||
findDefinition(uri: string, position: ls.Position): Thenable<ls.Location> {
|
||||
findDefinition(uri: string, position: cssService.Position): Thenable<cssService.Location> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let definition = this._languageService.findDefinition(document, position, stylesheet);
|
||||
return Promise.resolve(definition);
|
||||
}
|
||||
findReferences(uri: string, position: ls.Position): Thenable<ls.Location[]> {
|
||||
findReferences(uri: string, position: cssService.Position): Thenable<cssService.Location[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let references = this._languageService.findReferences(document, position, stylesheet);
|
||||
return Promise.resolve(references);
|
||||
}
|
||||
findDocumentHighlights(uri: string, position: ls.Position): Thenable<ls.DocumentHighlight[]> {
|
||||
findDocumentHighlights(uri: string, position: cssService.Position): Thenable<cssService.DocumentHighlight[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let highlights = this._languageService.findDocumentHighlights(document, position, stylesheet);
|
||||
return Promise.resolve(highlights);
|
||||
}
|
||||
findDocumentSymbols(uri: string): Thenable<ls.SymbolInformation[]> {
|
||||
findDocumentSymbols(uri: string): Thenable<cssService.SymbolInformation[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let symbols = this._languageService.findDocumentSymbols(document, stylesheet);
|
||||
return Promise.resolve(symbols);
|
||||
}
|
||||
doCodeActions(uri: string, range: ls.Range, context: ls.CodeActionContext): Thenable<ls.Command[]> {
|
||||
doCodeActions(uri: string, range: cssService.Range, context: cssService.CodeActionContext): Thenable<cssService.Command[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let actions = this._languageService.doCodeActions(document, range, context, stylesheet);
|
||||
return Promise.resolve(actions);
|
||||
}
|
||||
findDocumentColors(uri: string): Thenable<ls.ColorInformation[]> {
|
||||
findDocumentColors(uri: string): Thenable<cssService.ColorInformation[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let colorSymbols = this._languageService.findDocumentColors(document, stylesheet);
|
||||
return Promise.resolve(colorSymbols);
|
||||
}
|
||||
getColorPresentations(uri: string, color: ls.Color, range: ls.Range): Thenable<ls.ColorPresentation[]> {
|
||||
getColorPresentations(uri: string, color: cssService.Color, range: cssService.Range): Thenable<cssService.ColorPresentation[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let colorPresentations = this._languageService.getColorPresentations(document, stylesheet, color, range);
|
||||
return Promise.resolve(colorPresentations);
|
||||
}
|
||||
provideFoldingRanges(uri: string, context?: { rangeLimit?: number; }): Thenable<ls.FoldingRange[]> {
|
||||
getFoldingRanges(uri: string, context?: { rangeLimit?: number; }): Thenable<cssService.FoldingRange[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let ranges = this._languageService.getFoldingRanges(document, context);
|
||||
return Promise.resolve(ranges);
|
||||
}
|
||||
doRename(uri: string, position: ls.Position, newName: string): Thenable<ls.WorkspaceEdit> {
|
||||
getSelectionRanges(uri: string, positions: cssService.Position[]): Thenable<cssService.SelectionRange[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let ranges = this._languageService.getSelectionRanges(document, positions, stylesheet);
|
||||
return Promise.resolve(ranges);
|
||||
}
|
||||
doRename(uri: string, position: cssService.Position, newName: string): Thenable<cssService.WorkspaceEdit> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let renames = this._languageService.doRename(document, position, newName, stylesheet);
|
||||
return Promise.resolve(renames);
|
||||
}
|
||||
private _getTextDocument(uri: string): ls.TextDocument {
|
||||
private _getTextDocument(uri: string): cssService.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 cssService.TextDocument.create(uri, this._languageId, model.version, model.getValue());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue