Skip to content

fix(lsp): don't flag imports as unused when imported file defines a service or error#7

Merged
klaidliadon merged 1 commit into
masterfrom
fix/unused-import-service-files
Apr 22, 2026
Merged

fix(lsp): don't flag imports as unused when imported file defines a service or error#7
klaidliadon merged 1 commit into
masterfrom
fix/unused-import-service-files

Conversation

@klaidliadon
Copy link
Copy Markdown
Collaborator

Summary

Aggregator schemas like main.ridl that only compose other .ridl files were flagged "is unused" for every import, because the check only counted struct/enum/typealias references. Services and top-level errors are always-used contributors to the aggregated webrpc output, so their mere presence in the imported file means the import is live.

The same check also incorrectly suggested narrowing imports to a member list when the imported file contained a service or error — doing so would silently drop them from codegen.

Changes

  • importContributionsOf (new helper): separates what an imported file contributes into three buckets — types (referenceable per name), errors (always-used), services (always-used).
  • importDiagnostics now short-circuits when the imported file contributes a service or error, and only runs per-name reference counting on pure type-provider files.
  • Adds three focused tests covering the aggregator / service / error cases.

Decision matrix after this change

Imported file defines… Referenced by importer Result
Any service no warning
Any top-level error no warning
Only types, none referenced 0 "is unused"
Only types, some referenced partial "can be narrowed to: …"
Only types, all referenced full no warning
Nothing no warning

Selective imports (import "x.ridl" - Foo) are untouched — the transitive re-import check continues to work as before.

Real-world motivation

On omsx's schema/main.ridl — a pure aggregator that imports 11 service-bearing .ridl files plus errors.ridl — every import was flagged "unused" in the IDE. After this PR only a genuinely dead import (a model struct with no references) remains flagged, which is the signal the diagnostic is meant to produce.

Test plan

  • New unit tests cover aggregator + service / errors-only / service-with-types-not-all-used
  • Existing unused-import and narrowing tests still pass
  • make test clean
  • No new make lint findings (11 pre-existing failures in internal/ridl/parser.go and internal/lsp/semantic_document.go are untouched)

…ervice or error

Aggregator schemas like main.ridl that only compose other .ridl files
were flagged "is unused" for every import, because the check only
counted struct/enum/typealias references. Services and top-level errors
are always-used contributors to the aggregated webrpc output, so their
mere presence in the imported file means the import is live.

Also suppresses the "can be narrowed" suggestion on service/error-bearing
files — narrowing to a member list would drop the service or error from
codegen, which would be a silent correctness bug.

- Add importContributionsOf: separates types (per-name usage) from
  services and errors (always-used contributors)
- Update importDiagnostics to short-circuit on always-used contributors
  and apply reference counting only to pure type-provider files
@klaidliadon klaidliadon merged commit ec6dd7f into master Apr 22, 2026
1 check 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.

1 participant