add def file support
This commit is contained in:
@@ -16,7 +16,7 @@ export function formatCdlFile(content: string): string {
|
||||
return formattedLines.join("\n")
|
||||
}
|
||||
|
||||
export function completionHandler(document: vscode.TextDocument, position: vscode.Position) {
|
||||
export function completionHandlerCdl(document: vscode.TextDocument, position: vscode.Position) {
|
||||
const linePrefix = document.lineAt(position).text.substring(0, position.character)
|
||||
const categories = ["MILL", "LATHE", "DRILL"]
|
||||
|
||||
@@ -31,6 +31,13 @@ export function completionHandler(document: vscode.TextDocument, position: vscod
|
||||
]
|
||||
}
|
||||
|
||||
if (linePrefix.endsWith("TOGGLE ")) {
|
||||
return [
|
||||
new vscode.CompletionItem("off", vscode.CompletionItemKind.TypeParameter),
|
||||
new vscode.CompletionItem("on", vscode.CompletionItemKind.TypeParameter)
|
||||
]
|
||||
}
|
||||
|
||||
if (linePrefix.endsWith("CATEGORY ")) {
|
||||
return categories.map(
|
||||
(cat) => new vscode.CompletionItem(cat, vscode.CompletionItemKind.TypeParameter)
|
||||
@@ -49,7 +56,7 @@ export function completionHandler(document: vscode.TextDocument, position: vscod
|
||||
return undefined
|
||||
}
|
||||
|
||||
export function hoverHandler(document: vscode.TextDocument, position: vscode.Position) {
|
||||
export function hoverCdlHandler(document: vscode.TextDocument, position: vscode.Position) {
|
||||
const wordRange = document.getWordRangeAtPosition(position)
|
||||
const word = document.getText(wordRange)
|
||||
const text = document.getText()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import * as vscode from "vscode"
|
||||
import { formatCdlFile, completionHandler, hoverHandler } from "./common/handlers"
|
||||
import { formatCdlFile, completionHandlerCdl, hoverCdlHandler } from "./common/handlers"
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
const formatProvider = vscode.languages.registerDocumentFormattingEditProvider(
|
||||
const formatCdlProvider = vscode.languages.registerDocumentFormattingEditProvider(
|
||||
{ scheme: "file", language: "cdl" },
|
||||
{
|
||||
provideDocumentFormattingEdits(document: vscode.TextDocument): vscode.TextEdit[] {
|
||||
@@ -17,9 +17,9 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
}
|
||||
)
|
||||
|
||||
context.subscriptions.push(formatProvider)
|
||||
context.subscriptions.push(formatCdlProvider)
|
||||
|
||||
const completionProvider = vscode.languages.registerCompletionItemProvider(
|
||||
const completionCdlProvider = vscode.languages.registerCompletionItemProvider(
|
||||
{ scheme: "file", language: "cdl" },
|
||||
{
|
||||
provideCompletionItems(
|
||||
@@ -28,14 +28,14 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
token: vscode.CancellationToken,
|
||||
context: vscode.CompletionContext
|
||||
) {
|
||||
return completionHandler(document, position)
|
||||
return completionHandlerCdl(document, position)
|
||||
}
|
||||
},
|
||||
" " // Trigger completion on space
|
||||
)
|
||||
context.subscriptions.push(completionProvider)
|
||||
context.subscriptions.push(completionCdlProvider)
|
||||
|
||||
const hoverProvider = vscode.languages.registerHoverProvider(
|
||||
const hoverCdlProvider = vscode.languages.registerHoverProvider(
|
||||
{ scheme: "file", language: "cdl" },
|
||||
{
|
||||
provideHover(
|
||||
@@ -43,11 +43,11 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
position: vscode.Position,
|
||||
token: vscode.CancellationToken
|
||||
) {
|
||||
return hoverHandler(document, position)
|
||||
return hoverCdlHandler(document, position)
|
||||
}
|
||||
}
|
||||
)
|
||||
context.subscriptions.push(hoverProvider)
|
||||
context.subscriptions.push(hoverCdlProvider)
|
||||
}
|
||||
|
||||
export function deactivate() {}
|
||||
|
||||
Reference in New Issue
Block a user