|
|
@ -104,11 +104,7 @@ export class DiagnosticsAdapter {
|
|
|
|
.then((worker) => {
|
|
|
|
.then((worker) => {
|
|
|
|
return worker.doValidation(resource.toString()).then((diagnostics) => {
|
|
|
|
return worker.doValidation(resource.toString()).then((diagnostics) => {
|
|
|
|
const markers = diagnostics.map((d) => toDiagnostics(resource, d));
|
|
|
|
const markers = diagnostics.map((d) => toDiagnostics(resource, d));
|
|
|
|
editor.setModelMarkers(
|
|
|
|
editor.setModelMarkers(editor.getModel(resource), languageId, markers);
|
|
|
|
editor.getModel(resource),
|
|
|
|
|
|
|
|
languageId,
|
|
|
|
|
|
|
|
markers
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then(undefined, (err) => {
|
|
|
|
.then(undefined, (err) => {
|
|
|
@ -132,12 +128,8 @@ function toSeverity(lsSeverity: number): MarkerSeverity {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function toDiagnostics(
|
|
|
|
function toDiagnostics(resource: Uri, diag: htmlService.Diagnostic): editor.IMarkerData {
|
|
|
|
resource: Uri,
|
|
|
|
const code = typeof diag.code === 'number' ? String(diag.code) : <string>diag.code;
|
|
|
|
diag: htmlService.Diagnostic
|
|
|
|
|
|
|
|
): editor.IMarkerData {
|
|
|
|
|
|
|
|
const code =
|
|
|
|
|
|
|
|
typeof diag.code === 'number' ? String(diag.code) : <string>diag.code;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
severity: toSeverity(diag.severity),
|
|
|
|
severity: toSeverity(diag.severity),
|
|
|
@ -182,9 +174,7 @@ function toRange(range: htmlService.Range): Range {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function isInsertReplaceEdit(
|
|
|
|
function isInsertReplaceEdit(edit: TextEdit | InsertReplaceEdit): edit is InsertReplaceEdit {
|
|
|
|
edit: TextEdit | InsertReplaceEdit
|
|
|
|
|
|
|
|
): edit is InsertReplaceEdit {
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
typeof (<InsertReplaceEdit>edit).insert !== 'undefined' &&
|
|
|
|
typeof (<InsertReplaceEdit>edit).insert !== 'undefined' &&
|
|
|
|
typeof (<InsertReplaceEdit>edit).replace !== 'undefined'
|
|
|
|
typeof (<InsertReplaceEdit>edit).replace !== 'undefined'
|
|
|
@ -281,9 +271,7 @@ function fromCompletionItemKind(
|
|
|
|
return htmlService.CompletionItemKind.Property;
|
|
|
|
return htmlService.CompletionItemKind.Property;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function toTextEdit(
|
|
|
|
function toTextEdit(textEdit: htmlService.TextEdit): editor.ISingleEditOperation {
|
|
|
|
textEdit: htmlService.TextEdit
|
|
|
|
|
|
|
|
): editor.ISingleEditOperation {
|
|
|
|
|
|
|
|
if (!textEdit) {
|
|
|
|
if (!textEdit) {
|
|
|
|
return void 0;
|
|
|
|
return void 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -347,13 +335,10 @@ export class CompletionAdapter implements languages.CompletionItemProvider {
|
|
|
|
item.insertText = entry.textEdit.newText;
|
|
|
|
item.insertText = entry.textEdit.newText;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (entry.additionalTextEdits) {
|
|
|
|
if (entry.additionalTextEdits) {
|
|
|
|
item.additionalTextEdits = entry.additionalTextEdits.map(
|
|
|
|
item.additionalTextEdits = entry.additionalTextEdits.map(toTextEdit);
|
|
|
|
toTextEdit
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (entry.insertTextFormat === htmlService.InsertTextFormat.Snippet) {
|
|
|
|
if (entry.insertTextFormat === htmlService.InsertTextFormat.Snippet) {
|
|
|
|
item.insertTextRules =
|
|
|
|
item.insertTextRules = languages.CompletionItemInsertTextRule.InsertAsSnippet;
|
|
|
|
languages.CompletionItemInsertTextRule.InsertAsSnippet;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -399,10 +384,7 @@ function toMarkdownString(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function toMarkedStringArray(
|
|
|
|
function toMarkedStringArray(
|
|
|
|
contents:
|
|
|
|
contents: htmlService.MarkupContent | htmlService.MarkedString | htmlService.MarkedString[]
|
|
|
|
| htmlService.MarkupContent
|
|
|
|
|
|
|
|
| htmlService.MarkedString
|
|
|
|
|
|
|
|
| htmlService.MarkedString[]
|
|
|
|
|
|
|
|
): IMarkdownString[] {
|
|
|
|
): IMarkdownString[] {
|
|
|
|
if (!contents) {
|
|
|
|
if (!contents) {
|
|
|
|
return void 0;
|
|
|
|
return void 0;
|
|
|
@ -441,9 +423,7 @@ export class HoverAdapter implements languages.HoverProvider {
|
|
|
|
|
|
|
|
|
|
|
|
// --- document highlights ------
|
|
|
|
// --- document highlights ------
|
|
|
|
|
|
|
|
|
|
|
|
function toHighlighKind(
|
|
|
|
function toHighlighKind(kind: htmlService.DocumentHighlightKind): languages.DocumentHighlightKind {
|
|
|
|
kind: htmlService.DocumentHighlightKind
|
|
|
|
|
|
|
|
): languages.DocumentHighlightKind {
|
|
|
|
|
|
|
|
const mKind = languages.DocumentHighlightKind;
|
|
|
|
const mKind = languages.DocumentHighlightKind;
|
|
|
|
|
|
|
|
|
|
|
|
switch (kind) {
|
|
|
|
switch (kind) {
|
|
|
@ -457,8 +437,7 @@ function toHighlighKind(
|
|
|
|
return mKind.Text;
|
|
|
|
return mKind.Text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export class DocumentHighlightAdapter
|
|
|
|
export class DocumentHighlightAdapter implements languages.DocumentHighlightProvider {
|
|
|
|
implements languages.DocumentHighlightProvider {
|
|
|
|
|
|
|
|
constructor(private _worker: WorkerAccessor) {}
|
|
|
|
constructor(private _worker: WorkerAccessor) {}
|
|
|
|
|
|
|
|
|
|
|
|
public provideDocumentHighlights(
|
|
|
|
public provideDocumentHighlights(
|
|
|
@ -469,12 +448,7 @@ export class DocumentHighlightAdapter
|
|
|
|
const resource = model.uri;
|
|
|
|
const resource = model.uri;
|
|
|
|
|
|
|
|
|
|
|
|
return this._worker(resource)
|
|
|
|
return this._worker(resource)
|
|
|
|
.then((worker) =>
|
|
|
|
.then((worker) => worker.findDocumentHighlights(resource.toString(), fromPosition(position)))
|
|
|
|
worker.findDocumentHighlights(
|
|
|
|
|
|
|
|
resource.toString(),
|
|
|
|
|
|
|
|
fromPosition(position)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.then((items) => {
|
|
|
|
.then((items) => {
|
|
|
|
if (!items) {
|
|
|
|
if (!items) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -595,8 +569,7 @@ function fromFormattingOptions(
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export class DocumentFormattingEditProvider
|
|
|
|
export class DocumentFormattingEditProvider implements languages.DocumentFormattingEditProvider {
|
|
|
|
implements languages.DocumentFormattingEditProvider {
|
|
|
|
|
|
|
|
constructor(private _worker: WorkerAccessor) {}
|
|
|
|
constructor(private _worker: WorkerAccessor) {}
|
|
|
|
|
|
|
|
|
|
|
|
public provideDocumentFormattingEdits(
|
|
|
|
public provideDocumentFormattingEdits(
|
|
|
@ -633,11 +606,7 @@ export class DocumentRangeFormattingEditProvider
|
|
|
|
|
|
|
|
|
|
|
|
return this._worker(resource).then((worker) => {
|
|
|
|
return this._worker(resource).then((worker) => {
|
|
|
|
return worker
|
|
|
|
return worker
|
|
|
|
.format(
|
|
|
|
.format(resource.toString(), fromRange(range), fromFormattingOptions(options))
|
|
|
|
resource.toString(),
|
|
|
|
|
|
|
|
fromRange(range),
|
|
|
|
|
|
|
|
fromFormattingOptions(options)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.then((edits) => {
|
|
|
|
.then((edits) => {
|
|
|
|
if (!edits || edits.length === 0) {
|
|
|
|
if (!edits || edits.length === 0) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -661,11 +630,7 @@ export class RenameAdapter implements languages.RenameProvider {
|
|
|
|
|
|
|
|
|
|
|
|
return this._worker(resource)
|
|
|
|
return this._worker(resource)
|
|
|
|
.then((worker) => {
|
|
|
|
.then((worker) => {
|
|
|
|
return worker.doRename(
|
|
|
|
return worker.doRename(resource.toString(), fromPosition(position), newName);
|
|
|
|
resource.toString(),
|
|
|
|
|
|
|
|
fromPosition(position),
|
|
|
|
|
|
|
|
newName
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then((edit) => {
|
|
|
|
.then((edit) => {
|
|
|
|
return toWorkspaceEdit(edit);
|
|
|
|
return toWorkspaceEdit(edit);
|
|
|
@ -673,9 +638,7 @@ export class RenameAdapter implements languages.RenameProvider {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function toWorkspaceEdit(
|
|
|
|
function toWorkspaceEdit(edit: htmlService.WorkspaceEdit): languages.WorkspaceEdit {
|
|
|
|
edit: htmlService.WorkspaceEdit
|
|
|
|
|
|
|
|
): languages.WorkspaceEdit {
|
|
|
|
|
|
|
|
if (!edit || !edit.changes) {
|
|
|
|
if (!edit || !edit.changes) {
|
|
|
|
return void 0;
|
|
|
|
return void 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -719,9 +682,7 @@ export class FoldingRangeAdapter implements languages.FoldingRangeProvider {
|
|
|
|
end: range.endLine + 1
|
|
|
|
end: range.endLine + 1
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if (typeof range.kind !== 'undefined') {
|
|
|
|
if (typeof range.kind !== 'undefined') {
|
|
|
|
result.kind = toFoldingRangeKind(
|
|
|
|
result.kind = toFoldingRangeKind(<htmlService.FoldingRangeKind>range.kind);
|
|
|
|
<htmlService.FoldingRangeKind>range.kind
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -729,9 +690,7 @@ export class FoldingRangeAdapter implements languages.FoldingRangeProvider {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function toFoldingRangeKind(
|
|
|
|
function toFoldingRangeKind(kind: htmlService.FoldingRangeKind): languages.FoldingRangeKind {
|
|
|
|
kind: htmlService.FoldingRangeKind
|
|
|
|
|
|
|
|
): languages.FoldingRangeKind {
|
|
|
|
|
|
|
|
switch (kind) {
|
|
|
|
switch (kind) {
|
|
|
|
case htmlService.FoldingRangeKind.Comment:
|
|
|
|
case htmlService.FoldingRangeKind.Comment:
|
|
|
|
return languages.FoldingRangeKind.Comment;
|
|
|
|
return languages.FoldingRangeKind.Comment;
|
|
|
@ -753,12 +712,7 @@ export class SelectionRangeAdapter implements languages.SelectionRangeProvider {
|
|
|
|
const resource = model.uri;
|
|
|
|
const resource = model.uri;
|
|
|
|
|
|
|
|
|
|
|
|
return this._worker(resource)
|
|
|
|
return this._worker(resource)
|
|
|
|
.then((worker) =>
|
|
|
|
.then((worker) => worker.getSelectionRanges(resource.toString(), positions.map(fromPosition)))
|
|
|
|
worker.getSelectionRanges(
|
|
|
|
|
|
|
|
resource.toString(),
|
|
|
|
|
|
|
|
positions.map(fromPosition)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.then((selectionRanges) => {
|
|
|
|
.then((selectionRanges) => {
|
|
|
|
if (!selectionRanges) {
|
|
|
|
if (!selectionRanges) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|