|
1 |
| -import vscode, { CompletionItem, CompletionItemKind, CompletionList } from 'vscode'; |
| 1 | +import vscode, { CompletionItem, CompletionItemKind, CompletionList, SnippetString } from 'vscode'; |
2 | 2 | import tilePosition from './position.json';
|
3 | 3 |
|
4 |
| -function provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): CompletionList<CompletionItem> | null { |
| 4 | +function provideCompletionItemsMarkdown(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): CompletionList<CompletionItem> | null { |
5 | 5 |
|
6 |
| - const text = document.getText(new vscode.Range(new vscode.Position(0, 0), position)); |
7 |
| - const lang = text.substring(text.lastIndexOf('```') + 3).split('\n')[0].replace('```', '').trim().toLowerCase(); |
8 |
| - if (lang.startsWith('rdview')) { |
9 |
| - const lineText = document.lineAt(position).text.substring(0, position.character).trim(); |
10 |
| - var list: CompletionList<CompletionItem> = new CompletionList; |
11 |
| - if (/(^|;\s*|\s*)(e[sbadrc]|g)?/g.test(lineText)) { |
12 |
| - list.items.push( |
13 |
| - { label: 'es', detail: 'Sound event.', insertText: `es.Empty 0 0;` }, |
14 |
| - { label: 'eb', detail: 'Row event.', insertText: `eb.Empty 0 0;` }, |
15 |
| - { label: 'ea', detail: 'Action event.', insertText: `ea.Empty 0 0;` }, |
16 |
| - { label: 'ed', detail: 'Decoration event.', insertText: `ed.Empty 0 0;` }, |
17 |
| - { label: 'er', detail: 'Room event.', insertText: `er.Empty 0 0;` }, |
18 |
| - { label: 'ec', detail: 'Custom event.', insertText: `ec.Empty 0 0;` }, |
19 |
| - { label: 'g', detail: 'Event group.', insertText: `g 0 0 1 1;` }); |
20 |
| - } |
21 |
| - if (/[\[,].$/.test(lineText)) { |
22 |
| - new Map<string,any>([ |
23 |
| - ['hue', 0], |
24 |
| - ['brightness', 100], |
25 |
| - ['grayscale', 0], |
26 |
| - ['offset', '0 0'], |
27 |
| - ['offset_hue', 0], |
28 |
| - ['offset_brightness', 100], |
29 |
| - ['offset_grayscale', 0], |
30 |
| - ['if', 'true'], |
31 |
| - ['tag', 'true'], |
32 |
| - ['tick', 1], |
33 |
| - ['swing', 0.5], |
34 |
| - ['hold', 1], |
35 |
| - ['pulse', 7], |
36 |
| - ['rowxs', '------'], |
37 |
| - ['type','skipshot'], |
38 |
| - ['interval',1], |
39 |
| - ['delay',1], |
40 |
| - ['subdivision',2], |
41 |
| - ]).forEach((i, j) => list.items.push({ label: j + `=${i},` })); |
42 |
| - } |
| 6 | + const text = document.getText(new vscode.Range(new vscode.Position(0, 0), position)); |
| 7 | + const lang = text.substring(text.lastIndexOf('```') + 3).split('\n')[0].replace('```', '').trim().toLowerCase(); |
| 8 | + if (!lang.startsWith('rdview')) { return null; } |
| 9 | + const lineText = document.lineAt(position).text.substring(0, position.character).trim(); |
| 10 | + return MatchCompletionItem(lineText); |
| 11 | +} |
| 12 | +function provideCompletionItemsRDView(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): CompletionList<CompletionItem> | null { |
| 13 | + const lineText = document.lineAt(position).text.substring(0, position.character).trim(); |
| 14 | + return MatchCompletionItem(lineText); |
| 15 | +} |
| 16 | +function MatchCompletionItem(lineText: string): CompletionList<CompletionItem> | null { |
| 17 | + var list: CompletionList<CompletionItem> = new CompletionList; |
| 18 | + if (/((^|;)\s*)e$/g.test(lineText)) { |
| 19 | + list.items.push( |
| 20 | + { label: 'es', insertText: new SnippetString('es.${1:Empty} ${2:0 0}[$3];'), kind: CompletionItemKind.Keyword, documentation: 'Sound event.', }, |
| 21 | + { label: 'eb', insertText: new SnippetString('eb.${1:Empty} ${2:0 0}[$3];'), kind: CompletionItemKind.Keyword, documentation: 'Row event.' }, |
| 22 | + { label: 'ea', insertText: new SnippetString('ea.${1:Empty} ${2:0 0}[$3];'), kind: CompletionItemKind.Keyword, documentation: 'Action event.' }, |
| 23 | + { label: 'ed', insertText: new SnippetString('ed.${1:Empty} ${2:0 0}[$3];'), kind: CompletionItemKind.Keyword, documentation: 'Decoration event.' }, |
| 24 | + { label: 'er', insertText: new SnippetString('er.${1:Empty} ${2:0 0}[$3];'), kind: CompletionItemKind.Keyword, documentation: 'Room event.' }, |
| 25 | + { label: 'ec', insertText: new SnippetString('ec.${1:Empty} ${2:0 0}[$3];'), kind: CompletionItemKind.Keyword, documentation: 'Custom event.' }); |
| 26 | + } |
| 27 | + if (/((^|;)\s*)g$/g.test(lineText)) { |
| 28 | + list.items.push( |
| 29 | + { label: 'g', insertText: new SnippetString('g ${1:0 0} ${2:1 1} #${3:f00}[$4]{\n\t$0\n};'), kind: CompletionItemKind.Keyword, documentation: 'Event group.' }); |
| 30 | + } |
| 31 | + if (/[\[,].$/.test(lineText)) { |
| 32 | + new Map<string, any>([ |
| 33 | + ['hue', 0], |
| 34 | + ['brightness', 100], |
| 35 | + ['grayscale', 0], |
| 36 | + ['offset', '0 0'], |
| 37 | + ['offset_hue', 0], |
| 38 | + ['offset_brightness', 100], |
| 39 | + ['offset_grayscale', 0], |
| 40 | + ['if', 'true'], |
| 41 | + ['tag', 'true'], |
| 42 | + ['tick', 1], |
| 43 | + ['swing', 0.5], |
| 44 | + ['hold', 1], |
| 45 | + ['pulse', 7], |
| 46 | + ['rowxs', '------'], |
| 47 | + ['type', 'skipshot'], |
| 48 | + ['interval', 1], |
| 49 | + ['delay', 1], |
| 50 | + ['subdivision', 2], |
| 51 | + ]).forEach((i, j) => list.items.push({ label: j, insertText: new SnippetString(`${j}=\$\{1:${i}\},`), kind: CompletionItemKind.Keyword, documentation: 'Event property.' })); |
| 52 | + } |
43 | 53 |
|
44 |
| - var collection; |
45 |
| - var isBeat = false; |
46 |
| - switch (true) { |
47 |
| - case /(^|;\s*|\s*)es\s*\.\s*\w*/g.test(lineText): |
48 |
| - collection = tilePosition.events.sounds; |
49 |
| - break; |
50 |
| - case /(^|;\s*|\s*)eb\s*\.\s*\w*/g.test(lineText): |
51 |
| - collection = tilePosition.events.rows; |
52 |
| - isBeat = true; |
53 |
| - break; |
54 |
| - case /(^|;\s*|\s*)ea\s*\.\s*\w*/g.test(lineText): |
55 |
| - collection = tilePosition.events.actions; |
56 |
| - break; |
57 |
| - case /(^|;\s*|\s*)ed\s*\.\s*\w*/g.test(lineText): |
58 |
| - collection = tilePosition.events.decorations; |
59 |
| - break; |
60 |
| - case /(^|;\s*|\s*)er\s*\.\s*\w*/g.test(lineText): |
61 |
| - collection = tilePosition.events.rooms; |
62 |
| - break; |
63 |
| - case /(^|;\s*|\s*)ec\s*\.\s*\w*/g.test(lineText): |
64 |
| - collection = tilePosition.events.custom; |
65 |
| - break; |
66 |
| - default: |
67 |
| - break; |
68 |
| - } |
69 |
| - if (collection) { |
70 |
| - collection.map((i) => { list.items.push({ label: i.name + ';' }); }); |
71 |
| - if (isBeat) { |
72 |
| - tilePosition.events.beatsSpecial.map(i => list.items.push({ label: i + ';' })); |
73 |
| - } |
74 |
| - } |
75 |
| - return list; |
76 |
| - } |
77 |
| - return null; |
| 54 | + var collection; |
| 55 | + var isBeat = false; |
| 56 | + switch (true) { |
| 57 | + case /es\.$/g.test(lineText): |
| 58 | + collection = tilePosition.events.sounds; |
| 59 | + break; |
| 60 | + case /eb\.$/g.test(lineText): |
| 61 | + collection = tilePosition.events.rows; |
| 62 | + isBeat = true; |
| 63 | + break; |
| 64 | + case /ea\.$/g.test(lineText): |
| 65 | + collection = tilePosition.events.actions; |
| 66 | + break; |
| 67 | + case /ed\.$/g.test(lineText): |
| 68 | + collection = tilePosition.events.decorations; |
| 69 | + break; |
| 70 | + case /er\.$/g.test(lineText): |
| 71 | + collection = tilePosition.events.rooms; |
| 72 | + break; |
| 73 | + case /ec\.$/g.test(lineText): |
| 74 | + collection = tilePosition.events.custom; |
| 75 | + break; |
| 76 | + default: |
| 77 | + break; |
| 78 | + } |
| 79 | + if (collection) { |
| 80 | + collection.map((i) => list.items.push({ label: i.name, insertText: new SnippetString(`${i.name} \$\{1:0 0}[$2];`), kind: CompletionItemKind.Text })); |
| 81 | + if (isBeat) { |
| 82 | + tilePosition.events.beatsSpecial.map(i => list.items.push({ label: i, insertText: new SnippetString(`${i} \$\{1:0 0\}[$2]];`), kind: CompletionItemKind.Text })); |
| 83 | + } |
| 84 | + } |
| 85 | + return list; |
78 | 86 | }
|
79 | 87 |
|
80 | 88 | function resolveCompletionItem(item: vscode.CompletionItem, token: vscode.CancellationToken) {
|
81 |
| - return null; |
| 89 | + return null; |
82 | 90 | }
|
83 | 91 |
|
84 | 92 | export function Init(context: vscode.ExtensionContext) {
|
85 |
| - context.subscriptions.push(vscode.languages.registerCompletionItemProvider('markdown', { |
86 |
| - provideCompletionItems, |
87 |
| - resolveCompletionItem |
88 |
| - }, '.')); |
| 93 | + context.subscriptions.push( |
| 94 | + vscode.languages.registerCompletionItemProvider('markdown', { |
| 95 | + provideCompletionItems: provideCompletionItemsMarkdown, |
| 96 | + resolveCompletionItem |
| 97 | + }, '.'), |
| 98 | + vscode.languages.registerCompletionItemProvider('rdview', { |
| 99 | + provideCompletionItems: provideCompletionItemsRDView, |
| 100 | + resolveCompletionItem |
| 101 | + }, '.') |
| 102 | + ); |
89 | 103 | };
|
0 commit comments