Skip to content

Add Goto Definition for cabal common sections#4375

Merged
fendor merged 4 commits into
haskell:masterfrom
ChristophHochrainer:feature/cabal/import-go-to-definition
Aug 18, 2024
Merged

Add Goto Definition for cabal common sections#4375
fendor merged 4 commits into
haskell:masterfrom
ChristophHochrainer:feature/cabal/import-go-to-definition

Conversation

@ChristophHochrainer

Copy link
Copy Markdown
Contributor

This PR is the start of a go to definition code action for cabal files.

Screenshot-2024-08-03-17-37-28

@fendor

fendor commented Aug 4, 2024

Copy link
Copy Markdown
Collaborator

@VenInf I think this PR is relevant to you as well and might be implementing some util functions you could benefit from as well. Could you review this PR?

@fendor fendor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

This looks very nice, just a couple of tests missing, then this is good to merge :)

Comment on lines +292 to +295
case uriToFilePath' uri of
Nothing ->
pure $ InR $ InR Null
Just filePath -> do

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer getNormalizedFilePathE which takes care of the validation.

Suggested change
case uriToFilePath' uri of
Nothing ->
pure $ InR $ InR Null
Just filePath -> do
nfp <- getNormalizedFilePathE uri

Then use fromNormalizedFilePath if you need the underlying FilePath.

@@ -1,12 +1,16 @@
module Ide.Plugin.Cabal.Completion.CabalFields (findStanzaForColumn, findFieldSection, getOptionalSectionName, getAnnotation, getFieldName, onelineSectionArgs) where
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
module Ide.Plugin.Cabal.Completion.CabalFields (findStanzaForColumn, findFieldSection, findTextWord, findFieldLine, getOptionalSectionName, getAnnotation, getFieldName, onelineSectionArgs, getFieldEndPosition, getSectionArgEndPosition, getNameEndPosition, getFieldLineEndPosition, getFieldLSPRange) where

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am amazed stylish-haskell accepts this.

Would you mind introducing a couple of new lines to make this easier to read? E.g.

Suggested change
module Ide.Plugin.Cabal.Completion.CabalFields (findStanzaForColumn, findFieldSection, findTextWord, findFieldLine, getOptionalSectionName, getAnnotation, getFieldName, onelineSectionArgs, getFieldEndPosition, getSectionArgEndPosition, getNameEndPosition, getFieldLineEndPosition, getFieldLSPRange) where
module Ide.Plugin.Cabal.Completion.CabalFields
( findStanzaForColumn,
findFieldSection,
findTextWord,
...
) where

or something like that?

@@ -1,12 +1,16 @@
module Ide.Plugin.Cabal.Completion.CabalFields (findStanzaForColumn, findFieldSection, getOptionalSectionName, getAnnotation, getFieldName, onelineSectionArgs) where
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}

Looks unused?

import qualified Distribution.Fields as Syntax
import qualified Distribution.Parsec.Position as Syntax
import Ide.Plugin.Cabal.Completion.Types
import qualified Language.LSP.Protocol.Types as LSPTypes

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick:

Suggested change
import qualified Language.LSP.Protocol.Types as LSPTypes
import qualified Language.LSP.Protocol.Types as LSP

Other parts of the codebase use this qualified import. Perhaps we should have some kind of style guide? Hard to tell.

Comment on lines +78 to +80
-- that are not a space or column.

-- This function currently only considers words inside of a @FieldLine@.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-- that are not a space or column.
-- This function currently only considers words inside of a @FieldLine@.
-- that are not a space or column.
--
-- This function currently only considers words inside of a @FieldLine@.

Otherwise, the haddock comment will not be attached to the function :)

@VenInf

VenInf commented Aug 4, 2024

Copy link
Copy Markdown
Contributor

Thank you for your work!
The tools do indeed, look very handy.

The only comment I might have, is that I thought about mimicking
the approach used in the HoverDefinition.hs for the hovers/go-to definitions,
but this approach looks more practical, in some sense.

@VeryMilkyJoe VeryMilkyJoe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice feature and the code looks great, thanks!
I think once we get some tests, we're ready to merge 🥳

Comment thread plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Completion/CabalFields.hs Outdated
Comment thread plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs Outdated
@VenInf VenInf mentioned this pull request Aug 14, 2024
4 tasks
@ChristophHochrainer
ChristophHochrainer force-pushed the feature/cabal/import-go-to-definition branch from 62972ef to 8f164e2 Compare August 17, 2024 21:22
@ChristophHochrainer
ChristophHochrainer force-pushed the feature/cabal/import-go-to-definition branch from 8f164e2 to c2d980c Compare August 17, 2024 21:24
@ChristophHochrainer

Copy link
Copy Markdown
Contributor Author

Thank you all for your feedback!

I made the requested changes and added some tests. (Thanks @fendor for the short introduction)
I also included the requested hie.yaml for the test data requested by @fendor. :)

@ChristophHochrainer
ChristophHochrainer force-pushed the feature/cabal/import-go-to-definition branch from e35a426 to d0d0f94 Compare August 18, 2024 06:39

@fendor fendor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, awesome, thank you very much!

@fendor
fendor requested review from VenInf and VeryMilkyJoe August 18, 2024 08:33
@fendor fendor changed the title Add code action for cabal go to definition Add Goto Definition for cabal common sections Aug 18, 2024
@fendor
fendor merged commit 6f6f75b into haskell:master Aug 18, 2024
VenInf pushed a commit to VenInf/haskell-language-server that referenced this pull request Aug 18, 2024
* Add goto-definitions for cabal common sections

* Add default direct cradle hie.yaml file to testdata

* incorporate changes requested in haskell#4375

* add tests for cabal goto-definition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants