-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIDE Integration with Injector Functions.js
155 lines (132 loc) · 7.04 KB
/
IDE Integration with Injector Functions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Example: Bleeding-Edge VS Code Extension for WordMaze Language
const vscode = require('vscode');
function activate(context) {
// Register a hover provider for 'WordMaze'
const hoverProvider = vscode.languages.registerHoverProvider('wordmaze', {
provideHover(document, position, token) {
const range = document.getWordRangeAtPosition(position);
const word = document.getText(range);
// Add advanced hover information with markdown support
const markdownString = new vscode.MarkdownString();
markdownString.appendMarkdown(`**Hovering over:** \`${word}\`\n\n`);
markdownString.appendMarkdown(`*Language:* \`WordMaze\`\n`);
markdownString.appendMarkdown(`*Position:* \`${position.line}:${position.character}\`\n\n`);
markdownString.appendMarkdown(`[Click here for more info](https://example.com)`);
return new vscode.Hover(markdownString);
}
});
// Register a completion item provider for 'WordMaze'
const completionItemProvider = vscode.languages.registerCompletionItemProvider('wordmaze', {
provideCompletionItems(document, position, token, context) {
const line = document.lineAt(position);
const prefix = line.text.substr(0, position.character).split(/\s+/).pop();
// Sample completion item
const completionItem = new vscode.CompletionItem('sampleCompletion', vscode.CompletionItemKind.Text);
completionItem.documentation = new vscode.MarkdownString('This is a sample completion item for `WordMaze`.');
// Add more completion items
const completionItems = [
new vscode.CompletionItem('anotherCompletion', vscode.CompletionItemKind.Keyword),
new vscode.CompletionItem('yetAnotherCompletion', vscode.CompletionItemKind.Method)
];
return [completionItem, ...completionItems];
},
resolveCompletionItem(item, token) {
// Provide additional details for a completion item
item.detail = `Details for ${item.label}`;
item.documentation = new vscode.MarkdownString(`Documentation for ${item.label}`);
return item;
}
}, '.', ':'); // Trigger completion on '.' and ':'
// Register a code action provider for 'WordMaze'
const codeActionProvider = vscode.languages.registerCodeActionsProvider('wordmaze', {
provideCodeActions(document, range, context, token) {
const codeAction = new vscode.CodeAction('Sample Code Action', vscode.CodeActionKind.QuickFix);
codeAction.command = { command: 'wordmazeExtension.sampleCommand', title: 'Run Sample Command' };
return [codeAction];
}
});
// Register a command
const sampleCommand = vscode.commands.registerCommand('wordmazeExtension.sampleCommand', () => {
vscode.window.showInformationMessage('Sample Command Executed');
});
// Register a syntax highlighter for 'WordMaze'
const tokenTypes = new vscode.SemanticTokensLegend(['keyword', 'variable', 'function']);
const semanticTokensProvider = vscode.languages.registerDocumentSemanticTokensProvider('wordmaze', {
provideDocumentSemanticTokens(document, token) {
const builder = new vscode.SemanticTokensBuilder(tokenTypes);
const text = document.getText();
const keywords = ['if', 'else', 'for', 'while']; // Example keywords for WordMaze
text.split(/\s+/).forEach((word, index) => {
if (keywords.includes(word)) {
builder.push(new vscode.Range(new vscode.Position(0, index), new vscode.Position(0, index + word.length)), 'keyword');
}
});
return builder.build();
}
}, tokenTypes);
// Register a document symbol provider for 'WordMaze'
const documentSymbolProvider = vscode.languages.registerDocumentSymbolProvider('wordmaze', {
provideDocumentSymbols(document, token) {
const symbols = [];
// Example: Extract symbols from the document
const regex = /(?:function|method)\s+(\w+)\s*\(/g;
let match;
while ((match = regex.exec(document.getText()))) {
const symbolName = match[1];
const symbolRange = document.getWordRangeAtPosition(document.positionAt(match.index));
const symbolKind = vscode.SymbolKind.Function; // Adjust symbol kind as needed
symbols.push(new vscode.DocumentSymbol(symbolName, '', symbolKind, symbolRange, symbolRange));
}
return symbols;
}
});
// Register a code lens provider for 'WordMaze'
const codeLensProvider = vscode.languages.registerCodeLensProvider('wordmaze', {
provideCodeLenses(document, token) {
const codeLenses = [];
// Example: Add code lenses for each function/method
const regex = /(?:function|method)\s+(\w+)\s*\(/g;
let match;
while ((match = regex.exec(document.getText()))) {
const functionName = match[1];
const startPosition = document.positionAt(match.index);
const endPosition = document.positionAt(match.index + match[0].length);
const range = new vscode.Range(startPosition, endPosition);
codeLenses.push(new vscode.CodeLens(range));
}
return codeLenses;
},
resolveCodeLens(codeLens, token) {
// Example: Resolve additional information for a code lens
codeLens.command = {
title: 'Run Test',
command: 'wordmazeExtension.runTest',
arguments: [codeLens.range.start]
};
return codeLens;
}
});
// Register a code formatter for 'WordMaze'
const documentFormattingEditProvider = vscode.languages.registerDocumentFormattingEditProvider('wordmaze', {
provideDocumentFormattingEdits(document, options, token) {
const textEdits = [];
// Example: Format the entire document
const firstLine = document.lineAt(0);
const lastLine = document.lineAt(document.lineCount - 1);
const range = new vscode.Range(firstLine.range.start, lastLine.range.end);
const formattedText = document.getText(range).toUpperCase(); // Example: Convert to uppercase
textEdits.push(vscode.TextEdit.replace(range, formattedText));
return textEdits;
}
});
// Push all providers and commands to the context's subscriptions
context.subscriptions.push(hoverProvider);
context.subscriptions.push(completionItemProvider);
context.subscriptions.push(codeActionProvider);
context.subscriptions.push(sampleCommand);
context.subscriptions.push(semanticTokensProvider);
context.subscriptions.push(documentSymbolProvider);
context.subscriptions.push(codeLensProvider);
context.subscriptions.push(documentFormattingEditProvider);
}
exports.activate = activate;