Skip to content

Conversation

@ryzngard
Copy link
Contributor

No description provided.

@ryzngard ryzngard requested a review from a team as a code owner July 27, 2023 23:18

var owner = syntaxTree.Root.LocateOwner(change);
var token = syntaxTree.Root.FindToken(context.Location.AbsoluteIndex);
var owner = token?.Parent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you validate that the switch on line 69 below, is still needed? Some of those quirks in tree shape might have been fixed by the FindToken API.

Copy link
Contributor Author

@ryzngard ryzngard Jul 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it's still needed. Handle_AtEndOfCodeDirectiveWithNoSpace_ReturnsResult fails for

@code$${ private var x = 1; }

if I change just to look for a node.Parent is RazorDirectiveSyntax, along with the following other tests

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking. I suspect @code$$ { falls into the second arm now, not the first, but makes sense that the first one is needed with the current algorithm.

@333fred does Roslyn do any heuristics like "if the token in front of the caret is punctuation, use the token behind it"?

Copy link
Member

@333fred 333fred Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. The rule is very simple and straightforward: all trailing trivia, up to and not including the newline, is attached to the previous token. Any further trivia is attached to the next token (which is potentially the eof token at the end of the file). And, importantly, punctuation such as { is not trivia.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for confirming. If this becomes important we can always create an extension method that deals with it. As it is the switch expression only deals with two cases, so its not quite at the level of "deal with compiler quirks" :)

@ryzngard ryzngard enabled auto-merge (squash) July 27, 2023 23:54
ryzngard and others added 2 commits July 28, 2023 14:27
@ryzngard ryzngard merged commit bd4b98f into dotnet:main Jul 28, 2023
@ghost ghost added this to the Next milestone Jul 28, 2023
@Cosifne Cosifne modified the milestones: Next, 17.8 P3 Sep 25, 2023
@ryzngard ryzngard deleted the LocateOwner/code_action_providers branch October 15, 2024 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants