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

Semantic snippets: handle case with inline statement snippets before member access expression #74966

Merged
merged 2 commits into from
Sep 11, 2024

Conversation

DoctorKrolic
Copy link
Contributor

Previously inline statement snippets chacked, wherther they are part of a member access expression with parent being an expression statament. The second part of the check makes sure, that in cases like Invocation(validType.$$) the snippet isn't offered since we cannot insert a statement inside an invocation argument. That logic had ta flaw. It couldn't handle case like this:

validType.$$
Console.WriteLine();

Here syntractically we have the same thing as validType.$$Console.WriteLine();, therefore a snippet is executed in a hierarchy of expressions, thus by the previous rules is invalid there. But it is obvious, that this is just a state-of-the-world during typing and the snippet should be offered. Thus I changed how the core logic works. Instead of traversing a potentially complicated subtree I made a check, whether a position before the inline expression is suitable to insert statement into. This both guards us against Invocation(validType.$$), but also suggests snippet in the primary case we want to fix. However, I didn't want snippets to appear inside a line as you edit it, e.g. I don't think foreach snippet will be useful if you are inside enumerable.$$Select(..., in such case you probably want to add a method to the call chain or something similar. Therefore I made an additional line checks, so now inline statement snippet can only be the last "member access" on the line. Yes, we usually compute completions based only on previous tokens, but snippets stand out quite a bit, so I think that such approach to them is ok

… position to handle member access expression case
@DoctorKrolic DoctorKrolic requested a review from a team as a code owner August 31, 2024 13:05
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 31, 2024
@dotnet-policy-service dotnet-policy-service bot added Community The pull request was submitted by a contributor who is not a Microsoft employee. VSCode labels Aug 31, 2024
@DoctorKrolic
Copy link
Contributor Author

@akhera99 PTAL

Copy link
Member

@akhera99 akhera99 left a comment

Choose a reason for hiding this comment

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

Looks good, thank you for the contribution!

@DoctorKrolic
Copy link
Contributor Author

Can we merge this one please?

@akhera99 akhera99 merged commit 7b75058 into dotnet:main Sep 11, 2024
25 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Sep 11, 2024
@DoctorKrolic DoctorKrolic deleted the inline-snippets-member-access branch September 11, 2024 17:56
333fred added a commit to 333fred/roslyn that referenced this pull request Sep 13, 2024
* upstream/main: (45 commits)
  Adjust an assert in EmitArgument (dotnet#75067)
  Switch to new VMR control set (dotnet#75056)
  Disallow ref assignment to ternary or another ref assignment (dotnet#75076)
  Move some emit tests from Emit2 to Emit3 to avoid hitting UserString heap limit (dotnet#75091)
  BindAttributeCore - use proper binder to avoid an attribute binding cycle (dotnet#75060)
  Remove buggy IsPublic method from TypeAttributesExtensions (dotnet#75081)
  Include initial filter node when searching for nodes to order modifiers
  Remove additional Gitter link (dotnet#75086)
  Remove newlines between test run information sections
  Log messages for Test Results
  Fix stack adjustment when emitting stackalloc (dotnet#75042)
  Lock translation of strings used to demonstrate identifier naming styles
  docs: Correct SDK version in documentation to match global.json (dotnet#75038)
  Add a test observing lack of an issue. (dotnet#75057)
  Fix preview refresh on selection for enum flags checkboxes
  Semantic snippets: handle case with inline statement snippets before member access expression (dotnet#74966)
  Configure release/vscode branch for nuget publishing
  Remove MS.CA.Test.Resources.Proprietary PackageReference (dotnet#75037)
  Allow suppressing nullability warnings in more ref scenarios (dotnet#74498)
  Update dependencies from https://github.com/dotnet/arcade build 20240909.6 (dotnet#75040)
  ...
@akhera99 akhera99 modified the milestones: Next, 17.12 P3 Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants