Skip to content

Add member/port/package auto-completion (#82)#280

Merged
joecrop merged 7 commits into
eirikpre:masterfrom
joecrop:feature/82-member-completion
Jun 3, 2026
Merged

Add member/port/package auto-completion (#82)#280
joecrop merged 7 commits into
eirikpre:masterfrom
joecrop:feature/82-member-completion

Conversation

@joecrop

@joecrop joecrop commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Implements context-aware completion: typing a trigger character suggests the relevant members.

All four share one mechanism: detect the context, resolve a container symbol name, then list the symbols whose container is that name. Members are found by re-parsing the container's defining file on demand at a high maxDepth, because the default index depth (1) does not capture members of types nested in a package/module. Reuses DefinitionProvider.moduleFromPort for the port context and the ¤ exact-match workspace query to locate defining files.

New SystemVerilogCompletionItemProvider (registered with '.'/':' triggers), replacing the unused src/wip/CompletionItemProvider.ts. Adds unit tests for the pure context/type-name helpers and provider tests via executeCompletionItemProvider, plus verilog-examples/member_completion.sv.

Closes #82

joecrop and others added 7 commits June 3, 2026 15:53
Implements context-aware completion: typing a trigger character suggests the
relevant members.
- `var.`  -> fields of the struct/union type of `var` (the eirikpre#82 request)
- `obj.`  -> properties/methods of the class type of `obj`
- `.`     -> ports of the module being instantiated (in a port-connection slot)
- `pkg::` -> members declared in package `pkg`

All four share one mechanism: detect the context, resolve a container symbol
name, then list the symbols whose `container` is that name. Members are found
by re-parsing the container's defining file on demand at a high maxDepth,
because the default index depth (1) does not capture members of types nested
in a package/module. Reuses DefinitionProvider.moduleFromPort for the port
context and the `¤` exact-match workspace query to locate defining files.

New SystemVerilogCompletionItemProvider (registered with '.'/':' triggers),
replacing the unused src/wip/CompletionItemProvider.ts. Adds unit tests for
the pure context/type-name helpers and provider tests via
executeCompletionItemProvider, plus verilog-examples/member_completion.sv.

Closes eirikpre#82

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add the new member/port/package auto-completion (eirikpre#82) to the README feature
list and Examples section, and bump the version to 0.15.0 for this feature
release (moving the eirikpre#82 entry to a new [0.15.0] CHANGELOG section).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Completion latency came from re-parsing files on every invocation. Add a
per-file parse cache keyed by `fsPath|maxDepth` and invalidated by the
document version, so repeat completions (and same-file struct/package
lookups) reuse the parse instead of round-tripping to the indexer worker.

Also show a transient status-bar spinner ("$(sync~spin) SystemVerilog:
resolving members…") while the lookup runs, so the user gets feedback during
the (now rarer) slow path. The message clears automatically when the work
settles.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Extend member completion to enum values: typing `fsm_state ==`/`!=` or a
case-item label inside `case (fsm_state)` now suggests the enum's values.

- parser-core: index enum values as members of the enum type (getEnumValues),
  so they flow through the same container-based lookup as struct fields.
- symbol-kinds: map `enum_value` to SymbolKind.EnumMember.
- CompletionItemProvider: detect `expr ==`/`!=`/`===`/`!==` (a new `value`
  context) and case-item label positions (enclosingCaseExpr scans back to the
  enclosing `case (expr)` selector), then list that type's members.

Note: this is the enum idiom; for packed structs the fields are reached with
`.` (already supported), not via `==`/case.

Updates the fixture to a typedef enum and adds parser + provider tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Completion looked up a type/container by name across the whole workspace and
merged the members of every same-named definition, so a type name reused in
several local-scoped files (e.g. a per-file `state_e`) produced a union of all
their members.

Resolve with SystemVerilog scope instead:
1. a definition in the current file wins (local scope);
2. otherwise, when the name is defined in multiple files, prefer the
   definition whose package is imported by the current file (via the file's
   `import pkg::*` statements), falling back to a single match rather than the
   union of every same-named definition.

Adds scope_a.sv / scope_b.sv (same type name, different values) and a test
asserting the other file's values are not offered.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Extend scope resolution to respect an explicit package qualifier on the
declared type: `pkg_x::kind_e v` now completes pkg_x's members even when a
same-named type exists in another package or locally.

resolveType now returns the type name plus any explicit package scope
(typeScope helper), and completeMembers takes a preferScope: when present it
skips the local-definition shortcut and narrows the workspace matches to that
package (in addition to wildcard-imported packages).

Adds pkg_x.sv/pkg_y.sv (same enum type name in different packages) and
scope_explicit.sv with a test asserting only the referenced package's values
are offered.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…re#82)

A self-contained example exercising every completion context with "TRY:"
cursor hints: struct fields (pkt.), package members (demo_pkg::), class
members (tr.), module ports (fifo instantiation), and enum values in `==`
and case labels. Points to the scope_*/pkg_* fixtures for cross-file scope.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@joecrop
joecrop force-pushed the feature/82-member-completion branch from 593fe1a to 007de58 Compare June 3, 2026 22:56
@joecrop
joecrop merged commit cf034fb into eirikpre:master Jun 3, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Suggestion] Member Auto Suggestion for Struct or Union.

1 participant