|
1 | 1 | import * as monaco from 'monaco-editor';
|
2 | 2 | import * as vscode from 'vscode-languageserver-types';
|
3 | 3 |
|
4 |
| -function vscodeCompletionItemKindToMonaco( |
5 |
| - kind: vscode.CompletionItemKind | undefined, |
6 |
| -): monaco.languages.CompletionItemKind { |
| 4 | +export function asCompletionList(list: vscode.CompletionList): monaco.languages.CompletionList { |
| 5 | + return { |
| 6 | + incomplete: list.isIncomplete, |
| 7 | + suggestions: list.items.map(asCompletionItem), |
| 8 | + }; |
| 9 | +} |
| 10 | + |
| 11 | +export function asCompletionItemKind(kind: vscode.CompletionItemKind | undefined): monaco.languages.CompletionItemKind { |
7 | 12 | switch (kind) {
|
8 | 13 | case vscode.CompletionItemKind.Method:
|
9 | 14 | return monaco.languages.CompletionItemKind.Method;
|
@@ -60,12 +65,59 @@ function vscodeCompletionItemKindToMonaco(
|
60 | 65 | }
|
61 | 66 | }
|
62 | 67 |
|
63 |
| -export function vscodeCompletionItemToMonaco(item: vscode.CompletionItem): monaco.languages.CompletionItem { |
| 68 | +export function asCompletionItem(item: vscode.CompletionItem): monaco.languages.CompletionItem { |
64 | 69 | return {
|
65 | 70 | label: item.label,
|
66 |
| - insertText: item.insertText ?? item.label, |
67 |
| - kind: vscodeCompletionItemKindToMonaco(item.kind), |
| 71 | + kind: asCompletionItemKind(item.kind), |
| 72 | + tags: item.tags, |
| 73 | + detail: item.detail, |
| 74 | + documentation: item.documentation, |
68 | 75 | sortText: item.sortText,
|
69 |
| - range: undefined!, |
| 76 | + filterText: item.filterText, |
| 77 | + preselect: item.preselect, |
| 78 | + insertText: item.textEdit?.newText ?? item.insertText ?? item.label, |
| 79 | + range: asCompletionItemRange(item.textEdit), |
| 80 | + commitCharacters: item.commitCharacters, |
| 81 | + additionalTextEdits: item.additionalTextEdits?.map(asTextEdit), |
| 82 | + command: item.command ? asCommand(item.command) : undefined, |
| 83 | + }; |
| 84 | +} |
| 85 | + |
| 86 | +export function asCommand(command: vscode.Command): monaco.languages.Command { |
| 87 | + return { |
| 88 | + id: command.command, |
| 89 | + title: command.title, |
| 90 | + arguments: command.arguments, |
| 91 | + }; |
| 92 | +} |
| 93 | + |
| 94 | +export function asTextEdit(edit: vscode.TextEdit): monaco.languages.TextEdit { |
| 95 | + return { |
| 96 | + range: asRange(edit.range), |
| 97 | + text: edit.newText, |
| 98 | + }; |
| 99 | +} |
| 100 | + |
| 101 | +export function asCompletionItemRange(textEdit: vscode.CompletionItem['textEdit']): monaco.languages.CompletionItem['range'] { |
| 102 | + if (textEdit && 'insert' in textEdit && 'replace' in textEdit) { |
| 103 | + const result: monaco.languages.CompletionItemRanges = { |
| 104 | + insert: asRange(textEdit.insert), |
| 105 | + replace: asRange(textEdit.replace), |
| 106 | + }; |
| 107 | + return result; |
| 108 | + } |
| 109 | + else if (textEdit) { |
| 110 | + return asRange(textEdit.range); |
| 111 | + } |
| 112 | + // @ts-expect-error |
| 113 | + return undefined; |
| 114 | +} |
| 115 | + |
| 116 | +export function asRange(range: vscode.Range): monaco.IRange { |
| 117 | + return { |
| 118 | + startLineNumber: range.start.line + 1, |
| 119 | + startColumn: range.start.character + 1, |
| 120 | + endLineNumber: range.end.line + 1, |
| 121 | + endColumn: range.end.character + 1, |
70 | 122 | };
|
71 | 123 | }
|
0 commit comments