|
|
@ -217,50 +217,6 @@ interface DataCompletionItem extends monaco.languages.CompletionItem {
|
|
|
|
data?: any;
|
|
|
|
data?: any;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function toCompletionItem(entry: ls.CompletionItem): DataCompletionItem {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
label: entry.label,
|
|
|
|
|
|
|
|
insertText: entry.insertText,
|
|
|
|
|
|
|
|
sortText: entry.sortText,
|
|
|
|
|
|
|
|
filterText: entry.filterText,
|
|
|
|
|
|
|
|
documentation: entry.documentation,
|
|
|
|
|
|
|
|
detail: entry.detail,
|
|
|
|
|
|
|
|
kind: toCompletionItemKind(entry.kind),
|
|
|
|
|
|
|
|
textEdit: toTextEdit(entry.textEdit),
|
|
|
|
|
|
|
|
data: entry.data
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function fromMarkdownString(entry: string | monaco.IMarkdownString): ls.MarkupContent {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
kind: (typeof entry === 'string' ? ls.MarkupKind.PlainText : ls.MarkupKind.Markdown),
|
|
|
|
|
|
|
|
value: (typeof entry === 'string' ? entry : entry.value)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function fromCompletionItem(entry: DataCompletionItem): ls.CompletionItem {
|
|
|
|
|
|
|
|
let item: ls.CompletionItem = {
|
|
|
|
|
|
|
|
label: entry.label,
|
|
|
|
|
|
|
|
sortText: entry.sortText,
|
|
|
|
|
|
|
|
filterText: entry.filterText,
|
|
|
|
|
|
|
|
documentation: fromMarkdownString(entry.documentation),
|
|
|
|
|
|
|
|
detail: entry.detail,
|
|
|
|
|
|
|
|
kind: fromCompletionItemKind(entry.kind),
|
|
|
|
|
|
|
|
data: entry.data
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
if (typeof entry.insertText === 'object' && typeof entry.insertText.value === 'string') {
|
|
|
|
|
|
|
|
item.insertText = entry.insertText.value;
|
|
|
|
|
|
|
|
item.insertTextFormat = ls.InsertTextFormat.Snippet
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
item.insertText = <string>entry.insertText;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entry.range) {
|
|
|
|
|
|
|
|
item.textEdit = ls.TextEdit.replace(fromRange(entry.range), item.insertText);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class CompletionAdapter implements monaco.languages.CompletionItemProvider {
|
|
|
|
export class CompletionAdapter implements monaco.languages.CompletionItemProvider {
|
|
|
|
|
|
|
|
|
|
|
|
constructor(private _worker: WorkerAccessor) {
|
|
|
|
constructor(private _worker: WorkerAccessor) {
|
|
|
@ -270,11 +226,11 @@ export class CompletionAdapter implements monaco.languages.CompletionItemProvide
|
|
|
|
return ['.', ':', '<', '"', '=', '/'];
|
|
|
|
return ['.', ':', '<', '"', '=', '/'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
provideCompletionItems(model: monaco.editor.IReadOnlyModel, position: Position, token: CancellationToken): Thenable<monaco.languages.CompletionList> {
|
|
|
|
provideCompletionItems(model: monaco.editor.IReadOnlyModel, position: Position, context: monaco.languages.CompletionContext, token: CancellationToken): Thenable<monaco.languages.CompletionList> {
|
|
|
|
const wordInfo = model.getWordUntilPosition(position);
|
|
|
|
const wordInfo = model.getWordUntilPosition(position);
|
|
|
|
const resource = model.uri;
|
|
|
|
const resource = model.uri;
|
|
|
|
|
|
|
|
|
|
|
|
return wireCancellationToken(token, this._worker(resource).then(worker => {
|
|
|
|
return this._worker(resource).then(worker => {
|
|
|
|
return worker.doComplete(resource.toString(), fromPosition(position));
|
|
|
|
return worker.doComplete(resource.toString(), fromPosition(position));
|
|
|
|
}).then(info => {
|
|
|
|
}).then(info => {
|
|
|
|
if (!info) {
|
|
|
|
if (!info) {
|
|
|
@ -283,7 +239,7 @@ export class CompletionAdapter implements monaco.languages.CompletionItemProvide
|
|
|
|
let items: monaco.languages.CompletionItem[] = info.items.map(entry => {
|
|
|
|
let items: monaco.languages.CompletionItem[] = info.items.map(entry => {
|
|
|
|
let item: monaco.languages.CompletionItem = {
|
|
|
|
let item: monaco.languages.CompletionItem = {
|
|
|
|
label: entry.label,
|
|
|
|
label: entry.label,
|
|
|
|
insertText: entry.insertText,
|
|
|
|
insertText: entry.insertText || entry.label,
|
|
|
|
sortText: entry.sortText,
|
|
|
|
sortText: entry.sortText,
|
|
|
|
filterText: entry.filterText,
|
|
|
|
filterText: entry.filterText,
|
|
|
|
documentation: entry.documentation,
|
|
|
|
documentation: entry.documentation,
|
|
|
@ -294,17 +250,20 @@ export class CompletionAdapter implements monaco.languages.CompletionItemProvide
|
|
|
|
item.range = toRange(entry.textEdit.range);
|
|
|
|
item.range = toRange(entry.textEdit.range);
|
|
|
|
item.insertText = entry.textEdit.newText;
|
|
|
|
item.insertText = entry.textEdit.newText;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entry.additionalTextEdits) {
|
|
|
|
|
|
|
|
item.additionalTextEdits = entry.additionalTextEdits.map(toTextEdit)
|
|
|
|
|
|
|
|
}
|
|
|
|
if (entry.insertTextFormat === ls.InsertTextFormat.Snippet) {
|
|
|
|
if (entry.insertTextFormat === ls.InsertTextFormat.Snippet) {
|
|
|
|
item.insertText = { value: <string>item.insertText };
|
|
|
|
item.insertTextRules = monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
isIncomplete: info.isIncomplete,
|
|
|
|
isIncomplete: info.isIncomplete,
|
|
|
|
items: items
|
|
|
|
suggestions: items
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -354,7 +313,7 @@ export class DocumentHighlightAdapter implements monaco.languages.DocumentHighli
|
|
|
|
public provideDocumentHighlights(model: monaco.editor.IReadOnlyModel, position: Position, token: CancellationToken): Thenable<monaco.languages.DocumentHighlight[]> {
|
|
|
|
public provideDocumentHighlights(model: monaco.editor.IReadOnlyModel, position: Position, token: CancellationToken): Thenable<monaco.languages.DocumentHighlight[]> {
|
|
|
|
const resource = model.uri;
|
|
|
|
const resource = model.uri;
|
|
|
|
|
|
|
|
|
|
|
|
return wireCancellationToken(token, this._worker(resource).then(worker => worker.findDocumentHighlights(resource.toString(), fromPosition(position))).then(items => {
|
|
|
|
return this._worker(resource).then(worker => worker.findDocumentHighlights(resource.toString(), fromPosition(position))).then(items => {
|
|
|
|
if (!items) {
|
|
|
|
if (!items) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -362,7 +321,7 @@ export class DocumentHighlightAdapter implements monaco.languages.DocumentHighli
|
|
|
|
range: toRange(item.range),
|
|
|
|
range: toRange(item.range),
|
|
|
|
kind: toHighlighKind(item.kind)
|
|
|
|
kind: toHighlighKind(item.kind)
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -374,7 +333,7 @@ export class DocumentLinkAdapter implements monaco.languages.LinkProvider {
|
|
|
|
public provideLinks(model: monaco.editor.IReadOnlyModel, token: CancellationToken): Thenable<monaco.languages.ILink[]> {
|
|
|
|
public provideLinks(model: monaco.editor.IReadOnlyModel, token: CancellationToken): Thenable<monaco.languages.ILink[]> {
|
|
|
|
const resource = model.uri;
|
|
|
|
const resource = model.uri;
|
|
|
|
|
|
|
|
|
|
|
|
return wireCancellationToken(token, this._worker(resource).then(worker => worker.findDocumentLinks(resource.toString())).then(items => {
|
|
|
|
return this._worker(resource).then(worker => worker.findDocumentLinks(resource.toString())).then(items => {
|
|
|
|
if (!items) {
|
|
|
|
if (!items) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -382,7 +341,7 @@ export class DocumentLinkAdapter implements monaco.languages.LinkProvider {
|
|
|
|
range: toRange(item.range),
|
|
|
|
range: toRange(item.range),
|
|
|
|
url: item.target
|
|
|
|
url: item.target
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -402,14 +361,14 @@ export class DocumentFormattingEditProvider implements monaco.languages.Document
|
|
|
|
public provideDocumentFormattingEdits(model: monaco.editor.IReadOnlyModel, options: monaco.languages.FormattingOptions, token: CancellationToken): Thenable<monaco.editor.ISingleEditOperation[]> {
|
|
|
|
public provideDocumentFormattingEdits(model: monaco.editor.IReadOnlyModel, options: monaco.languages.FormattingOptions, token: CancellationToken): Thenable<monaco.editor.ISingleEditOperation[]> {
|
|
|
|
const resource = model.uri;
|
|
|
|
const resource = model.uri;
|
|
|
|
|
|
|
|
|
|
|
|
return wireCancellationToken(token, this._worker(resource).then(worker => {
|
|
|
|
return this._worker(resource).then(worker => {
|
|
|
|
return worker.format(resource.toString(), null, fromFormattingOptions(options)).then(edits => {
|
|
|
|
return worker.format(resource.toString(), null, fromFormattingOptions(options)).then(edits => {
|
|
|
|
if (!edits || edits.length === 0) {
|
|
|
|
if (!edits || edits.length === 0) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return edits.map(toTextEdit);
|
|
|
|
return edits.map(toTextEdit);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -421,14 +380,14 @@ export class DocumentRangeFormattingEditProvider implements monaco.languages.Doc
|
|
|
|
public provideDocumentRangeFormattingEdits(model: monaco.editor.IReadOnlyModel, range: Range, options: monaco.languages.FormattingOptions, token: CancellationToken): Thenable<monaco.editor.ISingleEditOperation[]> {
|
|
|
|
public provideDocumentRangeFormattingEdits(model: monaco.editor.IReadOnlyModel, range: Range, options: monaco.languages.FormattingOptions, token: CancellationToken): Thenable<monaco.editor.ISingleEditOperation[]> {
|
|
|
|
const resource = model.uri;
|
|
|
|
const resource = model.uri;
|
|
|
|
|
|
|
|
|
|
|
|
return wireCancellationToken(token, this._worker(resource).then(worker => {
|
|
|
|
return this._worker(resource).then(worker => {
|
|
|
|
return worker.format(resource.toString(), fromRange(range), fromFormattingOptions(options)).then(edits => {
|
|
|
|
return worker.format(resource.toString(), fromRange(range), fromFormattingOptions(options)).then(edits => {
|
|
|
|
if (!edits || edits.length === 0) {
|
|
|
|
if (!edits || edits.length === 0) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return edits.map(toTextEdit);
|
|
|
|
return edits.map(toTextEdit);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -440,7 +399,7 @@ export class FoldingRangeAdapter implements monaco.languages.FoldingRangeProvide
|
|
|
|
public provideFoldingRanges(model: monaco.editor.IReadOnlyModel, context: monaco.languages.FoldingContext, token: CancellationToken): Thenable<monaco.languages.FoldingRange[]> {
|
|
|
|
public provideFoldingRanges(model: monaco.editor.IReadOnlyModel, context: monaco.languages.FoldingContext, token: CancellationToken): Thenable<monaco.languages.FoldingRange[]> {
|
|
|
|
const resource = model.uri;
|
|
|
|
const resource = model.uri;
|
|
|
|
|
|
|
|
|
|
|
|
return wireCancellationToken(token, this._worker(resource).then(worker => worker.provideFoldingRanges(resource.toString(), context)).then(ranges => {
|
|
|
|
return this._worker(resource).then(worker => worker.provideFoldingRanges(resource.toString(), context)).then(ranges => {
|
|
|
|
if (!ranges) {
|
|
|
|
if (!ranges) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -454,7 +413,7 @@ export class FoldingRangeAdapter implements monaco.languages.FoldingRangeProvide
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -467,13 +426,3 @@ function toFoldingRangeKind(kind: ls.FoldingRangeKind): monaco.languages.Folding
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return void 0;
|
|
|
|
return void 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Hook a cancellation token to a WinJS Promise
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function wireCancellationToken<T>(token: CancellationToken, promise: Thenable<T>): Thenable<T> {
|
|
|
|
|
|
|
|
if ((<Promise<T>>promise).cancel) {
|
|
|
|
|
|
|
|
token.onCancellationRequested(() => (<Promise<T>>promise).cancel());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|