hashicorp / terraform-ls

Terraform Language Server
Mozilla Public License 2.0
996 stars 131 forks source link

Support folding ranges #105

Open paultyng opened 4 years ago

paultyng commented 4 years ago

https://microsoft.github.io/language-server-protocol/specification#textDocument_foldingRange

There are generally three "kinds" of foldable ranges that LSP supports natively:

In order to support folding of comments we'd need the upstream HCL parser to return comments in the first place, these are currently ignored.

Imports could either be interpreted as required_providers block, or just not reported at all.

We can also report any additional kinds as the kind in the protocol spec is technically just string. For example gopls chooses to report all kinds of foldable ranges, such as function calls, struct declarations, switch case statements etc.: https://github.com/golang/tools/blob/8c34cc9cafff8f13c3f3ed95a11de309752c1c60/internal/lsp/source/folding_range.go#L68-L128

It is unclear however how any custom kinds would be surfaced to the user and whether a custom kind (as opposed to just empty string, like gopls uses) is even useful in practice.

amasover commented 4 years ago

Apologies as I'm not too familiar with the LSP spec. Would this allow collapsing/expanding blocks, e.g., resource blocks, etc? If so, pretty cool!

paultyng commented 4 years ago

@amasover yep, exactly. I'd imagine the simplistic initial implementation will just be folding of root level blocks (resource, provider, data, variable, output, module, local, terraform, etc.).

PePoDev commented 3 years ago

@paultyng I have try with this, But not working.

#region test
variable "test" {
  type        = bool
  default     = true
}
#endregion
jpogran commented 3 years ago

@PePoDev we haven't implemented region folding yet. When we do you'll see a PR and a line item in our changelog

aleqsss commented 2 years ago

Hi,

I'm also interested in region folding, any news in regards of this? πŸ™‚πŸ€ž

dbanck commented 2 years ago

Hi @aleqsss,

Sorry, but there hasn't been any progress on this. We are currently planning our roadmap for the first quarter, and it's already full of other issues we need to address. So at this point, it's tough for me to say when we can work on folding ranges.

aleqsss commented 2 years ago

Understood, and thank you for the information!

garsiv1932 commented 7 months ago

Hello, is this feature implemented?

dbanck commented 7 months ago

@garsiv1932 Sorry, but we haven't implemented region folding yet

garsiv1932 commented 7 months ago

Is it too difficult?

jpogran commented 7 months ago

Hey @garsiv1932 , just to clarify region folding support was implemented in the Terraform VS Code extension in https://github.com/hashicorp/vscode-terraform/pull/924, so if you do want to use them now we do support them. If you use another editor, that has not been planned yet.

garsiv1932 commented 7 months ago

Hey @garsiv1932 , just to clarify region folding support was implemented in the Terraform VS Code extension in hashicorp/vscode-terraform#924, so if you do want to use them now we do support them. If you use another editor, that has not been planned yet.

And how is the syntax, because i tried to put # regiion and #endRegion and didnt work.

Can You post the link of the vscode plugin too, only yo clarify if i AM using the dame one.

jpogran commented 7 months ago

You can find our extension in the VS Code Marketplace or in the VS Code Extensions bar by typing 'hashicorp'.

The syntax is #region and #endregion:

https://github.com/hashicorp/terraform-ls/assets/272569/76881b3d-a5af-45bc-a196-28001088d5cf

garsiv1932 commented 7 months ago

I had a conflict on my extensions, is working right now.

artemudovyk commented 2 months ago

The syntax is #region and #endregion:

Sorry for nitpicking, but why are version with whitespace # region and # endregion not supported? image

The format you mentioned is working fine though: image

rcjsuen commented 1 month ago

The syntax is #region and #endregion:

Sorry for nitpicking, but why are version with whitespace # region and # endregion not supported?

@artemudovyk Is this still a problem for you? It seems to be working for me

image
artemudovyk commented 1 month ago

@artemudovyk Is this still a problem for you? It seems to be working for me

Yeah, it's still the same for me.

rcjsuen commented 1 month ago

Yeah, it's still the same for me.

I see the difference now. I was using v0.2.5 of 4ops.terraform. Indeed, if I use v2.32.3 of HashiCorp.terraform then it doesn't work. πŸ‘