Skip to content
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

Find References doesn't work when selection covers an entire symbol #4157

Closed
DanTup opened this issue Sep 14, 2022 · 6 comments
Closed

Find References doesn't work when selection covers an entire symbol #4157

DanTup opened this issue Sep 14, 2022 · 6 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 Sep 14, 2022

Double-clicking on a method name then pressing Shift+F12 doesn't find anything:

Screenshot 2022-09-14 at 15 20 54

(same goes for putting the caret at the end of the name, which is likely the same offset for this selection).

@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 Sep 14, 2022
@DanTup DanTup added this to the v3.50.0 milestone Sep 14, 2022
@DanTup
Copy link
Member Author

DanTup commented Sep 20, 2022

@bwilkerson I'm trying to debug this and found that NodeLocator() is locating the argument list here in the case where the caret is in front of it (which seems reasonable and maybe should be handled specially). However, I noticed that when the caret is in the name, we don't locate the name, but rather the whole member declaration. This seemed odd to me so I wanted to check this is correct before making any changes.

For example, if I run this test code:

@soloTest
  void test_danny() async {
    await resolveTestCode('''
void aaa() {}
''');
    result.unit.accept(MyVisitor());
  }

Where MyVisitor looks like this:

class MyVisitor extends UnifyingAstVisitor<void> {
  @override
  void visitNode(AstNode node) {
    print('Visiting (${node.offset}) $node');
    super.visitNode(node);
  }
}

I get the following output:

Visiting (0) void aaa() {}
Visiting (0) void aaa() {}
Visiting (0) void
Visiting (0) void
Visiting (8) () {}
Visiting (8) ()
Visiting (11) {}
Visiting (11) {}

What seems off to me here is that there is no visit of the aaa token the starts at offset 5, but I was expecting one. Does this seem like a bug? (anecdotally, I was sure the behaviour in this issue worked in the past, I feel like I do this all the time, but there are no tests with the caret at the end of the identifier so I may be misremembering 😄).

@DanTup
Copy link
Member Author

DanTup commented Sep 20, 2022

Testing the original behaviour up top with stable 2.18.0, it definitely does work, so I think something has changed. I'll try to bisect this tomorrow to figure out what changed (assuming nothing stands out and you might know what it is already).

@bwilkerson
Copy link

AstVisitors only visit AstNodes. It used to be the case that the names in declarations were represented as SimpleIdentifier nodes. But we decided that the names aren't expressions, so we replaced all of the references to the nodes with references to the tokens. Your code isn't visiting aaa because it isn't a node anymore. Therefore, the closest node that NodeLocator can return is the declaration that holds onto the token.

@DanTup
Copy link
Member Author

DanTup commented Sep 21, 2022

Aah, you warned me that was coming, makes sense now.

It's possible this affects more than just Navigation then - previously the offset between name and args (foo^() would have located the name node but now it locates the argument list. Anything that doesn't handle this specifically might fail in this case (when double-clicking a symbol to select it, VS Code uses the end as the offset for requests like this).

I'll fix navigation and check other functionality for similar issues. Thanks!

Edit: I wrote "argument" many times above, but while testing realised that (as you stated) this change only affected declarations/parameters (identifiers in front of argument lists are still tokens and don't seem affected).

@bwilkerson
Copy link

It's possible this affects more than just Navigation then ...

Yes, lots of code might potentially be broken. We relied heavily on test cases to catch breakage, but tests can't provide complete coverage.

copybara-service bot pushed a commit to dart-lang/sdk that referenced this issue Sep 27, 2022
…ween name and type/parameter lists

Removal AstNodes for names in declarations left some of these places getting FormalParameterList/TypeParameterLists when an offset was between the name and parameter list. This is a fairly common case if you double-click to select a name in VS Code (it sends the end of the name as the offset).

This only changes the case where a single offset is provided (not a range), and it is both the start of the parameter list and the end of the name.

Fixes Dart-Code/Dart-Code#4157.

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

DanTup commented Oct 3, 2022

Fixed by dart-lang/sdk@d83cb4e.

@DanTup DanTup closed this as completed Oct 3, 2022
@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 Oct 3, 2022
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