-
Notifications
You must be signed in to change notification settings - Fork 131
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
Adding refactor code actions #1525
Comments
I tried to open a PR(#1526) for |
Hi @ziyeqf I really appreciate your suggestions but I think they each need some further discussion before we jump straight to implementing them.
Could you elaborate on the use case here and how this could be any different from simply selecting the block and hitting Backspace or Delete? One way of potentially making this valuable would be taking care of references to the block being deleted. However, I don't really know what that would look like as removing a reference could mean we end up with wildly incomplete configuration.
How is this different or better compared to completion, which provides snippets today? Is there a more specific use case you can describe?
I am not sure what would qualify as "unused parameter" in the context of a If an attribute is "unused" then it would typically be marked as deprecated by the provider - which is already being surfaced as a diagnostic today. Having some quickfixes to address deprecations would indeed be amazing but it's not simple as providers currently do not expose any more (structured) details about the meaning of a deprecation. i.e. all we know is that attribute is deprecated, we don't know if it's being replaced by another one or removed etc. I plan to file an issue to track deprecation quick fixes however, in spite of these known challenges.
This looks like a good idea but IMO we should be thinking about extraction of an expression, not an attribute (that it the right side after The only potential difficulty here is that this may be a lossy refactoring. We could retain the expression as part of variable Relatedly I think there's another action we could ticket out, which is extraction to a local value (entry under
I think I roughly understand the use case here but I'd like to confirm. Is the following what you mean? Original config resource "azurerm_app_service_environment" "name" {
name = "foo"
resource_group_name = "toot"
subnet_id = "noot" # Refactoring action triggered on subnet_id attribute name
} Refactored config resource "azurerm_app_service_environment" "example" {
name = "foo"
resource_group_name = "toot"
subnet_id = "noot"
}
output "subnet_id" {
value = azurerm_app_service_environment.example.subnet_id
} Side note: I am not entirely sure this would fall under the code action kind of
I'm afraid I don't understand the use case here. Could you elaborate a bit more on this one? Maybe try illustrating it via an example "before and after" as I did above. |
Thanks for your response @radeksimko. Here is my explaination:
As you said, it could help take care of references, and it might be useful in some other tools not only vscode or text editor. 2.create a block (provider/output/variable), acts like a snippetI thought it could pre-define some snippet, and accept customized snippet like:
and same as #1, it might be useful in other clients other than text editor. 3.show all unused parameters of a resource, ( to help users find which parameter they want to use in an editing)
|
1. delete a block I can imagine some scenarios with interactive UI letting the user resolve tricky situations but I still think it would be very hard to get right. I'd say that the existing validation which flags up orphaned references may be a good enough tool for this, especially once we expand the support as per #1364 If you still believe this is possible to solve via code action, feel free to raise a separate issue because I'm pretty sure this would be big enough problem to deserve its own. 2. create a block (provider/output/variable), acts like a snippet
I'm curious in what other contexts do you imagine such a code action in a language server to be useful? I can see the need for some semi-automated CLI-based refactoring tooling outside of LS. I would think of such tooling to be more standalone tooling not reliant on LSP at all. In fact I expect dependency in the other direction. i.e. one could create a CLI tool which e.g. generates TL;DR I think this should start out as a separate project/repo. 3. show all unused parameters of a resource I filed a separate issue to track this: 4. extract a property to a variable block I have created the following issues to track it:
5. extract a property to an output block I filed a separate issue to track this: 6. extract a property to reference another property in another resource I have much better understanding of what you mean now - thank you. I am not too sure about the value of such an action though. It feels like it would require quite a lot of interaction which seems relatively high cost (UX/time) given that the same could be achieved more easily and quickly with just typing and autocompletion. With all that in mind - thank you again for all these ideas, they will be very helpful in validating the interfaces and overall design of code actions in the context of I'm going to close this issue however in favour of the individual ones I linked above which should be more easily addressable once we have the interfaces in place. Similarly if you come up with other ideas for other code actions which aren't yet covered in our tracker you welcomed to open a new issue, preferably one per code action. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Language Server Version
v0.32.4
Problem Statement
want to add some code actions to the language server.
Attempted Solutions
No response
Proposal
terraform-ls only supports
source.formatAll.terraform
action for now.I'm planing to adding some code actions ( mainly about
refactor.extract.xxx
) to it.To help improve the editing experience. And also for our project which help editing(refactoring) terraform configuration files by those not familar with terraform. We have a basic (rough) list of actions we want to implement and want to discuss about them, some might not fit to be in the language server, I have marked them with ❓.
action list
variable
blockoutput
blockAny response would be appericiated.
Related LSP methods
References
No response
Help Wanted
Community Note
The text was updated successfully, but these errors were encountered: