handle def file formatter

This commit is contained in:
Christoph Brandau
2025-01-10 07:44:48 +01:00
parent 3614f0cefb
commit 11af66a267
2 changed files with 42 additions and 1 deletions
+19
View File
@@ -12,10 +12,29 @@ export function formatCdlFile(content: string): string {
if (strippedLine.endsWith("{")) {
indentLevel += 1
}
if (strippedLine.startsWith("#")) {
formattedLines[formattedLines.length - 1] =
" ".repeat(indentLevel) + strippedLine.replace(/^#\s*/, "# ")
}
}
return formattedLines.join("\n")
}
export function formatDefFile(content: string): string {
let indentLevel = 0
const formattedLines = []
for (const line of content.split("\n")) {
const strippedLine = line.trim()
if (strippedLine.endsWith("}")) {
indentLevel = Math.max(indentLevel - 1, 0)
}
formattedLines.push(" ".repeat(indentLevel) + strippedLine)
if (strippedLine.endsWith("{")) {
indentLevel += 1
}
}
return formattedLines.join("\n")
}
export function completionHandlerCdl(document: vscode.TextDocument, position: vscode.Position) {
const linePrefix = document.lineAt(position).text.substring(0, position.character)
const categories = ["MILL", "LATHE", "DRILL"]