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

Allow user specified code ranges through markers in the source #3073

Open
bonds opened this issue Aug 1, 2022 · 8 comments
Open

Allow user specified code ranges through markers in the source #3073

bonds opened this issue Aug 1, 2022 · 8 comments
Labels
can-workaround component: hls-code-range-plugin for code range related functionalities, such as selection range and folding range type: enhancement New feature or request

Comments

@bonds
Copy link

bonds commented Aug 1, 2022

Is your enhancement request related to a problem? Please describe.

I want to be able to collapse the long boilerplate of language pragma at the start of my cabal scripts.

Describe the solution you'd like

This block of code is foldable:

-- region "name of the region"
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
-- endregion

See also: https://code.visualstudio.com/docs/editor/codebasics#_folding

Describe alternatives you've considered

Continue to live without this feature. :)

Additional context

I filed a related feature request with the vscode extension: haskell/vscode-haskell#663. If it can be supported at the HLS level, that would be great for all editors, not just vscode, though I imagine there's some work that will need to be done in the extension to take advantage of the feature once it's added to HLS.

IMO this is a pretty low priority feature, but I thought I'd ask just so y'all know at least one person would use it. And in case I'm not the only person interested, it gives others a place find whatever the decision is. Please feel free to close the ticket if y'all aren't interested in implementing this...at least those who find their way to this ticket will be able to find that decision!

And thank you for your consideration and thank you for your contributions to this project, its great!

@fendor
Copy link
Collaborator

fendor commented Aug 2, 2022

Indeed and implementing it here sounds like a good first issue. It is a fair amount of work since the latest release of https://github.com/haskell/lsp/ doesn't seem to have the FoldingRange Request implemented

@kokobd
Copy link
Collaborator

kokobd commented Aug 7, 2022

VSCode already supports custom folding ranges in its latest version: https://code.visualstudio.com/updates/v1_70#_fold-selection.

LSP folding range is another thing. It allows us to provide Haskell-specific folding ranges instead of the default ones inferred from indentation. @sloorush is implementing it in #3058. We may consider to generate a folding range for adjacent pragmas

@kokobd
Copy link
Collaborator

kokobd commented Aug 7, 2022

In conclusion, we have nothing to do about custom folding ranges, as Language Server Protocol doesn't support it. I recommend converting the purpose of this issue to merging language pragmas in our upcoming folding range support.

@kokobd kokobd changed the title Add support for folding user specified regions Add a folding range for language pragmas Aug 7, 2022
@kokobd
Copy link
Collaborator

kokobd commented Aug 7, 2022

Ah, I somehow misunderstood the original intent. There are three features actually, in VSCode's terms:

  1. Manually creating/removing folding ranges on the fly. This is covered by vscode 1.70
  2. Folding range markers in source code. This should be handled by HLS.
  3. Automatic folding ranges for language pragmas. This should be handled by HLS. I will create another issue for that.

@kokobd kokobd changed the title Add a folding range for language pragmas Add support for user specified folding ranges through markers in source Aug 7, 2022
@kokobd kokobd changed the title Add support for user specified folding ranges through markers in source Allow user specified code ranges through markers in the source Aug 7, 2022
@kokobd kokobd added the component: hls-code-range-plugin for code range related functionalities, such as selection range and folding range label Aug 7, 2022
@michaelpj
Copy link
Collaborator

Folding range markers in source code. This should be handled by HLS.

We could do this, but I'm not sure if we should. I think the language server's job is to report folding ranges that make sense based on the language. Adding custom folding ranges specified by the user seems like it's probably the client's job.

@kokobd
Copy link
Collaborator

kokobd commented Aug 8, 2022

To clarify, the second feature mentioned is about adding markers to the source code, for example:

-- #region
myPortionOfCode :: Int
-- #endregion

And this is language dependent. We need to parse Haskell source code in all clients (VSCode, vim, emacs, etc), and make sure they behave the same, which is practically impossible to maintain in my view. And if different clients use different markers, that will lead to multiple markers co-existing in the source code.

Though, the analysis above makes sense only if range makers do. Would some teams allow submitting these markers to version control? People do submit something like @SupressWarning to inform linters to my knowledge.

@kokobd
Copy link
Collaborator

kokobd commented Sep 16, 2022

2. Folding range markers in source code. This should be handled by HLS.

I came across this extension in the VSCode marketplace: Explicit Folding

@bonds
Copy link
Author

bonds commented Sep 16, 2022

I came across this extension in the VSCode marketplace: Explicit Folding

Nice find! Thanks for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can-workaround component: hls-code-range-plugin for code range related functionalities, such as selection range and folding range type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants