|
1 | 1 | import { |
2 | 2 | CompletionItem, |
3 | 3 | CompletionItemKind, |
| 4 | + InsertTextFormat, |
| 5 | + InsertTextMode, |
4 | 6 | TextDocumentPositionParams, |
| 7 | + TextDocuments, |
5 | 8 | } from 'vscode-languageserver/node.js'; |
6 | 9 | import { documentation } from './information/documentation.js'; |
7 | 10 | import { details } from './information/details.js'; |
8 | 11 | import { allKeywords, components, keywords } from './types/keywords.js'; |
| 12 | +import { TextDocument } from 'vscode-languageserver-textdocument'; |
| 13 | + |
| 14 | +//this would come from package |
| 15 | +const StandardVOCompletion = { |
| 16 | + prefixes: ['StandardVO'], |
| 17 | + // , 'StandardVO.Currency'], |
| 18 | + completions: { |
| 19 | + StandardVO: ['Currency'], |
| 20 | + // 'StandardVO.Currency': ['Value', 'Errors'], |
| 21 | + }, |
| 22 | +}; |
9 | 23 |
|
10 | 24 | export class CompletionItemProvider { |
11 | | - public static onCompletion(_textDocumentPosition: TextDocumentPositionParams) { |
12 | | - return allKeywords.map((symbol) => ({ |
13 | | - label: symbol, |
14 | | - kind: CompletionItemKind.Keyword, |
15 | | - data: 1, |
16 | | - })); |
| 25 | + public static onCompletion( |
| 26 | + documents: TextDocuments<TextDocument>, |
| 27 | + _textDocumentPosition: TextDocumentPositionParams, |
| 28 | + ) { |
| 29 | + const document = documents.get(_textDocumentPosition.textDocument.uri); |
| 30 | + let text = documents.get(_textDocumentPosition.textDocument.uri).getText(); |
| 31 | + let position = _textDocumentPosition.position; |
| 32 | + const offset = document.offsetAt(position); |
| 33 | + for (const prefix of StandardVOCompletion.prefixes) { |
| 34 | + const linePrefix = text.slice(offset - prefix.length - 1, offset); |
| 35 | + if (linePrefix.endsWith(prefix + '.')) { |
| 36 | + return [ |
| 37 | + ...StandardVOCompletion.completions[prefix].map((symbol) => ({ |
| 38 | + label: symbol, |
| 39 | + kind: CompletionItemKind.Keyword, |
| 40 | + data: 2, |
| 41 | + //we could add snippets too |
| 42 | + })), |
| 43 | + ]; |
| 44 | + } |
| 45 | + } |
| 46 | + return [ |
| 47 | + ...allKeywords.map((symbol) => ({ |
| 48 | + label: symbol, |
| 49 | + kind: CompletionItemKind.Keyword, |
| 50 | + data: 1, |
| 51 | + })), |
| 52 | + ]; |
17 | 53 | } |
18 | 54 |
|
19 | 55 | public static onCompletionResolve(item: CompletionItem): CompletionItem { |
20 | | - const label: string = item.label; |
21 | | - if (documentation[item.label as keyof typeof documentation]) { |
22 | | - item.documentation = documentation[item.label as keyof typeof documentation]; |
| 56 | + if (item.data == 1) { |
| 57 | + if (documentation[item.label as keyof typeof documentation]) { |
| 58 | + item.documentation = documentation[item.label as keyof typeof documentation]; |
| 59 | + } |
| 60 | + if (details[item.label as keyof typeof details]) { |
| 61 | + item.detail = details[item.label as keyof typeof details]; |
| 62 | + } |
23 | 63 | } |
24 | | - if (details[item.label as keyof typeof details]) { |
25 | | - item.detail = details[item.label as keyof typeof details]; |
26 | | - } |
27 | | - |
28 | 64 | return item; |
29 | 65 | } |
30 | 66 | } |
0 commit comments