-
Notifications
You must be signed in to change notification settings - Fork 771
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
Code actions/fixes for common edits #1406
Comments
In this file I create a new rule that provides a fix to add the @secure decorator to parameters of type string and object. I know how to provide code actions in typescript. |
@nilshedstrom Hey Nils. I'm afraid the linter was not designed for this - it returns diagnostics. What we need for code refactorings is to create a code actions provider (vscode.languages.registerCodeActionsProvider). It would need to be hooked up to synchronize with the language server compiler. @majastrz @anthony-c-martin This was marked as a good first issue, but it seems to me it will need some preparatory work first. After that, adding new refactorings ought to be fairly straightforward (we were just talking today about refactorings). @nilshedstrom We want to avoid doing work in typescript for Bicep because it would be restricted to vscode. If it's kept in the language server, it can be reused for other editors (that wasn't possible when the ARM Tools extension was started). |
Ok. Tell me when I can start working on this issue. |
@nilshedstrom - I've pushed a branch here: https://github.com/Azure/bicep/compare/ant/codefix to serve as an example. Feel free to take this code and fork it for a starting point! Note that my implementation for SecureParameterCodeFixProvider.cs is not robust - really intended to just provide an example of looking for a particular piece of syntax (parameter declaration), and suggesting a rewrite for it. Let me know if you have any questions :) Here's a demo of this code in action: Screen.Recording.2021-12-08.at.11.12.44.PM.mov |
Thanks @anthony-c-martin! I do not find a way to set the cursor when providing a quick fix (this was requested in this issue when adding the allowed decorator). |
@nilshedstrom - looks like moving the cursor in a |
Closing this issue as we now have support for parameter decorators (thanks @nilshedstrom!). Going forwards, I suggest we create separate issues for each code fix idea. |
Re-opening/reverting, the PR has failing suites. |
* Codefix example * Made SecureParameterCodeFixProvider more robust * Trying to fix the tests for CodeActions (after adding the new QuickFix'es) * Added DescriptionParameterCodeFixProvider * Refactored and added support for @Allowed, @minlength, @maxlength, @minValue, @MaxValue * Made ParameterCodeFixProvider more robust Co-authored-by: Anthony Martin <[email protected]> Co-authored-by: Hedström, Nils <[email protected]>
Closing again - the PR was eventually re-merged 😄 |
We should consider adding code actions or commands to make common edits in Bicep. For example, parameters could allow actions like the following:
@secure
decorator above it)@allowed
snippet and moves the cursor to the first item in the array)The text was updated successfully, but these errors were encountered: