update cdl/def diagnostic
This commit is contained in:
@@ -2,3 +2,4 @@ node_modules
|
|||||||
out
|
out
|
||||||
dist
|
dist
|
||||||
*.vsix
|
*.vsix
|
||||||
|
target
|
||||||
@@ -35,6 +35,32 @@ export function formatDefFile(content: string): string {
|
|||||||
}
|
}
|
||||||
return formattedLines.join("\n")
|
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"]
|
||||||
|
|||||||
+38
-3
@@ -1,11 +1,21 @@
|
|||||||
import * as vscode from "vscode"
|
import * as vscode from "vscode"
|
||||||
|
import {
|
||||||
|
LanguageClient,
|
||||||
|
LanguageClientOptions,
|
||||||
|
ServerOptions,
|
||||||
|
Executable
|
||||||
|
} from "vscode-languageclient/node"
|
||||||
import {
|
import {
|
||||||
formatCdlFile,
|
formatCdlFile,
|
||||||
completionHandlerCdl,
|
completionHandlerCdl,
|
||||||
hoverCdlHandler,
|
hoverCdlHandler,
|
||||||
formatDefFile
|
formatDefFile,
|
||||||
|
isFirstLineMachine,
|
||||||
|
diagnosticHandler
|
||||||
} from "./common/handlers"
|
} 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(
|
||||||
{ scheme: "file", language: "cdl" },
|
{ scheme: "file", language: "cdl" },
|
||||||
@@ -70,6 +80,31 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
context.subscriptions.push(formatDefProvider)
|
context.subscriptions.push(formatDefProvider)
|
||||||
}
|
|
||||||
|
|
||||||
export function deactivate() {}
|
// 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