|
|
|
@ -8,11 +8,12 @@ import * as lsTypes from 'vscode-languageserver-types';
|
|
|
|
|
import {
|
|
|
|
|
languages,
|
|
|
|
|
editor,
|
|
|
|
|
IMarkdownString,
|
|
|
|
|
Uri,
|
|
|
|
|
Position,
|
|
|
|
|
IRange,
|
|
|
|
|
Range,
|
|
|
|
|
CancellationToken,
|
|
|
|
|
IMarkdownString
|
|
|
|
|
CancellationToken
|
|
|
|
|
} from '../fillers/monaco-editor-core';
|
|
|
|
|
|
|
|
|
|
export interface WorkerAccessor {
|
|
|
|
@ -21,24 +22,35 @@ export interface WorkerAccessor {
|
|
|
|
|
|
|
|
|
|
// --- completion ------
|
|
|
|
|
|
|
|
|
|
function fromPosition(position: Position): lsTypes.Position {
|
|
|
|
|
function fromPosition(position: Position): lsTypes.Position;
|
|
|
|
|
function fromPosition(position: undefined): undefined;
|
|
|
|
|
function fromPosition(position: Position | undefined): lsTypes.Position | undefined;
|
|
|
|
|
function fromPosition(position: Position | undefined): lsTypes.Position | undefined {
|
|
|
|
|
if (!position) {
|
|
|
|
|
return void 0;
|
|
|
|
|
}
|
|
|
|
|
return { character: position.column - 1, line: position.lineNumber - 1 };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fromRange(range: Range): lsTypes.Range {
|
|
|
|
|
function fromRange(range: IRange): lsTypes.Range;
|
|
|
|
|
function fromRange(range: undefined): undefined;
|
|
|
|
|
function fromRange(range: IRange | undefined): lsTypes.Range | undefined;
|
|
|
|
|
function fromRange(range: IRange | undefined): lsTypes.Range | undefined {
|
|
|
|
|
if (!range) {
|
|
|
|
|
return void 0;
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
start: fromPosition(range.getStartPosition()),
|
|
|
|
|
end: fromPosition(range.getEndPosition())
|
|
|
|
|
start: {
|
|
|
|
|
line: range.startLineNumber - 1,
|
|
|
|
|
character: range.startColumn - 1
|
|
|
|
|
},
|
|
|
|
|
end: { line: range.endLineNumber - 1, character: range.endColumn - 1 }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toRange(range: lsTypes.Range): Range {
|
|
|
|
|
function toRange(range: lsTypes.Range): Range;
|
|
|
|
|
function toRange(range: undefined): undefined;
|
|
|
|
|
function toRange(range: lsTypes.Range | undefined): Range | undefined;
|
|
|
|
|
function toRange(range: lsTypes.Range | undefined): Range | undefined {
|
|
|
|
|
if (!range) {
|
|
|
|
|
return void 0;
|
|
|
|
|
}
|
|
|
|
@ -59,7 +71,7 @@ function isInsertReplaceEdit(
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toCompletionItemKind(kind: number): languages.CompletionItemKind {
|
|
|
|
|
function toCompletionItemKind(kind: number | undefined): languages.CompletionItemKind {
|
|
|
|
|
const mItemKind = languages.CompletionItemKind;
|
|
|
|
|
|
|
|
|
|
switch (kind) {
|
|
|
|
@ -147,7 +159,10 @@ function fromCompletionItemKind(kind: languages.CompletionItemKind): lsTypes.Com
|
|
|
|
|
return lsTypes.CompletionItemKind.Property;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toTextEdit(textEdit: lsTypes.TextEdit): editor.ISingleEditOperation {
|
|
|
|
|
function toTextEdit(textEdit: lsTypes.TextEdit): languages.TextEdit;
|
|
|
|
|
function toTextEdit(textEdit: undefined): undefined;
|
|
|
|
|
function toTextEdit(textEdit: lsTypes.TextEdit | undefined): languages.TextEdit | undefined;
|
|
|
|
|
function toTextEdit(textEdit: lsTypes.TextEdit | undefined): languages.TextEdit | undefined {
|
|
|
|
|
if (!textEdit) {
|
|
|
|
|
return void 0;
|
|
|
|
|
}
|
|
|
|
@ -157,7 +172,7 @@ function toTextEdit(textEdit: lsTypes.TextEdit): editor.ISingleEditOperation {
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toCommand(c: lsTypes.Command | undefined): languages.Command {
|
|
|
|
|
function toCommand(c: lsTypes.Command | undefined): languages.Command | undefined {
|
|
|
|
|
return c && c.command === 'editor.action.triggerSuggest'
|
|
|
|
|
? { id: c.command, title: c.title, arguments: c.arguments }
|
|
|
|
|
: undefined;
|
|
|
|
@ -175,7 +190,7 @@ export class CompletionAdapter implements languages.CompletionItemProvider {
|
|
|
|
|
position: Position,
|
|
|
|
|
context: languages.CompletionContext,
|
|
|
|
|
token: CancellationToken
|
|
|
|
|
): Promise<languages.CompletionList> {
|
|
|
|
|
): Promise<languages.CompletionList | undefined> {
|
|
|
|
|
const resource = model.uri;
|
|
|
|
|
|
|
|
|
|
return this._worker(resource)
|
|
|
|
@ -201,8 +216,8 @@ export class CompletionAdapter implements languages.CompletionItemProvider {
|
|
|
|
|
sortText: entry.sortText,
|
|
|
|
|
filterText: entry.filterText,
|
|
|
|
|
documentation: entry.documentation,
|
|
|
|
|
command: toCommand(entry.command),
|
|
|
|
|
detail: entry.detail,
|
|
|
|
|
command: toCommand(entry.command),
|
|
|
|
|
range: wordRange,
|
|
|
|
|
kind: toCompletionItemKind(entry.kind)
|
|
|
|
|
};
|
|
|
|
@ -218,7 +233,8 @@ export class CompletionAdapter implements languages.CompletionItemProvider {
|
|
|
|
|
item.insertText = entry.textEdit.newText;
|
|
|
|
|
}
|
|
|
|
|
if (entry.additionalTextEdits) {
|
|
|
|
|
item.additionalTextEdits = entry.additionalTextEdits.map(toTextEdit);
|
|
|
|
|
item.additionalTextEdits =
|
|
|
|
|
entry.additionalTextEdits.map<languages.TextEdit>(toTextEdit);
|
|
|
|
|
}
|
|
|
|
|
if (entry.insertTextFormat === lsTypes.InsertTextFormat.Snippet) {
|
|
|
|
|
item.insertTextRules = languages.CompletionItemInsertTextRule.InsertAsSnippet;
|
|
|
|
@ -234,8 +250,6 @@ export class CompletionAdapter implements languages.CompletionItemProvider {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- hover ------
|
|
|
|
|
|
|
|
|
|
function isMarkupContent(thing: any): thing is lsTypes.MarkupContent {
|
|
|
|
|
return (
|
|
|
|
|
thing && typeof thing === 'object' && typeof (<lsTypes.MarkupContent>thing).kind === 'string'
|
|
|
|
@ -264,7 +278,7 @@ function toMarkdownString(entry: lsTypes.MarkupContent | lsTypes.MarkedString):
|
|
|
|
|
|
|
|
|
|
function toMarkedStringArray(
|
|
|
|
|
contents: lsTypes.MarkupContent | lsTypes.MarkedString | lsTypes.MarkedString[]
|
|
|
|
|
): IMarkdownString[] {
|
|
|
|
|
): IMarkdownString[] | undefined {
|
|
|
|
|
if (!contents) {
|
|
|
|
|
return void 0;
|
|
|
|
|
}
|
|
|
|
@ -274,6 +288,8 @@ function toMarkedStringArray(
|
|
|
|
|
return [toMarkdownString(contents)];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- hover ------
|
|
|
|
|
|
|
|
|
|
export class HoverAdapter implements languages.HoverProvider {
|
|
|
|
|
constructor(private _worker: WorkerAccessor) {}
|
|
|
|
|
|
|
|
|
@ -281,7 +297,7 @@ export class HoverAdapter implements languages.HoverProvider {
|
|
|
|
|
model: editor.IReadOnlyModel,
|
|
|
|
|
position: Position,
|
|
|
|
|
token: CancellationToken
|
|
|
|
|
): Promise<languages.Hover> {
|
|
|
|
|
): Promise<languages.Hover | undefined> {
|
|
|
|
|
let resource = model.uri;
|
|
|
|
|
|
|
|
|
|
return this._worker(resource)
|
|
|
|
@ -302,18 +318,18 @@ export class HoverAdapter implements languages.HoverProvider {
|
|
|
|
|
|
|
|
|
|
// --- document highlights ------
|
|
|
|
|
|
|
|
|
|
function toHighlighKind(kind: lsTypes.DocumentHighlightKind): languages.DocumentHighlightKind {
|
|
|
|
|
const mKind = languages.DocumentHighlightKind;
|
|
|
|
|
|
|
|
|
|
function toDocumentHighlightKind(
|
|
|
|
|
kind: lsTypes.DocumentHighlightKind
|
|
|
|
|
): languages.DocumentHighlightKind {
|
|
|
|
|
switch (kind) {
|
|
|
|
|
case lsTypes.DocumentHighlightKind.Read:
|
|
|
|
|
return mKind.Read;
|
|
|
|
|
return languages.DocumentHighlightKind.Read;
|
|
|
|
|
case lsTypes.DocumentHighlightKind.Write:
|
|
|
|
|
return mKind.Write;
|
|
|
|
|
return languages.DocumentHighlightKind.Write;
|
|
|
|
|
case lsTypes.DocumentHighlightKind.Text:
|
|
|
|
|
return mKind.Text;
|
|
|
|
|
return languages.DocumentHighlightKind.Text;
|
|
|
|
|
}
|
|
|
|
|
return mKind.Text;
|
|
|
|
|
return languages.DocumentHighlightKind.Text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class DocumentHighlightAdapter implements languages.DocumentHighlightProvider {
|
|
|
|
@ -328,14 +344,59 @@ export class DocumentHighlightAdapter implements languages.DocumentHighlightProv
|
|
|
|
|
|
|
|
|
|
return this._worker(resource)
|
|
|
|
|
.then((worker) => worker.findDocumentHighlights(resource.toString(), fromPosition(position)))
|
|
|
|
|
.then((items) => {
|
|
|
|
|
if (!items) {
|
|
|
|
|
.then((entries) => {
|
|
|
|
|
if (!entries) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return items.map((item) => ({
|
|
|
|
|
range: toRange(item.range),
|
|
|
|
|
kind: toHighlighKind(item.kind)
|
|
|
|
|
}));
|
|
|
|
|
return entries.map((entry) => {
|
|
|
|
|
return <languages.DocumentHighlight>{
|
|
|
|
|
range: toRange(entry.range),
|
|
|
|
|
kind: toDocumentHighlightKind(entry.kind)
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toWorkspaceEdit(edit: lsTypes.WorkspaceEdit): languages.WorkspaceEdit {
|
|
|
|
|
if (!edit || !edit.changes) {
|
|
|
|
|
return void 0;
|
|
|
|
|
}
|
|
|
|
|
let resourceEdits: languages.WorkspaceTextEdit[] = [];
|
|
|
|
|
for (let uri in edit.changes) {
|
|
|
|
|
const _uri = Uri.parse(uri);
|
|
|
|
|
for (let e of edit.changes[uri]) {
|
|
|
|
|
resourceEdits.push({
|
|
|
|
|
resource: _uri,
|
|
|
|
|
edit: {
|
|
|
|
|
range: toRange(e.range),
|
|
|
|
|
text: e.newText
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
edits: resourceEdits
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class RenameAdapter implements languages.RenameProvider {
|
|
|
|
|
constructor(private _worker: WorkerAccessor) {}
|
|
|
|
|
|
|
|
|
|
provideRenameEdits(
|
|
|
|
|
model: editor.IReadOnlyModel,
|
|
|
|
|
position: Position,
|
|
|
|
|
newName: string,
|
|
|
|
|
token: CancellationToken
|
|
|
|
|
): Promise<languages.WorkspaceEdit> {
|
|
|
|
|
const resource = model.uri;
|
|
|
|
|
|
|
|
|
|
return this._worker(resource)
|
|
|
|
|
.then((worker) => {
|
|
|
|
|
return worker.doRename(resource.toString(), fromPosition(position), newName);
|
|
|
|
|
})
|
|
|
|
|
.then((edit) => {
|
|
|
|
|
return toWorkspaceEdit(edit);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -392,7 +453,7 @@ export class DocumentSymbolAdapter implements languages.DocumentSymbolProvider {
|
|
|
|
|
public provideDocumentSymbols(
|
|
|
|
|
model: editor.IReadOnlyModel,
|
|
|
|
|
token: CancellationToken
|
|
|
|
|
): Promise<languages.DocumentSymbol[]> {
|
|
|
|
|
): Promise<languages.DocumentSymbol[] | undefined> {
|
|
|
|
|
const resource = model.uri;
|
|
|
|
|
|
|
|
|
|
return this._worker(resource)
|
|
|
|
@ -406,9 +467,9 @@ export class DocumentSymbolAdapter implements languages.DocumentSymbolProvider {
|
|
|
|
|
detail: '',
|
|
|
|
|
containerName: item.containerName,
|
|
|
|
|
kind: toSymbolKind(item.kind),
|
|
|
|
|
tags: [],
|
|
|
|
|
range: toRange(item.location.range),
|
|
|
|
|
selectionRange: toRange(item.location.range)
|
|
|
|
|
selectionRange: toRange(item.location.range),
|
|
|
|
|
tags: []
|
|
|
|
|
}));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -453,7 +514,7 @@ export class DocumentFormattingEditProvider implements languages.DocumentFormatt
|
|
|
|
|
model: editor.IReadOnlyModel,
|
|
|
|
|
options: languages.FormattingOptions,
|
|
|
|
|
token: CancellationToken
|
|
|
|
|
): Promise<editor.ISingleEditOperation[]> {
|
|
|
|
|
): Promise<languages.TextEdit[] | undefined> {
|
|
|
|
|
const resource = model.uri;
|
|
|
|
|
|
|
|
|
|
return this._worker(resource).then((worker) => {
|
|
|
|
@ -463,7 +524,7 @@ export class DocumentFormattingEditProvider implements languages.DocumentFormatt
|
|
|
|
|
if (!edits || edits.length === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return edits.map(toTextEdit);
|
|
|
|
|
return edits.map<languages.TextEdit>(toTextEdit);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -479,7 +540,7 @@ export class DocumentRangeFormattingEditProvider
|
|
|
|
|
range: Range,
|
|
|
|
|
options: languages.FormattingOptions,
|
|
|
|
|
token: CancellationToken
|
|
|
|
|
): Promise<editor.ISingleEditOperation[]> {
|
|
|
|
|
): Promise<languages.TextEdit[] | undefined> {
|
|
|
|
|
const resource = model.uri;
|
|
|
|
|
|
|
|
|
|
return this._worker(resource).then((worker) => {
|
|
|
|
@ -489,55 +550,12 @@ export class DocumentRangeFormattingEditProvider
|
|
|
|
|
if (!edits || edits.length === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return edits.map(toTextEdit);
|
|
|
|
|
return edits.map<languages.TextEdit>(toTextEdit);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class RenameAdapter implements languages.RenameProvider {
|
|
|
|
|
constructor(private _worker: WorkerAccessor) {}
|
|
|
|
|
|
|
|
|
|
provideRenameEdits(
|
|
|
|
|
model: editor.IReadOnlyModel,
|
|
|
|
|
position: Position,
|
|
|
|
|
newName: string,
|
|
|
|
|
token: CancellationToken
|
|
|
|
|
): Promise<languages.WorkspaceEdit> {
|
|
|
|
|
const resource = model.uri;
|
|
|
|
|
|
|
|
|
|
return this._worker(resource)
|
|
|
|
|
.then((worker) => {
|
|
|
|
|
return worker.doRename(resource.toString(), fromPosition(position), newName);
|
|
|
|
|
})
|
|
|
|
|
.then((edit) => {
|
|
|
|
|
return toWorkspaceEdit(edit);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toWorkspaceEdit(edit: lsTypes.WorkspaceEdit): languages.WorkspaceEdit {
|
|
|
|
|
if (!edit || !edit.changes) {
|
|
|
|
|
return void 0;
|
|
|
|
|
}
|
|
|
|
|
let resourceEdits: languages.WorkspaceTextEdit[] = [];
|
|
|
|
|
for (let uri in edit.changes) {
|
|
|
|
|
const _uri = Uri.parse(uri);
|
|
|
|
|
for (let e of edit.changes[uri]) {
|
|
|
|
|
resourceEdits.push({
|
|
|
|
|
resource: _uri,
|
|
|
|
|
edit: {
|
|
|
|
|
range: toRange(e.range),
|
|
|
|
|
text: e.newText
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
edits: resourceEdits
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class FoldingRangeAdapter implements languages.FoldingRangeProvider {
|
|
|
|
|
constructor(private _worker: WorkerAccessor) {}
|
|
|
|
|
|
|
|
|
@ -545,7 +563,7 @@ export class FoldingRangeAdapter implements languages.FoldingRangeProvider {
|
|
|
|
|
model: editor.IReadOnlyModel,
|
|
|
|
|
context: languages.FoldingContext,
|
|
|
|
|
token: CancellationToken
|
|
|
|
|
): Promise<languages.FoldingRange[]> {
|
|
|
|
|
): Promise<languages.FoldingRange[] | undefined> {
|
|
|
|
|
const resource = model.uri;
|
|
|
|
|
|
|
|
|
|
return this._worker(resource)
|
|
|
|
@ -568,7 +586,9 @@ export class FoldingRangeAdapter implements languages.FoldingRangeProvider {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toFoldingRangeKind(kind: lsTypes.FoldingRangeKind): languages.FoldingRangeKind {
|
|
|
|
|
function toFoldingRangeKind(
|
|
|
|
|
kind: lsTypes.FoldingRangeKind
|
|
|
|
|
): languages.FoldingRangeKind | undefined {
|
|
|
|
|
switch (kind) {
|
|
|
|
|
case lsTypes.FoldingRangeKind.Comment:
|
|
|
|
|
return languages.FoldingRangeKind.Comment;
|
|
|
|
@ -577,6 +597,7 @@ function toFoldingRangeKind(kind: lsTypes.FoldingRangeKind): languages.FoldingRa
|
|
|
|
|
case lsTypes.FoldingRangeKind.Region:
|
|
|
|
|
return languages.FoldingRangeKind.Region;
|
|
|
|
|
}
|
|
|
|
|
return void 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class SelectionRangeAdapter implements languages.SelectionRangeProvider {
|
|
|
|
@ -586,16 +607,21 @@ export class SelectionRangeAdapter implements languages.SelectionRangeProvider {
|
|
|
|
|
model: editor.IReadOnlyModel,
|
|
|
|
|
positions: Position[],
|
|
|
|
|
token: CancellationToken
|
|
|
|
|
): Promise<languages.SelectionRange[][]> {
|
|
|
|
|
): Promise<languages.SelectionRange[][] | undefined> {
|
|
|
|
|
const resource = model.uri;
|
|
|
|
|
|
|
|
|
|
return this._worker(resource)
|
|
|
|
|
.then((worker) => worker.getSelectionRanges(resource.toString(), positions.map(fromPosition)))
|
|
|
|
|
.then((worker) =>
|
|
|
|
|
worker.getSelectionRanges(
|
|
|
|
|
resource.toString(),
|
|
|
|
|
positions.map<lsTypes.Position>(fromPosition)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
.then((selectionRanges) => {
|
|
|
|
|
if (!selectionRanges) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return selectionRanges.map((selectionRange) => {
|
|
|
|
|
return selectionRanges.map((selectionRange: lsTypes.SelectionRange | undefined) => {
|
|
|
|
|
const result: languages.SelectionRange[] = [];
|
|
|
|
|
while (selectionRange) {
|
|
|
|
|
result.push({ range: toRange(selectionRange.range) });
|
|
|
|
|