Preserve leading proc comments; add trace completions; fix unset option #63

Closed
Christoph wants to merge 0 commits from 58-nocomplain-is-missing into main
Owner

This change combines three related updates:

  • A formatter change that preserves leading comments inside procedure bodies at the procedure's indentation level instead of indenting them with the first real command.
  • Additions to Tcl command completions and dynamic completion rules for the trace command and its subcommands.
  • A fix to the unset command option description to include the leading - for the -nocomplain option.

What changed (behavioral summary)

  • Formatter: The formatter now tracks proc bodies and, when formatting a proc body, keeps comments that appear before the body's first real command unindented. Previously, those header comments were indented along with the rest of the proc body. Concretely, the new logic records id(command.args[-1]) for commands whose routine is proc, and format_script checks whether the script object is a proc body. If so and should_indent is true, it removes one indentation level only for initial comment lines (lines that start with the expected indent plus #) until the first non-comment or non-empty line, leaving subsequent lines and comments indented normally.

    Before: leading header comments inside a proc were indented along with the first command.
    After: leading header comments remain at the proc's indentation level; the first actual command and everything after it are indented.

  • Completions: The Tcl completion tables gain entries for trace and its subcommands. Specifically:

    • SUBCOMMANDS_BY_PATH adds trace with subcommands add, info, remove and their respective modes (command, execution, variable).
    • VALUES_BY_POSITION adds expected values for trace add|remove for command, execution, and variable kinds (e.g. rename, delete, enter, leave, array, read, etc.).
    • DYNAMIC_COMPLETION_RULES adds dynamic completion rules for trace ... variable to suggest variable names, and for trace ... command|execution to suggest procedures where appropriate.
  • unset option: The OPTIONS_BY_PATH entry for ("unset",) was changed to include -nocomplain (with the leading hyphen) instead of nocomplain.

Files touched (high-level)

  • server/src/tools/formatter.py: new tracking for proc bodies and updated format_script to keep leading comments unindented.
  • server/src/tools/tcl_command_completion.py: added trace subcommands, values, and dynamic completion rules; replaced nocomplain with -nocomplain for unset options.
  • server/tests/python_tests/test_formatter.py: updated an existing formatter test and added test_leading_proc_comments_are_not_indented that expresses the new expected output for leading comments in proc bodies.

Testing

  • Tests or execution status: No test execution results were provided.

  • Tests added/changed: server/tests/python_tests/test_formatter.py was changed and a new test test_leading_proc_comments_are_not_indented was added to assert the formatting behavior described above.

Suggested checks for reviewers

  1. Run the formatter unit tests (for example, the Python test suite that includes test_formatter.py) to verify the new test expectations; inspect other formatter-related tests for unintended regressions.
  2. Try completions for trace add|info|remove in an environment that uses tcl_command_completion.py to confirm the static value suggestions and dynamic completions for variable and procedure positions.
  3. Verify that unset -nocomplain is recognized where the option parsing/metadata is used (search for usage sites relying on OPTIONS_BY_PATH).

Compatibility / risk notes

  • The formatter change only alters how leading comments inside proc bodies are indented. It should not affect other formatting behavior because the code only removes one indentation level for initial comment lines in proc bodies and only when should_indent is true. Reviewers should confirm no other code paths rely on the previous indentation of those comments.
  • The completions change extends suggestions for trace and is additive; it should not remove existing completions.

No reviewer action is required beyond running the suggested tests and validating completions and option recognition where these tables are consumed.

Closes #58

