fix(lsp): don't flag imports as unused when imported file defines a service or error#7
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Aggregator schemas like
main.ridlthat only compose other.ridlfiles 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).importDiagnosticsnow short-circuits when the imported file contributes a service or error, and only runs per-name reference counting on pure type-provider files.Decision matrix after this change
"is unused""can be narrowed to: …"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.ridlfiles pluserrors.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
make testcleanmake lintfindings (11 pre-existing failures ininternal/ridl/parser.goandinternal/lsp/semantic_document.goare untouched)