Skip to content

Filename completion doesn't work for conditional imports #4530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DanTup opened this issue May 9, 2023 · 3 comments
Closed

Filename completion doesn't work for conditional imports #4530

DanTup opened this issue May 9, 2023 · 3 comments
Labels
in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server is bug relies on sdk changes Something that requires changes in the Dart/Flutter SDK to ship before it will become available
Milestone

Comments

@DanTup
Copy link
Member

DanTup commented May 9, 2023

Filed by @mosuem at #4529. Splitting it up because the issues may be fixed separately.

  1. There is no code completion for source file paths in conditional imports.
@DanTup DanTup added is bug in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server labels May 9, 2023
@DanTup DanTup added this to the v3.66.0 milestone May 9, 2023
@DanTup
Copy link
Member Author

DanTup commented 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:

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:

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 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 😄)

@bwilkerson
Copy link

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.

copybara-service bot pushed a commit to dart-lang/sdk that referenced this issue May 10, 2023
Fixes Dart-Code/Dart-Code#4530.

Change-Id: Iac1ec0467fa9d1838f75ff2512e1ca79f02fade8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302205
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
@DanTup
Copy link
Member Author

DanTup commented 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).

@DanTup DanTup closed this as completed May 10, 2023
@DanTup DanTup added the relies on sdk changes Something that requires changes in the Dart/Flutter SDK to ship before it will become available label Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server is bug relies on sdk changes Something that requires changes in the Dart/Flutter SDK to ship before it will become available
Projects
None yet
Development

No branches or pull requests

2 participants