This change combines three related updates: - A formatter change that preserves leading comments inside procedure bodies at the procedure's indentation level instead of indenting them with the first real command. - Additions to Tcl command completions and dynamic completion rules for the `trace` command and its subcommands. - A fix to the `unset` command option description to include the leading `-` for the `-nocomplain` option. What changed (behavioral summary) - Formatter: The formatter now tracks proc bodies and, when formatting a proc body, keeps comments that appear before the body\'s first real command unindented. Previously, those header comments were indented along with the rest of the proc body. Concretely, the new logic records `id(command.args[-1])` for commands whose routine is `proc`, and `format_script` checks whether the script object is a proc body. If so and `should_indent` is true, it removes one indentation level only for initial comment lines (lines that start with the expected indent plus `#`) until the first non-comment or non-empty line, leaving subsequent lines and comments indented normally. Before: leading header comments inside a proc were indented along with the first command. After: leading header comments remain at the proc\'s indentation level; the first actual command and everything after it are indented. - Completions: The Tcl completion tables gain entries for `trace` and its subcommands. Specifically: - `SUBCOMMANDS_BY_PATH` adds `trace` with subcommands `add`, `info`, `remove` and their respective modes (`command`, `execution`, `variable`). - `VALUES_BY_POSITION` adds expected values for `trace add|remove` for `command`, `execution`, and `variable` kinds (e.g. `rename`, `delete`, `enter`, `leave`, `array`, `read`, etc.). - `DYNAMIC_COMPLETION_RULES` adds dynamic completion rules for `trace ... variable` to suggest variable names, and for `trace ... command|execution` to suggest procedures where appropriate. - `unset` option: The `OPTIONS_BY_PATH` entry for `("unset",)` was changed to include `-nocomplain` (with the leading hyphen) instead of `nocomplain`. Files touched (high-level) - server/src/tools/formatter.py: new tracking for proc bodies and updated `format_script` to keep leading comments unindented. - server/src/tools/tcl_command_completion.py: added `trace` subcommands, values, and dynamic completion rules; replaced `nocomplain` with `-nocomplain` for `unset` options. - server/tests/python_tests/test_formatter.py: updated an existing formatter test and added `test_leading_proc_comments_are_not_indented` that expresses the new expected output for leading comments in proc bodies. Testing - Tests or execution status: No test execution results were provided. - Tests added/changed: `server/tests/python_tests/test_formatter.py` was changed and a new test `test_leading_proc_comments_are_not_indented` was added to assert the formatting behavior described above. Suggested checks for reviewers 1. Run the formatter unit tests (for example, the Python test suite that includes `test_formatter.py`) to verify the new test expectations; inspect other formatter-related tests for unintended regressions. 2. Try completions for `trace add|info|remove` in an environment that uses `tcl_command_completion.py` to confirm the static value suggestions and dynamic completions for variable and procedure positions. 3. Verify that `unset -nocomplain` is recognized where the option parsing/metadata is used (search for usage sites relying on `OPTIONS_BY_PATH`). Compatibility / risk notes - The formatter change only alters how leading comments inside proc bodies are indented. It should not affect other formatting behavior because the code only removes one indentation level for initial comment lines in proc bodies and only when `should_indent` is true. Reviewers should confirm no other code paths rely on the previous indentation of those comments. - The completions change extends suggestions for `trace` and is additive; it should not remove existing completions. No reviewer action is required beyond running the suggested tests and validating completions and option recognition where these tables are consumed. Closes #58
feat(tcl-completion): add completions and dynamic rules for trace
All checks were successful
Tests / node (pull_request) Successful in 31s
Tests / python (pull_request) Successful in 32s
ac736fff86
Add "trace" subcommands (add, info, remove) and their kinds
(command, execution, variable) to static completion tables. Provide
position-specific value suggestions for each kind (e.g. "rename",
"delete" for command; "enter", "leave", "enterstep", "leavestep" for
execution; "array", "read", "write", "unset" for variable).

Register dynamic completion rules so the appropriate trace argument
positions complete as VARIABLE or PROCEDURE where applicable. This enables
context-aware name suggestions when using trace add/info/remove.

Fixes #61
Previously the "unset" option was registered as "nocomplain" (no leading hyphen), which was inconsistent with other OptionSpec entries and could cause option-matching to fail. This commit changes that entry to "-nocomplain" so the option is recognized with its expected dash.

Also reformatted two multiline generator expressions that build DynamicCompletionRule entries into single-line comprehensions; this is a whitespace-only tidy and does not change behavior.

Fixes #58
feat(formatter): keep leading comments in proc bodies unindented
Some checks failed
Tests / node (pull_request) Successful in 24s
Tests / python (pull_request) Failing after 35s
14cdfc9bfe
Preserve comment lines that occur before the first real command inside a proc
body at the proc's own indentation level instead of indenting them with the
body. NxFormatter now tracks proc body objects (by id) when formatting
commands and adjusts format_script (only when should_indent is True) to
leave those leading header comments unindented. Adds unit test
test_leading_proc_comments_are_not_indented to cover nested and namespaced cases.

Fixes #58
Christoph closed this pull request 2026-10-10 16:15:46 +00:00
Some checks failed
Tests / node (pull_request) Successful in 24s
Required
Details
Tests / python (pull_request) Failing after 35s
Required
Details

Pull request closed

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!63
No description provided.