Skip to content

Dart doc shows no result in auto complete for type names and only for static declarations inside them #59724

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
FMorschel opened this issue Dec 16, 2024 · 13 comments
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-completion Issues with the analysis server's code completion feature P3 A lower priority bug or feature request

Comments

@FMorschel
Copy link
Contributor

FMorschel commented Dec 16, 2024

Repro:

lib.dart

class Class1 {
  static void foo() {}
  void bar() {}
}

main.dart

/// This is a dart doc.
/// It should show an auto-complete for Class1 over here: [C] but it doesn't.
/// Also should show autocomplete for instance values like bar over [Class1.] but it doesn't.
library main;

See here no items from Dart:

image

See here only triggering for static methods:

image


//CC @DanTup

@FMorschel FMorschel added the legacy-area-analyzer Use area-devexp instead. label Dec 16, 2024
@FMorschel FMorschel changed the title Dart doc doesn't trigger auto complete for type names and only for static declarations inside them Dart doc shows no result in auto complete for type names and only for static declarations inside them Dec 16, 2024
@bwilkerson bwilkerson added devexp-completion Issues with the analysis server's code completion feature P3 A lower priority bug or feature request labels Dec 16, 2024
@FMorschel
Copy link
Contributor Author

Also, if this needs to add an import, we should agree with adding a doc import here too, I think (@bwilkerson).

@bwilkerson
Copy link
Member

Yes. Doc imports are there for any names referenced only in documentation comments.

@FMorschel
Copy link
Contributor Author

@srawlins comment #59910 (comment):

Dartdoc prefers the A.foo instance member. To specifically refer to the constructor, you can use A.foo(). We should document this behavior here: https://dart.dev/tools/doc-comments/references

So for this code, you can differentiate between them:

/// A class with [A.foo] and [A.foo()]
class A {
  int foo = 0;
  A.foo();
}

But there is no colouring for A.foo() (currently being suggested correctly). Should I open a new issue for this? Not sure where is the problem (@DanTup? I saw you fixed braces colouring previously somewhere).

Image

@srawlins
Copy link
Member

Ah yeah, that'd be an Analysis Server issue I think.

@FMorschel
Copy link
Contributor Author

For the above:

/// It should show an auto-complete for Class1 over here: [C] but it doesn't.

similar to #59946, this only happens at library;. It works fine over a class declaration.

Image

Image


I was actually trying to fix this myself, but while I was following the structure of pkg\analysis_server\test\services\completion\dart\location\constructor_invocation_test.dart to create a new file for dart docs, this is the current state of my first test:

Image

I'm unsure of what am I doing differently here. If anyone could help I'd appreciate it. Also unsure of where are the current tests for completion in Dart docs.

@bwilkerson
Copy link
Member

The test looks reasonable to me, at least on the surface.

I verified that the comment is associated with the class declaration, so it seems like it ought to be working.

The only advice I have is to use the advice in https://github.com/dart-lang/sdk/blob/main/pkg/analysis_server/doc/implementation/code_completion.md to debug the problem.

@FMorschel
Copy link
Contributor Author

The completion suggestion gets all the way here but this regex is expecting different names on 207:

