Allow LSP code action requests to set the (new) AllowGenerateInHiddenCode option#66917
Allow LSP code action requests to set the (new) AllowGenerateInHiddenCode option#66917davidwengier wants to merge 10 commits intodotnet:mainfrom
Conversation
|
Warning: Need to add this ability (to set options) to CodeActionResolve too, because the first thing it does is compute code actions again :( At least there we have |
...e/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateMethodService.State.cs
Outdated
Show resolved
Hide resolved
...es/Core/Portable/GenerateMember/GenerateParameterizedMember/AbstractGenerateMethodService.cs
Outdated
Show resolved
Hide resolved
...orkspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeGeneration/CodeGenerationOptions.cs
Outdated
Show resolved
Hide resolved
src/Features/LanguageServer/ProtocolUnitTests/CodeActions/CodeActionsTests.cs
Outdated
Show resolved
Hide resolved
src/Features/LanguageServer/ProtocolUnitTests/CodeActions/CodeActionsTests.cs
Outdated
Show resolved
Hide resolved
|
Could you point to code that sets the option value on an instance of |
|
I'm going to wait on Tomas being ok before looking :) |
dibarbet
left a comment
There was a problem hiding this comment.
lsp side mostly looks fine to me
src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionParamsWithOptions.cs
Show resolved
Hide resolved
| Contract.ThrowIfNull(document); | ||
|
|
||
| var options = _globalOptions.GetCodeActionOptionsProvider(); | ||
| var options = new LSPCodeActionOptionsProvider(request.AllowGenerateInHiddenCode, _globalOptions.GetCodeActionOptionsProvider()); |
There was a problem hiding this comment.
I forget - why do we need a provider here instead of passing in the actual CodeActionOptions? Probably a question for @tmat
There was a problem hiding this comment.
I was surprised to find it wasn't a CodeActionOptions myself, though to be honest I'm not sure I would have known how to override the value if it was, so I wasn't unhappy :)
There was a problem hiding this comment.
Probably because we call to some code that potentially operates on any document/project in the solution and might need options for a different language than the language of the current document.
There was a problem hiding this comment.
Would be good to add a test for that scenario.
For an LSP request the value is set by wrapping the options provider: Otherwise the CodeGenerationOptions constructor sets it from the fallbackOptions, which is what makes |
src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionsHandler.cs
Outdated
Show resolved
Hide resolved
|
On second thought, I think we might need a different approach here. I think we need to do what The problem is if we have a Foo.razor file and a Goo.cs file that had hidden regions in it, then currently this change will mean code actions requested from Foo.razor will offer to generate in hidden regions of Goo.cs, which we don't want. If we just use the document properties service approach though, code actions requested from Goo.cs will offer to generate in Foo.razor[.g.cs], but nothing will be processing the result of the code action request to actual make those edits valid. The question is how to tell the document is a razor document. We could add something to DocumentPropertiesService for Thoughts? Do we even care about hidden regions for non-asp.net files? As far as I understand from the code comments, thats what it was added for. I would be surprised if people were manually creating them, and were happy not getting code generation offered. Also worth mentioning that we'll eventually be switching to using the razor source generator documents instead of |
Right, so that's what troubles me about adding more document services based approach. It seems like we need to rethink how code actions for Razor should be architected rather than just adding one-off flag. |
I don't disagree, but I also don't want to block this forever. Even if we consider this a temporary hacky fix, it unblocks Generate Method for razor users, and that's the 3rd most used code action in C#. I guess I'll set up a meeting and we can talk about it more. |
|
Random thought/realisation: If we separate "Generate Method" and "Generate Method into a different document" into two code fixes, then Razor could just allow-list the former, and this PR would be sufficient. The latter would then be unblocked by the more elaborate re-architecting that we're talking about. |
More background work for dotnet/razor#8204
I've talked to all of you about this, so hopefully this matches your expectations.
It is intentional, for now, that only one of the actual code fixes honour the new setting. I figured going for a slow rollout makes sense, and given its triggered by LSP we don't need to worry about dual insertion nonsense to expand support on the Roslyn sign once Razor is capable enough.