add autocomp
This commit is contained in:
+5
-1
@@ -1,3 +1,7 @@
|
||||
## [1.0.0]
|
||||
## [0.0.1]
|
||||
|
||||
- Initial release
|
||||
|
||||
## [0.0.2]
|
||||
|
||||
- Add Autocomp for TYPE
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import * as vscode from "vscode";
|
||||
|
||||
export function formatCdlFile(content: string): string {
|
||||
let indentLevel = 0;
|
||||
const formattedLines = [];
|
||||
@@ -13,3 +15,22 @@ export function formatCdlFile(content: string): string {
|
||||
}
|
||||
return formattedLines.join("\n");
|
||||
}
|
||||
|
||||
export function completionHandler(
|
||||
document: vscode.TextDocument,
|
||||
position: vscode.Position
|
||||
) {
|
||||
const linePrefix = document
|
||||
.lineAt(position)
|
||||
.text.substr(0, position.character);
|
||||
if (!linePrefix.endsWith("TYPE ")) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return [
|
||||
new vscode.CompletionItem("o", vscode.CompletionItemKind.Keyword),
|
||||
new vscode.CompletionItem("b", vscode.CompletionItemKind.Keyword),
|
||||
new vscode.CompletionItem("i", vscode.CompletionItemKind.Keyword),
|
||||
new vscode.CompletionItem("d", vscode.CompletionItemKind.Keyword),
|
||||
];
|
||||
}
|
||||
|
||||
+17
-1
@@ -1,5 +1,5 @@
|
||||
import * as vscode from "vscode";
|
||||
import { formatCdlFile } from "./common/handlers";
|
||||
import { formatCdlFile, completionHandler } from "./common/handlers";
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
const disposable = vscode.languages.registerDocumentFormattingEditProvider(
|
||||
@@ -20,6 +20,22 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
);
|
||||
|
||||
context.subscriptions.push(disposable);
|
||||
|
||||
const completionProvider = vscode.languages.registerCompletionItemProvider(
|
||||
{ scheme: "file", language: "cdl" },
|
||||
{
|
||||
provideCompletionItems(
|
||||
document: vscode.TextDocument,
|
||||
position: vscode.Position,
|
||||
token: vscode.CancellationToken,
|
||||
context: vscode.CompletionContext
|
||||
) {
|
||||
return completionHandler(document, position);
|
||||
},
|
||||
},
|
||||
" " // Trigger completion on space
|
||||
);
|
||||
context.subscriptions.push(completionProvider);
|
||||
}
|
||||
|
||||
export function deactivate() {}
|
||||
|
||||
Reference in New Issue
Block a user