Add FORMAT/address completions and format/block previews for .def files #68

Merged
Christoph merged 9 commits from def_nav into main 2026-10-13 06:28:22 +00:00
Owner

This change adds editor support for DEF-format previews and context-aware completions in .def files and integrates them into the LSP server and client.

Summary

  • Completion of FORMAT names after FORMAT/ZERO_FORMAT inside an ADDRESS, showing the format specification and an example output preview. After ZERO_FORMAT, names containing zero are ranked first.
  • Completion of ADDRESS names at the start of a line inside a BLOCK_TEMPLATE, inserting a new element as N[] with the cursor between brackets (or replacing only the name when an element with brackets already exists). The completion details show format and output preview.
  • Hovering a format name (in a FORMAT declaration or after FORMAT/ZERO_FORMAT in an address) shows the specification, a description, and example values formatted as the address would output them (including known leader/trailer). Supports NX-style specifications (eg. &__5.3_) and printf-style formats (eg. %s, %d).
  • Address hover rows for FORMAT and ZERO_FORMAT include an output preview (e.g. Coordinate → "&__4.3_" previews SPOS=1.5).
  • Hovering a BLOCK_TEMPLATE (in .def or referenced from Tcl) previews the whole NC block (literal values formatted as NX, variable-derived values shown as …), and lists all its addresses, expressions, formats, and preview outputs.
  • Updates to the README and CHANGELOG documenting the new DEF editing support and behavior.

Key implementation notes (evidence from diff)

  • Client: a completion provider for DEF_SELECTOR was registered to call the new LSP endpoint nxPostSupport/def/completion (file: client/src/common/defProviders.ts).
  • Server LSP: new request constant DEF_REQUEST_COMPLETION and handler def_completion added. def_hover now first tries a format-specific hover before falling back to existing behavior (file: server/src/lsp_server.py).
  • New format utilities: server/src/tools/def_format.py added. It parses NX and printf-style format specifications, produces example values, and renders markdown tables of example inputs → outputs.
  • Navigation/preview/completion logic: server/src/tools/def_navigation.py extended to produce format and address completions, compute previews (leader/trailer handling and sample formatting), and include format previews in address/property tables.
  • Grammar/token tweak: package.json adds a tokenTypes mapping for string.unquoted.def to other so bare words in .def are not treated as strings by VS Code (this prevents suppression of quick suggestions while typing).
  • Docs: README and CHANGELOG updated to document editing features and the preview behavior.

Tests

  • Test files were added/updated according to commit summaries (navigation tests updated for format previews and completions; tests added for FORMAT preview). No test execution results were provided.

Recommended checks for reviewers / QA

  1. Manual editor checks in VS Code with the extension built/loaded:

    • Inside a .def file, type after FORMAT/ZERO_FORMAT in an ADDRESS and verify completion suggestions include format spec and preview, and that Zero*-like formats rank higher after ZERO_FORMAT.
    • In a BLOCK_TEMPLATE body, start a new line and confirm address completions insert N[] with cursor inside the brackets; if the element already has brackets, confirm only the name is replaced.
    • Hover a format declaration and a format use (after FORMAT/ZERO_FORMAT) to confirm markdown shows specification, description, and example outputs including leader/trailer.
    • Hover a block template (in .def and from a Tcl MOM_do_template call) and confirm the NC block preview and the per-address table appear with formatted outputs or … for variables.
    • Verify quick suggestions are not suppressed while typing bare words in .def files (the tokenTypes change).
  2. Run the repository test suite (unit/integration tests) to confirm updated/added tests pass locally.

Compatibility / Risk notes

  • The package.json grammar token type mapping changes how unquoted words are tokenized by VS Code; this is intentional to allow quick suggestions while typing in .def files.
  • The new completion endpoint is additive and should not change existing LSP behavior except that format-specific hover now takes precedence when applicable.

No test execution results were provided.

This change adds editor support for DEF-format previews and context-aware completions in .def files and integrates them into the LSP server and client. Summary - Completion of FORMAT names after `FORMAT`/`ZERO_FORMAT` inside an `ADDRESS`, showing the format specification and an example output preview. After `ZERO_FORMAT`, names containing `zero` are ranked first. - Completion of ADDRESS names at the start of a line inside a `BLOCK_TEMPLATE`, inserting a new element as `N[]` with the cursor between brackets (or replacing only the name when an element with brackets already exists). The completion details show format and output preview. - Hovering a format name (in a `FORMAT` declaration or after `FORMAT`/`ZERO_FORMAT` in an address) shows the specification, a description, and example values formatted as the address would output them (including known leader/trailer). Supports NX-style specifications (eg. `&__5.3_`) and printf-style formats (eg. `%s`, `%d`). - Address hover rows for `FORMAT` and `ZERO_FORMAT` include an output preview (e.g. `Coordinate → "&__4.3_"` previews `SPOS=1.5`). - Hovering a `BLOCK_TEMPLATE` (in .def or referenced from Tcl) previews the whole NC block (literal values formatted as NX, variable-derived values shown as `…`), and lists all its addresses, expressions, formats, and preview outputs. - Updates to the README and CHANGELOG documenting the new DEF editing support and behavior. Key implementation notes (evidence from diff) - Client: a completion provider for `DEF_SELECTOR` was registered to call the new LSP endpoint `nxPostSupport/def/completion` (file: `client/src/common/defProviders.ts`). - Server LSP: new request constant `DEF_REQUEST_COMPLETION` and handler `def_completion` added. `def_hover` now first tries a format-specific hover before falling back to existing behavior (file: `server/src/lsp_server.py`). - New format utilities: `server/src/tools/def_format.py` added. It parses NX and printf-style format specifications, produces example values, and renders markdown tables of example inputs → outputs. - Navigation/preview/completion logic: `server/src/tools/def_navigation.py` extended to produce format and address completions, compute previews (leader/trailer handling and sample formatting), and include format previews in address/property tables. - Grammar/token tweak: `package.json` adds a `tokenTypes` mapping for `string.unquoted.def` to `other` so bare words in .def are not treated as strings by VS Code (this prevents suppression of quick suggestions while typing). - Docs: README and CHANGELOG updated to document editing features and the preview behavior. Tests - Test files were added/updated according to commit summaries (navigation tests updated for format previews and completions; tests added for FORMAT preview). No test execution results were provided. Recommended checks for reviewers / QA 1. Manual editor checks in VS Code with the extension built/loaded: - Inside a `.def` file, type after `FORMAT`/`ZERO_FORMAT` in an `ADDRESS` and verify completion suggestions include format spec and preview, and that `Zero*`-like formats rank higher after `ZERO_FORMAT`. - In a `BLOCK_TEMPLATE` body, start a new line and confirm address completions insert `N[]` with cursor inside the brackets; if the element already has brackets, confirm only the name is replaced. - Hover a format declaration and a format use (after `FORMAT`/`ZERO_FORMAT`) to confirm markdown shows specification, description, and example outputs including leader/trailer. - Hover a block template (in .def and from a Tcl `MOM_do_template` call) and confirm the NC block preview and the per-address table appear with formatted outputs or `…` for variables. - Verify quick suggestions are not suppressed while typing bare words in .def files (the `tokenTypes` change). 2. Run the repository test suite (unit/integration tests) to confirm updated/added tests pass locally. Compatibility / Risk notes - The `package.json` grammar token type mapping changes how unquoted words are tokenized by VS Code; this is intentional to allow quick suggestions while typing in .def files. - The new completion endpoint is additive and should not change existing LSP behavior except that format-specific hover now takes precedence when applicable. No test execution results were provided.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Christoph/nx_post_support!68
No description provided.