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

Issue with running the source.formatAll.terraform-ls code action on save #679

Closed
rchl opened this issue Oct 18, 2021 · 3 comments · Fixed by #680
Closed

Issue with running the source.formatAll.terraform-ls code action on save #679

rchl opened this issue Oct 18, 2021 · 3 comments · Fixed by #680
Labels
bug Something isn't working textDocument/codeAction

Comments

@rchl
Copy link

rchl commented Oct 18, 2021

I've only got around to testing the #327 feature now and noticed that the behavior doesn't seem to be as expected in regards to the kind sent in the response. If the client is asking for the source.formatAll.terraform-ls kind then that is the kind that should also be included in the response, otherwise the client will ignore the response (at least ST implementation but I'm fairly certain that VSCode would do the same).

Server Version

0.23.0

Terraform Version

Terraform v1.0.4
on darwin_amd64

Client Version

Sublme Text 4

Terraform Configuration Files

variable "spin_autoscaling_config" {
  type = map(number)
  default = {
    target_value         = 40,
    scaleout_cooldown = 60,
    scalein_cooldown  = 120,
  }
}

Log Output

textDocument/codeAction Request:

{
  "context": {
    "diagnostics": [],
    "only": [
      "source.formatAll.terraform-ls"
    ]
  },
  "range": {
    "end": {
      "character": 0,
      "line": 8
    },
    "start": {
      "character": 0,
      "line": 0
    }
  },
  "textDocument": {
    "uri": "file:///Users/rafal/xxx/app.tf"
  }
}

textDocument/codeAction Response:

[
  {
    "edit": {
      "changes": {
        "file:///Users/rafal/xxx/app.tf": [
          {
            "newText": "    target_value      = 40,\n",
            "range": {
              "end": {
                "character": 0,
                "line": 4
              },
              "start": {
                "character": 0,
                "line": 3
              }
            }
          }
        ]
      }
    },
    "kind": "source.fixAll",
    "title": "Format Document"
  }
]

Expected Behavior

The response includes the source.formatAll.terraform-ls kind.
The document is formatted.

Actual Behavior

The response includes the source.fixAll kind.
The document is not formatted.

Steps to Reproduce

  1. Add source.formatAll.terraform-ls to the list of code actions triggered on save (done differently depending on the editor of choice)
  2. Trigger save with the hcl above
@radeksimko radeksimko added the bug Something isn't working label Oct 18, 2021
@radeksimko
Copy link
Member

Thanks for trying it out and for the report @rchl

@jpogran I think this is the bug you mentioned to me last week?

@jpogran
Copy link
Contributor

jpogran commented Oct 18, 2021

Yes, part of it. This particular part comes from https://github.com/hashicorp/terraform-ls/blob/main/internal/langserver/handlers/code_action.go#L64, from when I misunderstood the spec. I thought you were supposed to return what code action was 'resolved', because any of source.fixAll, source.formatAll, or source.formatAll.terraform-ls currently were the same action.

Will be able to fix this alongside the case of returning 4 actions instead of 1.

@github-actions
Copy link

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.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working textDocument/codeAction
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants