bmc-tpl-code-all-around/src/providers/completions/BuiltInCompletion.ts

35 lines
1.7 KiB
TypeScript
Raw Normal View History

import * as vscode from 'vscode';
import { CompletionStrategy } from './CompletionStrategy';
export class BuiltInCompletion implements CompletionStrategy {
public provideCompletions(document: vscode.TextDocument, position: vscode.Position, linePrefix: string): vscode.CompletionItem[] | undefined {
const items: vscode.CompletionItem[] = [];
// Prüft, ob wir im Namespace "log." oder "discovery." sind (auch wenn man danach weiter tippt!)
const match = linePrefix.match(/\b(discovery|log|model|text|regex|time|xpath|json|hash|inference)\.([a-zA-Z0-9_]*)$/);
if (match) {
const namespace = match[1];
if (namespace === 'log') {
const levels = ['debug', 'info', 'warn', 'error'];
for (const level of levels) {
const item = new vscode.CompletionItem(level, vscode.CompletionItemKind.Method);
item.insertText = new vscode.SnippetString(`${level}("\${1:message}");`);
item.documentation = new vscode.MarkdownString(`Schreibt eine Log-Meldung auf dem Level **${level}**.`);
items.push(item);
}
}
else if (namespace === 'discovery') {
const runCmd = new vscode.CompletionItem('runCommand', vscode.CompletionItemKind.Method);
runCmd.insertText = new vscode.SnippetString('runCommand(${1:host}, "${2:command}");');
runCmd.detail = "discovery.runCommand(host, command)";
items.push(runCmd);
}
return items; // Treffer gefunden, wir geben sie zurück!
}
return undefined;
}
}