haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.61k stars 351 forks source link

Cabal plugin outline view #4323

Open VenInf opened 1 week ago

VenInf commented 1 week ago

This is an attempt to solve an issue #4282. It adds an Outline for the cabal files.

Implementation details

Using runIdeAction we get parsed cabal fields with positions of the keywords.

This can be transformed with a series of functions to the DocumentSymbol. It is returned, and the moduleOutline can be plugged in to the cabal descriptor.

What is not implemented / any issues.

VeryMilkyJoe commented 1 week ago

Thank you for working on this feature, it seems like a great addition to the plugin! Could you add a screenshot of what the feature looks like in action?

VenInf commented 1 week ago

Thank you for working on this feature, it seems like a great addition to the plugin! Could you add a screenshot of what the feature looks like in action?

Yes, sure. There is how the outline looks for haskell-language-server.cabal file and simple.cabal file from cabal plugin tests. hls_cabal_outline_screenshot simple_cabal_outline_sway-screenshot

VeryMilkyJoe commented 1 week ago

I was trying out the feature, it looks like a great start! But, I think there is some unwanted behaviour here. Firstly, I think it would be less overwhelming to only see the parents in the outline by default, with everything else collapsed. Secondly, I think it would be easier to use the outline if the names of stanzas were part of the respective elements instead of being a child. Also, I think the if conditions are not grouped correctly as can be seen below. image

VeryMilkyJoe commented 1 week ago

I think, it could also make sense to not show leaf values in the outline at all? Specifically for long descriptions or exposed-modules content, the text becomes rather long.

VenInf commented 1 week ago

I was trying out the feature, it looks like a great start! But, I think there is some unwanted behaviour here. Firstly, I think it would be less overwhelming to only see the parents in the outline by default, with everything else collapsed.

I thought that this will be an easy fix, but it looks like that it's unclear, who can provide such settings. It certanly can be done manualy, but I can't tell if it's possible to do by default. I will look into it, but I will be glad to hear any ideas for a soltion.

Secondly, I think it would be easier to use the outline if the names of stanzas were part of the respective elements instead of being a child. Also, I think the if conditions are not grouped correctly as can be seen below.

Right now the outline displays the cabal's AST without any modifications. I think it will be nice to see the if statements in one line, and looks like it can be done by jamming all SectionArgs on one level in one DocumentSymbol. I will test this.

VenInf commented 1 week ago

I think, it could also make sense to not show leaf values in the outline at all? Specifically for long descriptions or exposed-modules content, the text becomes rather long.

At least for me it's not obvious, what data should be displayed, and what omitted. As far as I can tell, it can be independent with the depth in the cabal's AST.

I think a collapsed outline would solve this issue as well.

michaelpj commented 1 week ago

I don't think we have any control over whether or not the outline is expanded or not.

At least for me it's not obvious, what data should be displayed, and what omitted.

As I understand it, the outline view is generally used for navigation between named entities in the file. So I definitely don't think we should be including the values of fields, that's quite odd.

I think having the top-level field names is probably useful, in that it allows jumping to them, but I think it would be nice to group them in a "top-level stanza" element, perhaps?

VenInf commented 1 week ago

Fixed some minor issues, and hopefully solved the problem with displaying values of the fields. Also now the Section and SectionArgs are displayed in one line. For example source-repository head and if impl(ghc >= 9.8)

cabal_outline_ifs_oneline_sway-screenshot

VeryMilkyJoe commented 1 week ago

Fixed some minor issues, and hopefully solved the problem with displaying values of the fields. Also now the Section and SectionArgs are displayed in one line. For example source-repository head and if impl(ghc >= 9.8)

cabal_outline_ifs_oneline_sway-screenshot

This looks great!

VeryMilkyJoe commented 1 week ago

To fix the pre-commit failing, you will want to run the stylish haskell formatter on your code, especially the imports.

VenInf commented 1 week ago

Once the functionality will be set I will implement the tests.

VenInf commented 5 days ago

The tests are now implemented as well.