Skip to content

Commit dcc045a

Browse files
committed
docs and small changes
1 parent cec4e54 commit dcc045a

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Completion/CabalFields.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ getModulesNames fields = map swap $ groupSort rawModuleTargetPairs
196196
getSectionModuleNames (Syntax.Section _ secArgs fields) = map (, getArgsName secArgs) $ concatMap getFieldModuleNames fields
197197
getSectionModuleNames _ = []
198198

199-
getArgsName [] = Nothing -- only a main library can have no name
200199
getArgsName [Syntax.SecArgName _ name] = Just $ T.decodeUtf8 name
201-
getArgsName _ = Nothing -- impossible to have multiple names for a build target
200+
getArgsName _ = Nothing -- Can be only a main library, that has no name
201+
-- since it's impossible to have multiple names for a build target
202202

203203
getFieldModuleNames field@(Syntax.Field _ modules) = if getFieldName field == T.pack "exposed-modules" ||
204204
getFieldName field == T.pack "other-modules"

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Definition.hs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ import System.FilePath (joinPath,
4646
takeDirectory,
4747
(<.>), (</>))
4848

49-
-- | CodeActions for going to definitions.
49+
-- | Handler for going to definitions.
5050
--
51-
-- Provides a CodeAction for going to the definition in a cabal file,
51+
-- Provides a handler for going to the definition in a cabal file,
5252
-- gathering all possible definitions by calling subfunctions.
5353

5454
-- TODO: Resolve more cases for go-to definition.
@@ -93,13 +93,10 @@ gotoCommonSectionDefinition
9393
-> Syntax.Position -- ^ Cursor position
9494
-> [Syntax.Field Syntax.Position] -- ^ Trimmed cabal AST on a cursor
9595
-> Maybe Definition
96-
gotoCommonSectionDefinition uri commonSections cursor fieldsOfInterest =
97-
case CabalFields.findTextWord cursor fieldsOfInterest of
98-
Nothing -> Nothing
99-
Just cursorText -> do
100-
case find (isSectionArgName cursorText) commonSections of
101-
Just commonSection -> Just $ Definition $ InL $ Location uri $ CabalFields.getFieldLSPRange commonSection
102-
Nothing -> Nothing
96+
gotoCommonSectionDefinition uri commonSections cursor fieldsOfInterest = do
97+
cursorText <- CabalFields.findTextWord cursor fieldsOfInterest
98+
commonSection <- find (isSectionArgName cursorText) commonSections
99+
Just $ Definition $ InL $ Location uri $ CabalFields.getFieldLSPRange commonSection
103100
where
104101
isSectionArgName name (Syntax.Section _ sectionArgName _) = name == CabalFields.onelineSectionArgs sectionArgName
105102
isSectionArgName _ _ = False
@@ -192,9 +189,13 @@ lookupBuildTargetPackageDescription (PackageDescription {..}) (Just buildTargetN
192189
then Just benchmarkBuildInfo
193190
else Nothing
194191

195-
-- | Converts a name of a module to a FilePath
196-
-- Warning: Makes a lot of assumptions and generally
197-
-- not advised to use.
192+
-- | Converts a name of a module to a FilePath.
193+
-- Is needed to guess the relative path to a file
194+
-- using the name of the module.
195+
-- We assume, that correct module naming is guaranteed.
196+
--
197+
-- Warning: Generally not advised to use, if there are
198+
-- better ways to get the path.
198199
--
199200
-- Examples: (output is system dependent)
200201
-- >>> toHaskellFile "My.Module.Lib"

0 commit comments

Comments
 (0)