Merge pull request 'develop_def_syntax' (#4) from develop_def_syntax into main
/ build_and_publish (push) Successful in 23s
/ build_and_publish (push) Successful in 23s
Reviewed-on: Christoph/vscode-cdl#4
This commit was merged in pull request #4.
This commit is contained in:
@@ -2,3 +2,4 @@ node_modules
|
|||||||
out
|
out
|
||||||
dist
|
dist
|
||||||
*.vsix
|
*.vsix
|
||||||
|
target
|
||||||
@@ -12,10 +12,55 @@ export function formatCdlFile(content: string): string {
|
|||||||
if (strippedLine.endsWith("{")) {
|
if (strippedLine.endsWith("{")) {
|
||||||
indentLevel += 1
|
indentLevel += 1
|
||||||
}
|
}
|
||||||
|
if (strippedLine.startsWith("#")) {
|
||||||
|
formattedLines[formattedLines.length - 1] =
|
||||||
|
" ".repeat(indentLevel) + strippedLine.replace(/^#\s*/, "# ")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return formattedLines.join("\n")
|
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 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) {
|
export function completionHandlerCdl(document: vscode.TextDocument, position: vscode.Position) {
|
||||||
const linePrefix = document.lineAt(position).text.substring(0, position.character)
|
const linePrefix = document.lineAt(position).text.substring(0, position.character)
|
||||||
const categories = ["MILL", "LATHE", "DRILL"]
|
const categories = ["MILL", "LATHE", "DRILL"]
|
||||||
|
|||||||
+60
-3
@@ -1,5 +1,20 @@
|
|||||||
import * as vscode from "vscode"
|
import * as vscode from "vscode"
|
||||||
import { formatCdlFile, completionHandlerCdl, hoverCdlHandler } from "./common/handlers"
|
import {
|
||||||
|
LanguageClient,
|
||||||
|
LanguageClientOptions,
|
||||||
|
ServerOptions,
|
||||||
|
Executable
|
||||||
|
} from "vscode-languageclient/node"
|
||||||
|
import {
|
||||||
|
formatCdlFile,
|
||||||
|
completionHandlerCdl,
|
||||||
|
hoverCdlHandler,
|
||||||
|
formatDefFile,
|
||||||
|
isFirstLineMachine,
|
||||||
|
diagnosticHandler
|
||||||
|
} from "./common/handlers"
|
||||||
|
|
||||||
|
let client: LanguageClient
|
||||||
|
|
||||||
export function activate(context: vscode.ExtensionContext) {
|
export function activate(context: vscode.ExtensionContext) {
|
||||||
const formatCdlProvider = vscode.languages.registerDocumentFormattingEditProvider(
|
const formatCdlProvider = vscode.languages.registerDocumentFormattingEditProvider(
|
||||||
@@ -48,6 +63,48 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
context.subscriptions.push(hoverCdlProvider)
|
context.subscriptions.push(hoverCdlProvider)
|
||||||
}
|
|
||||||
|
|
||||||
export function deactivate() {}
|
const formatDefProvider = vscode.languages.registerDocumentFormattingEditProvider(
|
||||||
|
{ scheme: "file", language: "def" },
|
||||||
|
{
|
||||||
|
provideDocumentFormattingEdits(document: vscode.TextDocument): vscode.TextEdit[] {
|
||||||
|
const text = document.getText()
|
||||||
|
const formattedText = formatDefFile(text)
|
||||||
|
const fullRange = new vscode.Range(
|
||||||
|
document.positionAt(0),
|
||||||
|
document.positionAt(text.length)
|
||||||
|
)
|
||||||
|
return [vscode.TextEdit.replace(fullRange, formattedText)]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
context.subscriptions.push(formatDefProvider)
|
||||||
|
|
||||||
|
// Diagnostics collection
|
||||||
|
const diagnosticCollectionCdl = vscode.languages.createDiagnosticCollection("cdl")
|
||||||
|
const diagnosticCollectionDef = vscode.languages.createDiagnosticCollection("def")
|
||||||
|
context.subscriptions.push(diagnosticCollectionCdl, diagnosticCollectionDef)
|
||||||
|
|
||||||
|
// Check if the first line of the CDL file contains "MACHINE"
|
||||||
|
vscode.workspace.onDidOpenTextDocument((document) => {
|
||||||
|
if (document.languageId === "cdl" || document.languageId === "def") {
|
||||||
|
if (document.languageId === "cdl") {
|
||||||
|
diagnosticCollectionCdl.set(document.uri, diagnosticHandler(document))
|
||||||
|
} else if (document.languageId === "def") {
|
||||||
|
diagnosticCollectionDef.set(document.uri, diagnosticHandler(document))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
vscode.workspace.onDidChangeTextDocument((event) => {
|
||||||
|
const document = event.document
|
||||||
|
if (document.languageId === "cdl" || document.languageId === "def") {
|
||||||
|
if (document.languageId === "cdl") {
|
||||||
|
diagnosticCollectionCdl.set(document.uri, diagnosticHandler(document))
|
||||||
|
} else if (document.languageId === "def") {
|
||||||
|
diagnosticCollectionDef.set(document.uri, diagnosticHandler(document))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
+5
-5
@@ -1,4 +1,4 @@
|
|||||||
MACHINE DEFAULT
|
MACHINE
|
||||||
EVENT dummy_event_start
|
EVENT dummy_event_start
|
||||||
{
|
{
|
||||||
UI_LABEL "------------SAMSON UDES------------"
|
UI_LABEL "------------SAMSON UDES------------"
|
||||||
@@ -282,11 +282,11 @@ EVENT lib_event_cycle_60
|
|||||||
{
|
{
|
||||||
|
|
||||||
# <english>
|
# <english>
|
||||||
#Engraving - CYCLE60
|
# Engraving - CYCLE60
|
||||||
#CYCLE60(STRING[200] _TEXT, REAL _RTP, REAL _RFP, REAL _SDIS, REAL _DP, REAL _DPR, REAL _PA, REAL _PO, REAL _STA, REAL _CP1, REAL _CP2,REAL _WID, REAL _DF, REAL _FFD, REAL _FFP1, INT _VARI, INT _CODEP,INT _UMODE, INT _GMODE, INT _DMODE, INT _AMODE)
|
# CYCLE60(STRING[200] _TEXT, REAL _RTP, REAL _RFP, REAL _SDIS, REAL _DP, REAL _DPR, REAL _PA, REAL _PO, REAL _STA, REAL _CP1, REAL _CP2,REAL _WID, REAL _DF, REAL _FFD, REAL _FFP1, INT _VARI, INT _CODEP,INT _UMODE, INT _GMODE, INT _DMODE, INT _AMODE)
|
||||||
# <german>
|
# <german>
|
||||||
#Gravurzyklus - CYCLE60
|
# Gravurzyklus - CYCLE60
|
||||||
#CYCLE60(STRING[200] _TEXT, REAL _RTP, REAL _RFP, REAL _SDIS, REAL _DP, REAL _DPR, REAL _PA, REAL _PO, REAL _STA, REAL _CP1, REAL _CP2,REAL _WID, REAL _DF, REAL _FFD, REAL _FFP1, INT _VARI, INT _CODEP,INT _UMODE, INT _GMODE, INT _DMODE, INT _AMODE)
|
# CYCLE60(STRING[200] _TEXT, REAL _RTP, REAL _RFP, REAL _SDIS, REAL _DP, REAL _DPR, REAL _PA, REAL _PO, REAL _STA, REAL _CP1, REAL _CP2,REAL _WID, REAL _DF, REAL _FFD, REAL _FFP1, INT _VARI, INT _CODEP,INT _UMODE, INT _GMODE, INT _DMODE, INT _AMODE)
|
||||||
|
|
||||||
UI_LABEL "SAMSON: Gravieren (CYCLE60)"
|
UI_LABEL "SAMSON: Gravieren (CYCLE60)"
|
||||||
UI_HELP "Detailierte Zyklus Beschrieb" "file://${POST_LIB_CURRENT_BMP_DIR}/CYCL60_DE.pdf"
|
UI_HELP "Detailierte Zyklus Beschrieb" "file://${POST_LIB_CURRENT_BMP_DIR}/CYCL60_DE.pdf"
|
||||||
|
|||||||
Reference in New Issue
Block a user