add vars and function for completion

This commit is contained in:
Christoph Brandau
2025-07-17 14:36:33 +02:00
parent d4e3f8f806
commit 9390ad4569
4 changed files with 351 additions and 9 deletions
+7 -1
View File
@@ -8,4 +8,10 @@ test
vite.config.js vite.config.js
.prettierrc.json .prettierrc.json
esbuild.js esbuild.js
.gitea .gitea
.venv/**
.nox/**
**/__pycache__/**
**/requirements.txt
**/requirements.in
**/server/src/_debug_server.py
+227 -5
View File
@@ -7,10 +7,232 @@
"elseif" "elseif"
], ],
"MOM_procs": [ "MOM_procs": [
"MOM_output_literal", {
"MOM_ask_ude_info", "label": "MOM_abort",
"MOM_suppress", "kind": "function",
"MOM_force", "description": "This function causes postprocessing to write an error message to the syslog and then terminate.",
"MOM_enable_address" "format": "MOM_abort <message>",
"parameters": [
{
"name": "message",
"desc": "Text string to be output when postprocessing is aborted."
}
],
"example": [
"MOM_abort \"Error occurred. Postprocessing has been aborted.\""
]
},
{
"label": "MOM_abort_event",
"kind": "function",
"description": "This command immediately aborts the current event and returns processing control back to NX. Use this command if you do not want to return to a calling procedure.",
"format": "MOM_abort_event <message>",
"parameters": [
{
"name": "message",
"desc": "Text string to be output when postprocessing is aborted."
}
],
"example": [
"MOM_abort_event \"Error occurred. Postprocessing has been aborted.\""
]
},
{
"label": "MOM_abort_operation",
"kind": "function",
"description": "This function causes post processing to terminate the current operation. Post processing will continue with MOM_end_of_path event.",
"format": "MOM_abort_operation",
"parameters": [
{
"name": "message",
"desc": "Text string to be output when postprocessing is aborted."
}
],
"example": [
"MOM_abort_operation"
]
},
{
"label": "MOM_abort_program",
"kind": "function",
"description": "This function causes post processing to terminate the current program group with an entry to the syslog file. Postprocessing will continue with the MOM_end_of_program event. The message is optional. This command is available with NX12.",
"format": "MOM_abort_program [<message>]",
"parameters": [
{
"name": "message",
"desc": "Text string to be output when postprocessing is aborted."
}
],
"example": [
"MOM_abort_program",
"MOM_abort_program \"Abort program group post processing.\""
]
},
{
"label": "MOM_add_to_address_buffer",
"kind": "function",
"description": "Depending on the <start|end> attribute specified, this extension will add <value(s)> to either the address start buffer or the address end buffer. Each time that this extension is called, it adds to the specified buffer. When the contents of the address are sent to the output buffer, the contents of the address start buffer will precede it and the contents of the end buffer will go after it. The address start buffer and the address end buffer are cleared once they have been sent to the output buffer.",
"format": "MOM_add_to_address_buffer <address_name> <start|end> <value>+",
"parameters": [
{
"name": "address_name",
"desc": "Name of address."
},
{
"name": "start|end",
"desc": "Position in address buffer to add content."
},
{
"name": "value",
"desc": "Content to be added to address buffer."
}
],
"example": [
"MOM_add_to_address_buffer X end [append end $list2 $list1]",
"MOM_add_to_address_buffer X start $prefix",
"MOM_add_to_address_buffer X start [MOM_do_template Seq_no CREATE]",
"MOM_add_to_address_buffer X start \"X\""
]
},
{
"label": "MOM_add_to_block_buffer",
"kind": "function",
"description": "Depending on the <start|end> attribute specified, this extension will add <value(s)> to either the block start buffer or the block end buffer. Each time that this extension is called, it adds to the specified buffer. When the block is sent to the output buffer, the contents of the block start buffer will precede it on the line and the contents of the block end buffer will go after it. The block start buffer and the block end buffer are cleared once they have been written to the output buffer.",
"format": "MOM_add_to_block_buffer <block_name> <start|end> <value>+",
"parameters": [
{
"name": "block_name",
"desc": "Name of block."
},
{
"name": "start|end",
"desc": "Position in block buffer to add content."
},
{
"name": "value",
"desc": "Content to be added to block buffer."
}
],
"example": [
"MOM_add_to_block_buffer From end [append end $list2 $list1]",
"MOM_add_to_block_buffer From start $prefix",
"MOM_add_to_block_buffer Linear start [MOM_do_template Seq_no CREATE]",
"MOM_add_to_block _buffer From start \"Remark\""
]
},
{
"label": "MOM_add_to_block_buffer",
"kind": "function",
"description": "Depending on the <start|end> attribute specified, this extension will add <value(s)> to either the line's start buffer or the line's end buffer. Each time that this extension is called, it adds to the specified buffer. When the contents of the output buffer are sent to the output file, the contents of the line's start buffer will precede it on the line and the contents of the end buffer will go on the same line after it. The line start buffer, line end buffer, and output buffer are all cleared once they have been written to the output file.",
"format": "MOM_add_to_line_buffer <start|end> <value>+",
"parameters": [
{
"name": "start|end",
"desc": "Position in line buffer to add content."
},
{
"name": "value",
"desc": "Content to be added to line buffer."
}
],
"example": [
"MOM_add_to_line_buffer start [MOM_do_template Linear CREATE]",
"MOM_add_to_line_buffer start [append start $list1 $list2]",
"MOM_add_to_line_buffer start $prefix",
"MOM_add_to_line_buffer start \"****\""
]
},
{
"label": "MOM_ask_address_value",
"kind": "function",
"description": "Always returns the absolute address value NOT the incremental value.",
"format": "MOM_ask_address_value <address_name>",
"parameters": [
{
"name": "address_name",
"desc": "Text string of the output address."
}
],
"example": [
"MOM_ask_address_value X"
]
},
{
"label": "MOM_ask_cutter_info",
"kind": "function",
"description": "Retrieves tool information at the start of a program and stores the results in the array variable mom_cutter_info. Called from Post Configurator procedure MOM_start_of_path_LIB.",
"format": "MOM_ask_cutter_info <cutter_list>",
"parameters": [
{
"name": "cutter_list",
"desc": "List of tool names."
}
],
"example": [
"set cutter_list \"UGTI0202_030 UGTI0202_025 UGTI0201_062\"\nMOM_ask_cutter_info cutter_list"
]
},
{
"label": "MOM_ask_ude_info",
"kind": "function",
"description": "This command is used to retrieve the information about a user-defined event (UDE) of a specified object.",
"format": "MOM_ask_ude_info object_name object_type <Start/End/\"\">",
"parameters": [
{
"name": "Object_name",
"desc": "The name of the object to which the UDE is attached. It can be a group, an operation, a tool, a geometry, or a method."
},
{
"name": "object_type",
"desc": "The type of the object to which the UDE is attached. The following types are available.(group || operation/oper || tool || geometry/geom || method/meth)"
},
{
"name": "Start/End/\"\"",
"desc": "This parameter is optional. Indicates whether you want to retrieve the UDE attached to the start event, end event, or both. If it is empty, returns the UDEs attached to the specified operation."
}
],
"returns": [
"0 - The UDE information retrieval failed.",
"1 - The UDE information successfully retrieved."
],
"example": []
}
],
"mom_variables": [
{
"label": "mom_alt_pos",
"kind": "variable",
"description": "The alternate machine tool coordinates (X,Y,Z,fourth axis,fifth axis) for the current GOTO. This value is different from mom_pos if the kinematics of the machine tool is five axis. Otherwise, mom_alt_pos will be the same as mom_pos. For five axis machine tools, there are always at least two valid solutions when converting the input coordinates (X,Y,Z,I,J,K) into machine tool coordinates (X,Y,Z,A,B). The optimal solution will be mom_pos, the alternate solution will be mom_alt_pos.",
"possible_values": "Real numbers.",
"data_type": "Numeric Array(5)"
},
{
"label": "mom_arc_angle",
"kind": "variable",
"description": "The total number of degrees for the current arc.",
"possible_values": "0.0 to 360.0",
"data_type": "Numeric Value"
},
{
"label": "mom_arc_axis",
"kind": "variable",
"description": "The circle axis vector.",
"possible_values": "Unit vector.",
"data_type": "Numeric Array(3)"
},
{
"label": "mom_arc_center",
"kind": "variable",
"description": "The center of the circle.",
"possible_values": "Real numbers.",
"data_type": "Numeric Array(3)"
},
{
"label": "mom_arc_direction",
"kind": "variable",
"description": "The direction of the circle.",
"possible_values": "CLW or CCLW",
"data_type": "String"
}
] ]
} }
+112 -2
View File
@@ -3,15 +3,36 @@ import lsprotocol.types as lsp
import pathlib import pathlib
KIND_MAP = {
"function": lsp.CompletionItemKind.Function,
"method": lsp.CompletionItemKind.Method,
"class": lsp.CompletionItemKind.Class,
"variable": lsp.CompletionItemKind.Variable,
"field": lsp.CompletionItemKind.Field,
"module": lsp.CompletionItemKind.Module,
"namespace": lsp.CompletionItemKind.Class,
}
class StandardCompletionItems: class StandardCompletionItems:
def __init__(self): def __init__(self):
self.__tcl_keyword_list = self.load_tcl_keyword() self.__tcl_keyword_list = self.__load_tcl_keyword()
self.__nx_procs = self.__load_nx_procs()
self.__nx_variables = self.__load_nx_variables()
@property @property
def tcl_keyword_list(self): def tcl_keyword_list(self):
return self.__tcl_keyword_list return self.__tcl_keyword_list
def load_tcl_keyword(self) -> list[lsp.CompletionItem]: @property
def nx_procs(self):
return self.__nx_procs
@property
def nx_variables(self):
return self.__nx_variables
def __load_tcl_keyword(self) -> list[lsp.CompletionItem]:
with open( with open(
pathlib.Path(__file__).parent.joinpath("completion_list.json"), "r" pathlib.Path(__file__).parent.joinpath("completion_list.json"), "r"
) as f: ) as f:
@@ -24,5 +45,94 @@ class StandardCompletionItems:
) )
return items return items
def __load_nx_variables(self):
with open(
pathlib.Path(__file__).parent.joinpath("completion_list.json"), "r"
) as f:
data = json.load(f)
items = []
for var in data.get("mom_variables", []):
label = var.get("label", "")
kind_str = var.get("kind", "").lower()
kind_enum = KIND_MAP.get(kind_str, lsp.CompletionItemKind.Text)
doc_md = f"""\
**MOM variable**
{label}
**Description**
{var.get("description", "")}
**Possible Values:**
{var.get("possible_values", "any")}
**Data type**
{var.get("data_type", "")}
"""
items.append(
lsp.CompletionItem(
label=label,
kind=kind_enum,
detail=f"{label}",
documentation=lsp.MarkupContent(
kind=lsp.MarkupKind.Markdown, value=doc_md
),
)
)
return items
def __load_nx_procs(self) -> list[lsp.CompletionItem]:
with open(
pathlib.Path(__file__).parent.joinpath("completion_list.json"), "r"
) as f:
data = json.load(f)
items = []
for proc in data.get("MOM_procs", []):
label = proc.get("label", "")
kind_str = proc.get("kind", "").lower()
kind_enum = KIND_MAP.get(kind_str, lsp.CompletionItemKind.Text)
parameters = proc.get("parameters", [])
param_lines = (
"\n".join(f"- `{p['name']}`: {p['desc']}" for p in parameters)
or "_None_"
)
example_data = proc.get("example", [])
example_md = "\n".join(f"{line}" for line in example_data)
returns_data = proc.get("returns", ["None"])
returns_md = "\n".join(f"- {line}" for line in returns_data)
doc_md = f"""\
### 📘 {label}
**Purpose**
{proc.get("description", "No description available.")}
**Format**
`{proc.get("format", label)}`
**Parameters**
{param_lines}
**Return value**
{returns_md}
**Example**
```tcl
{example_md}"""
items.append(
lsp.CompletionItem(
label=label,
kind=kind_enum,
detail=f"{label} {proc.get('description', '').split('.')[0]}",
documentation=lsp.MarkupContent(
kind=lsp.MarkupKind.Markdown, value=doc_md
),
)
)
return items
standard_items = StandardCompletionItems() standard_items = StandardCompletionItems()
+5 -1
View File
@@ -96,7 +96,11 @@ def did_change(params: lsp.DidChangeTextDocumentParams) -> None:
@LSP_SERVER.feature(lsp.TEXT_DOCUMENT_COMPLETION) @LSP_SERVER.feature(lsp.TEXT_DOCUMENT_COMPLETION)
def on_completion(params: lsp.CompletionParams) -> list[lsp.CompletionItem]: def on_completion(params: lsp.CompletionParams) -> list[lsp.CompletionItem]:
items = standard_items.tcl_keyword_list items = (
standard_items.tcl_keyword_list
+ standard_items.nx_procs
+ standard_items.nx_variables
)
return lsp.CompletionList(is_incomplete=False, items=items) return lsp.CompletionList(is_incomplete=False, items=items)