|
|
|
@ -12,7 +12,7 @@ export class CSSWorker {
|
|
|
|
|
|
|
|
|
|
private _ctx: worker.IWorkerContext;
|
|
|
|
|
private _languageService: cssService.LanguageService;
|
|
|
|
|
private _languageSettings: cssService.LanguageSettings;
|
|
|
|
|
private _languageSettings: Options;
|
|
|
|
|
private _languageId: string;
|
|
|
|
|
|
|
|
|
|
constructor(ctx: worker.IWorkerContext, createData: ICreateData) {
|
|
|
|
@ -53,10 +53,10 @@ export class CSSWorker {
|
|
|
|
|
// --- language service host ---------------
|
|
|
|
|
|
|
|
|
|
async doValidation(uri: string): Promise<cssService.Diagnostic[]> {
|
|
|
|
|
let document = this._getTextDocument(uri);
|
|
|
|
|
const document = this._getTextDocument(uri);
|
|
|
|
|
if (document) {
|
|
|
|
|
let stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
let diagnostics = this._languageService.doValidation(document, stylesheet);
|
|
|
|
|
const stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
const diagnostics = this._languageService.doValidation(document, stylesheet);
|
|
|
|
|
return Promise.resolve(diagnostics);
|
|
|
|
|
}
|
|
|
|
|
return Promise.resolve([]);
|
|
|
|
@ -65,63 +65,63 @@ export class CSSWorker {
|
|
|
|
|
uri: string,
|
|
|
|
|
position: cssService.Position
|
|
|
|
|
): Promise<cssService.CompletionList | null> {
|
|
|
|
|
let document = this._getTextDocument(uri);
|
|
|
|
|
const document = this._getTextDocument(uri);
|
|
|
|
|
if (!document) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
let stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
let completions = this._languageService.doComplete(document, position, stylesheet);
|
|
|
|
|
const stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
const completions = this._languageService.doComplete(document, position, stylesheet);
|
|
|
|
|
return Promise.resolve(completions);
|
|
|
|
|
}
|
|
|
|
|
async doHover(uri: string, position: cssService.Position): Promise<cssService.Hover | null> {
|
|
|
|
|
let document = this._getTextDocument(uri);
|
|
|
|
|
const document = this._getTextDocument(uri);
|
|
|
|
|
if (!document) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
let stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
let hover = this._languageService.doHover(document, position, stylesheet);
|
|
|
|
|
const stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
const hover = this._languageService.doHover(document, position, stylesheet);
|
|
|
|
|
return Promise.resolve(hover);
|
|
|
|
|
}
|
|
|
|
|
async findDefinition(
|
|
|
|
|
uri: string,
|
|
|
|
|
position: cssService.Position
|
|
|
|
|
): Promise<cssService.Location | null> {
|
|
|
|
|
let document = this._getTextDocument(uri);
|
|
|
|
|
const document = this._getTextDocument(uri);
|
|
|
|
|
if (!document) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
let stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
let definition = this._languageService.findDefinition(document, position, stylesheet);
|
|
|
|
|
const stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
const definition = this._languageService.findDefinition(document, position, stylesheet);
|
|
|
|
|
return Promise.resolve(definition);
|
|
|
|
|
}
|
|
|
|
|
async findReferences(uri: string, position: cssService.Position): Promise<cssService.Location[]> {
|
|
|
|
|
let document = this._getTextDocument(uri);
|
|
|
|
|
const document = this._getTextDocument(uri);
|
|
|
|
|
if (!document) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
let stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
let references = this._languageService.findReferences(document, position, stylesheet);
|
|
|
|
|
const stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
const references = this._languageService.findReferences(document, position, stylesheet);
|
|
|
|
|
return Promise.resolve(references);
|
|
|
|
|
}
|
|
|
|
|
async findDocumentHighlights(
|
|
|
|
|
uri: string,
|
|
|
|
|
position: cssService.Position
|
|
|
|
|
): Promise<cssService.DocumentHighlight[]> {
|
|
|
|
|
let document = this._getTextDocument(uri);
|
|
|
|
|
const document = this._getTextDocument(uri);
|
|
|
|
|
if (!document) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
let stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
let highlights = this._languageService.findDocumentHighlights(document, position, stylesheet);
|
|
|
|
|
const stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
const highlights = this._languageService.findDocumentHighlights(document, position, stylesheet);
|
|
|
|
|
return Promise.resolve(highlights);
|
|
|
|
|
}
|
|
|
|
|
async findDocumentSymbols(uri: string): Promise<cssService.SymbolInformation[]> {
|
|
|
|
|
let document = this._getTextDocument(uri);
|
|
|
|
|
const document = this._getTextDocument(uri);
|
|
|
|
|
if (!document) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
let stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
let symbols = this._languageService.findDocumentSymbols(document, stylesheet);
|
|
|
|
|
const stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
const symbols = this._languageService.findDocumentSymbols(document, stylesheet);
|
|
|
|
|
return Promise.resolve(symbols);
|
|
|
|
|
}
|
|
|
|
|
async doCodeActions(
|
|
|
|
@ -129,21 +129,21 @@ export class CSSWorker {
|
|
|
|
|
range: cssService.Range,
|
|
|
|
|
context: cssService.CodeActionContext
|
|
|
|
|
): Promise<cssService.Command[]> {
|
|
|
|
|
let document = this._getTextDocument(uri);
|
|
|
|
|
const document = this._getTextDocument(uri);
|
|
|
|
|
if (!document) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
let stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
let actions = this._languageService.doCodeActions(document, range, context, stylesheet);
|
|
|
|
|
const stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
const actions = this._languageService.doCodeActions(document, range, context, stylesheet);
|
|
|
|
|
return Promise.resolve(actions);
|
|
|
|
|
}
|
|
|
|
|
async findDocumentColors(uri: string): Promise<cssService.ColorInformation[]> {
|
|
|
|
|
let document = this._getTextDocument(uri);
|
|
|
|
|
const document = this._getTextDocument(uri);
|
|
|
|
|
if (!document) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
let stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
let colorSymbols = this._languageService.findDocumentColors(document, stylesheet);
|
|
|
|
|
const stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
const colorSymbols = this._languageService.findDocumentColors(document, stylesheet);
|
|
|
|
|
return Promise.resolve(colorSymbols);
|
|
|
|
|
}
|
|
|
|
|
async getColorPresentations(
|
|
|
|
@ -151,12 +151,12 @@ export class CSSWorker {
|
|
|
|
|
color: cssService.Color,
|
|
|
|
|
range: cssService.Range
|
|
|
|
|
): Promise<cssService.ColorPresentation[]> {
|
|
|
|
|
let document = this._getTextDocument(uri);
|
|
|
|
|
const document = this._getTextDocument(uri);
|
|
|
|
|
if (!document) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
let stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
let colorPresentations = this._languageService.getColorPresentations(
|
|
|
|
|
const stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
const colorPresentations = this._languageService.getColorPresentations(
|
|
|
|
|
document,
|
|
|
|
|
stylesheet,
|
|
|
|
|
color,
|
|
|
|
@ -168,23 +168,23 @@ export class CSSWorker {
|
|
|
|
|
uri: string,
|
|
|
|
|
context?: { rangeLimit?: number }
|
|
|
|
|
): Promise<cssService.FoldingRange[]> {
|
|
|
|
|
let document = this._getTextDocument(uri);
|
|
|
|
|
const document = this._getTextDocument(uri);
|
|
|
|
|
if (!document) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
let ranges = this._languageService.getFoldingRanges(document, context);
|
|
|
|
|
const ranges = this._languageService.getFoldingRanges(document, context);
|
|
|
|
|
return Promise.resolve(ranges);
|
|
|
|
|
}
|
|
|
|
|
async getSelectionRanges(
|
|
|
|
|
uri: string,
|
|
|
|
|
positions: cssService.Position[]
|
|
|
|
|
): Promise<cssService.SelectionRange[]> {
|
|
|
|
|
let document = this._getTextDocument(uri);
|
|
|
|
|
const document = this._getTextDocument(uri);
|
|
|
|
|
if (!document) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
let stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
let ranges = this._languageService.getSelectionRanges(document, positions, stylesheet);
|
|
|
|
|
const stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
const ranges = this._languageService.getSelectionRanges(document, positions, stylesheet);
|
|
|
|
|
return Promise.resolve(ranges);
|
|
|
|
|
}
|
|
|
|
|
async doRename(
|
|
|
|
@ -192,17 +192,30 @@ export class CSSWorker {
|
|
|
|
|
position: cssService.Position,
|
|
|
|
|
newName: string
|
|
|
|
|
): Promise<cssService.WorkspaceEdit | null> {
|
|
|
|
|
let document = this._getTextDocument(uri);
|
|
|
|
|
const document = this._getTextDocument(uri);
|
|
|
|
|
if (!document) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
let stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
let renames = this._languageService.doRename(document, position, newName, stylesheet);
|
|
|
|
|
const stylesheet = this._languageService.parseStylesheet(document);
|
|
|
|
|
const renames = this._languageService.doRename(document, position, newName, stylesheet);
|
|
|
|
|
return Promise.resolve(renames);
|
|
|
|
|
}
|
|
|
|
|
async format(
|
|
|
|
|
uri: string,
|
|
|
|
|
range: cssService.Range | null,
|
|
|
|
|
options: cssService.CSSFormatConfiguration
|
|
|
|
|
): Promise<cssService.TextEdit[]> {
|
|
|
|
|
const document = this._getTextDocument(uri);
|
|
|
|
|
if (!document) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
const settings = { ...this._languageSettings.format, ...options };
|
|
|
|
|
const textEdits = this._languageService.format(document, range! /* TODO */, settings);
|
|
|
|
|
return Promise.resolve(textEdits);
|
|
|
|
|
}
|
|
|
|
|
private _getTextDocument(uri: string): cssService.TextDocument | null {
|
|
|
|
|
let models = this._ctx.getMirrorModels();
|
|
|
|
|
for (let model of models) {
|
|
|
|
|
const models = this._ctx.getMirrorModels();
|
|
|
|
|
for (const model of models) {
|
|
|
|
|
if (model.uri.toString() === uri) {
|
|
|
|
|
return cssService.TextDocument.create(
|
|
|
|
|
uri,
|
|
|
|
|