if (kind == CompletionSuggestionKind.IDENTIFIER ||
kind == CompletionSuggestionKind.INVOCATION) {
var completion = suggestion.completion;
if (includeClosures && completion.startsWith('(')) {
return true;
}
var periodIndex = completion.indexOf('.');
if (periodIndex > 0) {
completion = completion.substring(0, periodIndex);
}
return RegExp(r'^_?[a-zA-Z][0-9]+$').hasMatch(completion) ||
allowedIdentifiers.contains(completion);

This is probably to avoid huge lists of suggestions here, I'll add this info to the docs for the tests here too.

@FMorschel
Copy link
Contributor Author

Here is the initial CL to add the outline of tests for completion inside dart-docs https://dart-review.googlesource.com/410461.

@stereotype441 was suggested as reviewer by the CLI, so if you disagree, please assign someone else. I've added @srawlins because I've seen him working with Dart Docs before and being very familiar with the specs for it.

@FMorschel
Copy link
Contributor Author

FMorschel commented Feb 18, 2025

As a separate note, the above comment referencing auto-complete not showing up (quoted below), happens above:

  • library (as noted above)
  • import (maybe export and part as well but I'm unsure on why these would be commented, if you think I should add tests too, please say so)
  • extension
  • typedef

For the above:

/// It should show an auto-complete for Class1 over here: [C] but it doesn't.

similar to #59946, this only happens at library;. It works fine over a class declaration.

Image

Image


Edit: It seems like the parser/resolver is not correctly identifying the [] as a CommentReference for typedef and extension and this will take me longer to fix since I'm not that familiar with this code. For library and import they are correctly identified so I'll keep working locally on that.

@FMorschel
Copy link
Contributor Author

FMorschel commented Feb 18, 2025

I already have a fix for library and import (and probably any directive as I wrote) here https://github.com/fmorschel/sdk/tree/auto-complete-directives.


Edit: https://dart-review.googlesource.com/c/sdk/+/411360

@FMorschel
Copy link
Contributor Author

FMorschel commented Feb 19, 2025

I already have the fix for the typedef and extension. It was something other (easier) than my initial assessment: https://github.com/fmorschel/sdk/tree/identify-commentreference


Edit: https://dart-review.googlesource.com/c/sdk/+/411380

@FMorschel
Copy link
Contributor Author

FMorschel commented Feb 19, 2025

Now last but not least, the fix for the instance members is at https://github.com/fmorschel/sdk/tree/auto-complete-instance. Once the base tests are merged I'll update these last messages with their respective CL links as soon as I open them. Thanks to everyone in this issue and the CL reviewers!


Edit: https://dart-review.googlesource.com/c/sdk/+/411361

copybara-service bot pushed a commit that referenced this issue Feb 21, 2025
[email protected]

Bug: #59724
Change-Id: Ia2345c77371a58ad0be402daa93642a3f0e53dc7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/410461
Reviewed-by: Phil Quitslund <[email protected]>
Commit-Queue: Brian Wilkerson <[email protected]>
Reviewed-by: Samuel Rawlins <[email protected]>
Auto-Submit: Felipe Morschel <[email protected]>
@FMorschel
Copy link
Contributor Author

FMorschel commented Feb 21, 2025

Alright, probably last update here. The three new CLs are open and updated above. The last one is medium sized (mostly tests) and the other two are small ones. Thanks again everyone!


Edit: Ping @srawlins for reviews 😁
Edit 2: Ping @keertip for review (mainly the last CL, you're set as a reviewer there already), thanks!

@bwilkerson bwilkerson added area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. and removed legacy-area-analyzer Use area-devexp instead. labels Feb 21, 2025
copybara-service bot pushed a commit that referenced this issue Feb 25, 2025
[email protected]

Bug: #59724
Change-Id: I9a4a7390e71b1e1fd2daa0f3e548f28cd34834cf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/411380
Reviewed-by: Samuel Rawlins <[email protected]>
Auto-Submit: Felipe Morschel <[email protected]>
Reviewed-by: Phil Quitslund <[email protected]>
Commit-Queue: Samuel Rawlins <[email protected]>
copybara-service bot pushed a commit that referenced this issue Feb 26, 2025
[email protected]

Bug: #59724
Change-Id: I580b39acc96697990b12527aea699cdf09d788e3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/411360
Auto-Submit: Felipe Morschel <[email protected]>
Reviewed-by: Samuel Rawlins <[email protected]>
Reviewed-by: Phil Quitslund <[email protected]>
Commit-Queue: Samuel Rawlins <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-completion Issues with the analysis server's code completion feature P3 A lower priority bug or feature request
Projects
None yet
Development

No branches or pull requests

3 participants