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
Renaming a symbol adds an extra dot in Dart doc comments, breaks link between symbol and reference #2816
Comments
@bwilkerson I can reproduce this in a test. The issue seems to be that the source range for a named constructor returned by Does not include the leading period. However the declaration reference and the replacement text seem to assume ranges should include the leading period (since the replacement text includes it). It seems like the range is coming from the index here: I'm not sure of the best way to fix - changing the result of the search engine seems like it could be risky (if other things expect it to be the name without the period). Do you know what the expectation is, and which bit is likely incorrect? I could update rename_constructor to assume there's no dot, though there are two other places it gets ranges (one is Another option (though I'm not sure this is really "clean") could be to check the length of the range, and include the period (or not) based on whether its length matches the old name with or without the period. For reference, here's a test (for @soloTest
Future<void> test_docReference() async {
await indexTestUnit('''
class SomeClass {
/// Docs for [SomeClass.namedConstructor].
SomeClass.namedConstructor(); // marker
}
''');
// configure refactoring
_createConstructorDeclarationRefactoring('namedConstructor(); // marker');
expect(refactoring.refactoringName, 'Rename Constructor');
expect(refactoring.elementKindName, 'constructor');
expect(refactoring.oldName, 'namedConstructor');
// validate change
refactoring.newName = 'newConstructor';
return assertSuccessfulRefactoring('''
class SomeClass {
/// Docs for [SomeClass.newConstructor].
SomeClass.newConstructor(); // marker
}
''');
} |
That seems appropriate to me. If the search engine is being used to find references to the constructor those ranges will be the range to which the user will navigate, and it seems appropriate that it doesn't include the period.
I believe that the search engine is correct and that it's the refactoring that needs to be updated.
It isn't quite that simple, unfortunately, because of unnamed constructors. The rename refactoring allows users to rename a named constructor to a named constructor (both have a period so it should be left as is), a named constructor to an unnamed constructor (the period needs to be removed), or an unnamed constructor to a named constructor (the period needs to be added). It sounds like the bug is in the first case. |
Ah, good point. Though it does seem like there is some inconsistency in the search engine results. I updated my sample to this: class SomeClass {
/// Docs for [SomeClass.namedConstructor].
SomeClass.namedConstructor(); // marker
final instance = SomeClass.namedConstructor();
} Here there are two references to the named constructor (one in the dartdoc, one in a call to the constructor for the I don't know if this is expected - should the search engine results be different for these? (I wouldn't have thought so - though if they are, the fix in the refactor would need to account for this difference). |
I wouldn't have expected them to be different. That might be a bug in the indexer, but @scheglov might know better. |
@scheglov do you have any thoughts on the above? Thanks! |
Yes, this looks like a bug in the refactoring or the indexer, I can reproduce it in a unit test. |
Bug: Dart-Code/Dart-Code#2816 Change-Id: I4515b6887f5d8bd93fc6ba59812c5a9ec14f0d3c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/181260 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
@scheglov great, thanks! |
Describe the bug
Renaming a named constructor or a factory results in duplicating the dot in any doc comment that is referencing that symbol. It breaks the link between the symbol and the reference for any subsequent renaming.
To Reproduce
Steps to reproduce the behavior:
Versions (please complete the following information):
The text was updated successfully, but these errors were encountered: