|
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 StandardVO = { |
| 16 | + prefixes: ['StandardVO', 'StandardVO.Currency'], |
| 17 | + completions: { |
| 18 | + StandardVO: ['Currency'], |
| 19 | + 'StandardVO.Currency': ['Value', 'Create'], |
| 20 | + }, |
| 21 | +}; |
9 | 22 |
|
10 | 23 | 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 | | - })); |
| 24 | + public static onCompletion( |
| 25 | + documents: TextDocuments<TextDocument>, |
| 26 | + _textDocumentPosition: TextDocumentPositionParams, |
| 27 | + ) { |
| 28 | + const document = documents.get(_textDocumentPosition.textDocument.uri); |
| 29 | + let text = documents.get(_textDocumentPosition.textDocument.uri).getText(); |
| 30 | + let position = _textDocumentPosition.position; |
| 31 | + const offset = document.offsetAt(position); |
| 32 | + for (const prefix of StandardVO.prefixes) { |
| 33 | + const linePrefix = text.slice(offset - prefix.length - 1, offset); |
| 34 | + if (linePrefix.endsWith(prefix + '.')) { |
| 35 | + return [ |
| 36 | + ...StandardVO.completions[prefix].map((symbol) => ({ |
| 37 | + label: symbol, |
| 38 | + kind: CompletionItemKind.Keyword, |
| 39 | + data: 2, |
| 40 | + //we could check for snippets too |
| 41 | + })), |
| 42 | + ]; |
| 43 | + } |
| 44 | + } |
| 45 | + return [ |
| 46 | + ...allKeywords.map((symbol) => ({ |
| 47 | + label: symbol, |
| 48 | + kind: CompletionItemKind.Keyword, |
| 49 | + data: 1, |
| 50 | + })), |
| 51 | + ]; |
17 | 52 | } |
18 | 53 |
|
19 | 54 | 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]; |
| 55 | + if (item.data == 1) { |
| 56 | + if (documentation[item.label as keyof typeof documentation]) { |
| 57 | + item.documentation = documentation[item.label as keyof typeof documentation]; |
| 58 | + } |
| 59 | + if (details[item.label as keyof typeof details]) { |
| 60 | + item.detail = details[item.label as keyof typeof details]; |
| 61 | + } |
23 | 62 | } |
24 | | - if (details[item.label as keyof typeof details]) { |
25 | | - item.detail = details[item.label as keyof typeof details]; |
26 | | - } |
27 | | - |
28 | 63 | return item; |
29 | 64 | } |
30 | 65 | } |
0 commit comments