You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Filename completion doesn't work for conditional imports #4530
@bwilkerson I thought this would be a trivial fix, but I hit some issues because when completing at eof in code like:
import '' if (a) '^
The completion entity is a synthetic ; whose parent is ImportDirective. This means in a few places where I'd like to see Configuration I see ImportDirective. There are a few places that assume given an ImportDirective we'd be completing its uri, for example:
So I'm not sure whether the fix is to try and handle this in those places (another is UriContributor which only visits ImportDirective as a result, and not Configuration), or whether the completion target/containingNode should be more specific for Configurations?
(I'm also aware you wanted to make some changes in this area, so if this is best left until after, that's fine - I thought this would be a two-line fix 😄)
It will probably be easier to fix in the design I've proposed, but they key here is to notice when we're completing in an ImportDirective, the offset is inside a configuration, and the offset is after a synthetic string and before a synthetic semicolon (or something like that, there's probably other structures produced if it's followed by another configuration).
Unfortunately, with code completion, there's generally nothing easier than trying all of the possible inputs you can think of and figuring out what structure you're looking at, and it's sometimes the case that the structure doesn't match what the user has in mind at all.
Activity
DanTup commentedon May 9, 2023
@bwilkerson I thought this would be a trivial fix, but I hit some issues because when completing at eof in code like:
The completion entity is a synthetic
;whose parent isImportDirective. This means in a few places where I'd like to seeConfigurationI seeImportDirective. There are a few places that assume given anImportDirectivewe'd be completing itsuri, for example:https://github.com/dart-lang/sdk/blob/a41d1b5813b4e463cff6876bb24730642ffa8405/pkg/analyzer_plugin/lib/src/utilities/completion/completion_target.dart#L487
So I'm not sure whether the fix is to try and handle this in those places (another is
UriContributorwhich only visitsImportDirectiveas a result, and notConfiguration), or whether the completion target/containingNode should be more specific forConfigurations?(I'm also aware you wanted to make some changes in this area, so if this is best left until after, that's fine - I thought this would be a two-line fix 😄)
bwilkerson commentedon May 9, 2023
It will probably be easier to fix in the design I've proposed, but they key here is to notice when we're completing in an
ImportDirective, the offset is inside a configuration, and the offset is after a synthetic string and before a synthetic semicolon (or something like that, there's probably other structures produced if it's followed by another configuration).Unfortunately, with code completion, there's generally nothing easier than trying all of the possible inputs you can think of and figuring out what structure you're looking at, and it's sometimes the case that the structure doesn't match what the user has in mind at all.
[analysis_server] Handle completion for conditional imports
DanTup commentedon May 10, 2023
Fixed by dart-lang/sdk@dd72682 (an SDK change, so it'll show up in an SDK release rather than a Dart-Code release).