Skip to content

Commit a1c081b

Browse files
committed
syntax highlight
1 parent d7802aa commit a1c081b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+707
-94
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
/.vscodeignore
44
/node_modules
55
/out
6-
/vsc-extension-quickstart.md
6+
/vsc-extension-quickstart.md
7+
*.vsix

LICENSE.md

+21

README.md

+3-3
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

package.json

+65-12
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"displayName": "Markdown RDView Support",
44
"description": "Make the Rhythm Doctor Editor event bar interface easily rendered on Markdown.",
55
"author": {
6-
"name": "obugs"
6+
"name": "obugs",
7+
"url": "https://github.com/OLDRedstone"
78
},
8-
"icon": "./rdview_icon.png",
9-
"version": "0.0.1",
9+
"icon": "rdview_icon.png",
10+
"version": "0.0.3",
1011
"publisher": "obugs",
1112
"private": true,
1213
"engines": {
@@ -21,7 +22,53 @@
2122
"contributes": {
2223
"markdown.markdownItPlugins": true,
2324
"markdown.previewStyles": [
24-
"./src/RDView.css"
25+
"./rdview.css"
26+
],
27+
"languages": [
28+
{
29+
"id": "rdview",
30+
"extensions": [
31+
".rdview",
32+
".rdv"
33+
]
34+
}
35+
],
36+
"grammars": [
37+
{
38+
"language": "rdview",
39+
"scopeName": "markdown.rdview.codeblock",
40+
"path": "./syntaxes/rdview.tmLanguage-markdown.json"
41+
},
42+
{
43+
"scopeName": "markdown.rdview.codeblock",
44+
"path": "./syntaxes/rdview.tmLanguage-markdown.json",
45+
"injectTo": ["text.html.markdown"],
46+
"embeddedLanguages": {
47+
"meta.embedded.block.rdview": "rdview"
48+
}
49+
},
50+
{
51+
"language": "rdview",
52+
"scopeName": "text.rdview",
53+
"path": "./syntaxes/rdview.tmLanguage.json"
54+
}
55+
],
56+
"configuration":[
57+
{
58+
"title": "RDView",
59+
"properties": {
60+
"markdown-rdview-support.reloadconfiguration": {
61+
"type": "boolean",
62+
"default": true,
63+
"description": "Resetting the Configuration at the Next VSCode Startup."
64+
},
65+
"markdown-rdview-support.removeconfiguration": {
66+
"type": "boolean",
67+
"default": false,
68+
"description": "Remove all configurations at the next VSCode startup."
69+
}
70+
}
71+
}
2572
]
2673
},
2774
"repository": {
@@ -40,19 +87,25 @@
4087
"lint": "eslint src",
4188
"test": "vscode-test"
4289
},
90+
"files": [
91+
"src",
92+
"assets",
93+
"rdview_icon.png",
94+
"rdview.css",
95+
"package.json",
96+
"README.md",
97+
"LICENSE",
98+
"syntaxes",
99+
"themes"
100+
],
43101
"devDependencies": {
44102
"@types/markdown-it": "^14.1.2",
45103
"@types/mocha": "^10.0.8",
46104
"@types/node": "20.x",
47105
"@types/vscode": "^1.94.0",
48106
"@typescript-eslint/eslint-plugin": "^8.7.0",
49-
"@typescript-eslint/parser": "^8.7.0",
50-
"@vscode/test-cli": "^0.0.10",
51-
"@vscode/test-electron": "^2.4.1",
52-
"eslint": "^9.11.1",
53-
"typescript": "^5.6.2"
54-
},
55-
"dependencies": {
56-
"markdown-it": "^14.1.0"
107+
"eslint": "^8.7.0",
108+
"typescript": "^4.5.4",
109+
"vscode-test": "^1.6.0"
57110
}
58111
}
File renamed without changes.

src/completion.ts

+92-78
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,103 @@
1-
import vscode, { CompletionItem, CompletionItemKind, CompletionList } from 'vscode';
1+
import vscode, { CompletionItem, CompletionItemKind, CompletionList, SnippetString } from 'vscode';
22
import tilePosition from './position.json';
33

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 {
55

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+
}
4353

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;
7886
}
7987

8088
function resolveCompletionItem(item: vscode.CompletionItem, token: vscode.CancellationToken) {
81-
return null;
89+
return null;
8290
}
8391

8492
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+
);
89103
};

0 commit comments

Comments
 (0)