Complete BLOCK_LIST/ADDR_LIST completions and format comment spacing #45

Merged
Christoph merged 0 commits from refs/pull/45/head into main 2026-09-24 12:27:56 +00:00
Christoph commented 2026-09-24 12:27:50 +00:00 (Migrated from git.cbsk-tech.de)

This change adds editor completion for the special keywords BLOCK_LIST and ADDR_LIST and tweaks comment formatting to ensure a space after a single # when appropriate.

The primary user-visible outcomes:

  • LSP completion behavior for symbol-list keywords

    • Typing a prefix like BLOCK_L now offers the BLOCK_LIST keyword as an incomplete completion item that triggers further suggestions (it uses editor.action.triggerSuggest).
    • Once the full keyword is present in the typed word position, the completion replaces the keyword with a complete list of quoted names (block templates for BLOCK_LIST, addresses for ADDR_LIST).
    • Each returned item uses filter_text prefixed with the keyword (e.g. BLOCK_LIST"steady_rest") so suggesting the keyword remains visible while additional typing narrows the list.
    • The completion ignores occurrences that are variables (e.g. $BLOCK_LIST) or other word contexts (e.g. MY_BLOCK_LIST or plain steady).
    • Implementation is concentrated in a new helper _symbol_list_completion(...) and integration points in on_completion and _on_completion in server/src/lsp_server.py. The file imports line_prefix_at_position and uses a small regex to detect the word before the cursor.
  • Comment formatting

    • NxFormatter.format_comment (in server/src/tools/formatter.py) now inserts a single space after a # for comments like #Comment → # Comment, while leaving #, ##... separators, #! shebang-like comments, and comments that already start with whitespace unchanged. Inline comments after code (set x 1 ;#inline) are likewise formatted to ;# inline.

Files touched (high-level):

  • server/src/lsp_server.py: add _symbol_list_completion, integrate with completion flow, and merge symbol-list items when suggestions are re-requested.
  • server/src/tools/formatter.py: add format_comment to NxFormatter.
  • Tests: added/updated tests under server/tests/python_tests/:
    • test_def_symbols.py: new tests for BLOCK_LIST/ADDR_LIST completion behavior.
    • test_formatter.py: renamed from test_format_uplevel.py and extended with test_comment_gets_space_after_hash.

Testing

No test execution results were provided.

Recommended checks for reviewers:

  • Run the unit tests in server/tests/python_tests/ (e.g. pytest server/tests/python_tests/ -k def_symbols and -k formatter) to exercise the new tests locally.
  • In an editor connected to the LSP server, verify these interactive scenarios:
    1. Type BLOCK_L and confirm the completion list shows BLOCK_LIST as an incomplete item and that selecting or continuing typing triggers the full list.
    2. Type BLOCK_LIST (or ADDR_LIST) in a call site and confirm the completions are the quoted names (e.g. "steady_rest", "SPOS") and that the replacement inserts quotes.
    3. Confirm comments like #Comment become # Comment and that ## heading, #\tTabbed, #, and #!something remain unchanged.

Compatibility / Risk notes

  • This is a localized change to LSP completion and formatter behavior. There are no changed on-disk formats or configuration flags introduced by the diff.
  • The completion logic depends on LSP_SERVER.block_template_items() and LSP_SERVER.address_items() to return the available names; reviewers should confirm these functions behave as expected in the running environment.

If you want I can point to the specific changed blocks in lsp_server.py and formatter.py for a targeted review of the new helpers and their interaction with existing completion ranking logic.

This change adds editor completion for the special keywords `BLOCK_LIST` and `ADDR_LIST` and tweaks comment formatting to ensure a space after a single `#` when appropriate. The primary user-visible outcomes: - LSP completion behavior for symbol-list keywords - Typing a prefix like `BLOCK_L` now offers the `BLOCK_LIST` keyword as an incomplete completion item that triggers further suggestions (it uses `editor.action.triggerSuggest`). - Once the full keyword is present in the typed word position, the completion replaces the keyword with a complete list of quoted names (block templates for `BLOCK_LIST`, addresses for `ADDR_LIST`). - Each returned item uses `filter_text` prefixed with the keyword (e.g. `BLOCK_LIST"steady_rest"`) so suggesting the keyword remains visible while additional typing narrows the list. - The completion ignores occurrences that are variables (e.g. `$BLOCK_LIST`) or other word contexts (e.g. `MY_BLOCK_LIST` or plain `steady`). - Implementation is concentrated in a new helper `_symbol_list_completion(...)` and integration points in `on_completion` and `_on_completion` in `server/src/lsp_server.py`. The file imports `line_prefix_at_position` and uses a small regex to detect the word before the cursor. - Comment formatting - `NxFormatter.format_comment` (in `server/src/tools/formatter.py`) now inserts a single space after a `#` for comments like `#Comment` → `# Comment`, while leaving `#`, `##...` separators, `#!` shebang-like comments, and comments that already start with whitespace unchanged. Inline comments after code (`set x 1 ;#inline`) are likewise formatted to `;# inline`. Files touched (high-level): - `server/src/lsp_server.py`: add `_symbol_list_completion`, integrate with completion flow, and merge symbol-list items when suggestions are re-requested. - `server/src/tools/formatter.py`: add `format_comment` to `NxFormatter`. - Tests: added/updated tests under `server/tests/python_tests/`: - `test_def_symbols.py`: new tests for `BLOCK_LIST`/`ADDR_LIST` completion behavior. - `test_formatter.py`: renamed from `test_format_uplevel.py` and extended with `test_comment_gets_space_after_hash`. Testing No test execution results were provided. Recommended checks for reviewers: - Run the unit tests in `server/tests/python_tests/` (e.g. `pytest server/tests/python_tests/ -k def_symbols` and `-k formatter`) to exercise the new tests locally. - In an editor connected to the LSP server, verify these interactive scenarios: 1. Type `BLOCK_L` and confirm the completion list shows `BLOCK_LIST` as an incomplete item and that selecting or continuing typing triggers the full list. 2. Type `BLOCK_LIST` (or `ADDR_LIST`) in a call site and confirm the completions are the quoted names (e.g. `"steady_rest"`, `"SPOS"`) and that the replacement inserts quotes. 3. Confirm comments like `#Comment` become `# Comment` and that `## heading`, `#\tTabbed`, `#`, and `#!something` remain unchanged. Compatibility / Risk notes - This is a localized change to LSP completion and formatter behavior. There are no changed on-disk formats or configuration flags introduced by the diff. - The completion logic depends on `LSP_SERVER.block_template_items()` and `LSP_SERVER.address_items()` to return the available names; reviewers should confirm these functions behave as expected in the running environment. If you want I can point to the specific changed blocks in `lsp_server.py` and `formatter.py` for a targeted review of the new helpers and their interaction with existing completion ranking logic.
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!45
No description provided.