Visual Studio Code, rebuilt in Rust
Rust
const vscode = require('vscode');
const { completions, hover } = require('./lib');
exports.activate = context => {
context.subscriptions.push(
vscode.languages.registerCompletionItemProvider('apacheconf', {
provideCompletionItems(document, position) {
const found = completions(document.lineAt(position).text.slice(0, position.character));
if (!found) {
return undefined;
}
const range = new vscode.Range(position.translate(0, -found.word.length), position);
return found.items.map(({ label, snippet, detail, documentation }) => {
const item = new vscode.CompletionItem(label, vscode.CompletionItemKind.Keyword);
item.insertText = new vscode.SnippetString(snippet);
item.range = range;
item.detail = detail;
item.documentation = new vscode.MarkdownString(documentation);
return item;
});
},
}, '<', '/'),
vscode.languages.registerHoverProvider('apacheconf', {
provideHover(document, position) {
const range = document.getWordRangeAtPosition(position, /[A-Za-z0-9_]+/);
const markdown = range && hover(document.lineAt(position).text, range.start.character, range.end.character);
return markdown && new vscode.Hover(new vscode.MarkdownString(markdown), range);
},
}),
);
};