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

Add Goto Definition for cabal common sections #4375

Conversation

ChristophHochrainer
Copy link
Contributor

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

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

@fendor
Copy link
Collaborator

fendor commented Aug 4, 2024

@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?

Copy link
Collaborator

@fendor fendor left a comment

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
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
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
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 Data.List.NonEmpty (NonEmpty)
import qualified Data.List.NonEmpty as NE
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
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
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
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
Copy link
Contributor

VenInf commented Aug 4, 2024

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.

Copy link
Collaborator

@VeryMilkyJoe VeryMilkyJoe left a comment

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 🥳

@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
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
Copy link
Collaborator

@fendor fendor left a comment

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 VeryMilkyJoe and VenInf 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
30 of 36 checks passed
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