update cdl/def diagnostic
This commit is contained in:
@@ -35,6 +35,32 @@ export function formatDefFile(content: string): string {
|
||||
}
|
||||
return formattedLines.join("\n")
|
||||
}
|
||||
|
||||
export function isFirstLineMachine(content: string): boolean {
|
||||
const firstLine = content.split("\n")[0].trim()
|
||||
const machineRegex = /^MACHINE\s+\S+/
|
||||
return machineRegex.test(firstLine)
|
||||
}
|
||||
|
||||
export function diagnosticHandler(document: vscode.TextDocument) {
|
||||
if (document.languageId === "cdl" || document.languageId === "def") {
|
||||
const diagnostics: vscode.Diagnostic[] = []
|
||||
if (!isFirstLineMachine(document.getText())) {
|
||||
const range = new vscode.Range(
|
||||
document.positionAt(0),
|
||||
document.positionAt(document.getText().length)
|
||||
)
|
||||
const diagnostic = new vscode.Diagnostic(
|
||||
range,
|
||||
"The first line of the CDL file should contain 'MACHINE'.",
|
||||
vscode.DiagnosticSeverity.Error
|
||||
)
|
||||
diagnostics.push(diagnostic)
|
||||
}
|
||||
return diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
export function completionHandlerCdl(document: vscode.TextDocument, position: vscode.Position) {
|
||||
const linePrefix = document.lineAt(position).text.substring(0, position.character)
|
||||
const categories = ["MILL", "LATHE", "DRILL"]
|
||||
|
||||
Reference in New Issue
Block a user