fix:First line can comment #5
/ build_and_publish (push) Successful in 23s

This commit is contained in:
2025-01-25 00:19:55 +01:00
parent 189db33fc7
commit 1491aad2ea
6 changed files with 43 additions and 690 deletions
+14 -6
View File
@@ -37,14 +37,22 @@ export function formatDefFile(content: string): string {
}
export function isFirstLineMachine(content: string): boolean {
const firstLine = content.split("\n")[0].trim()
const machineRegex = /^MACHINE\s+\S+/
return machineRegex.test(firstLine)
const lines = content.split("\n").map((line) => line.trim())
for (const line of lines) {
console.log(line)
if (line === "" || line.startsWith("#")) {
console.log("skipping line")
continue
}
const machineRegex = /^MACHINE\s+\S+/
return machineRegex.test(line)
}
return false
}
export function diagnosticHandler(document: vscode.TextDocument) {
const diagnostics: vscode.Diagnostic[] = []
if (document.languageId === "cdl" || document.languageId === "def") {
const diagnostics: vscode.Diagnostic[] = []
if (!isFirstLineMachine(document.getText())) {
const range = new vscode.Range(
document.positionAt(0),
@@ -52,13 +60,13 @@ export function diagnosticHandler(document: vscode.TextDocument) {
)
const diagnostic = new vscode.Diagnostic(
range,
"The first line of the CDL file should contain 'MACHINE'.",
"The first line should contain 'MACHINE'.",
vscode.DiagnosticSeverity.Error
)
diagnostics.push(diagnostic)
}
return diagnostics
}
return diagnostics
}
export function completionHandlerCdl(document: vscode.TextDocument, position: vscode.Position) {