@@ -32,7 +32,20 @@ import Development.IDE.Graph (Key,
32
32
import qualified Development.IDE.Plugin.Completions.Logic as Ghcide
33
33
import Development.IDE.Types.Shake (toKey )
34
34
import qualified Distribution.Fields as Syntax
35
+ import Distribution.PackageDescription (Benchmark (.. ),
36
+ BuildInfo (.. ),
37
+ Executable (.. ),
38
+ ForeignLib (.. ),
39
+ Library (.. ),
40
+ LibraryName (LMainLibName , LSubLibName ),
41
+ PackageDescription (.. ),
42
+ TestSuite (.. ),
43
+ library ,
44
+ unUnqualComponentName )
45
+ import Distribution.PackageDescription.Configuration (flattenPackageDescription )
35
46
import qualified Distribution.Parsec.Position as Syntax
47
+ import Distribution.Utils.Generic (safeHead )
48
+ import Distribution.Utils.Path (getSymbolicPath )
36
49
import GHC.Generics
37
50
import Ide.Plugin.Cabal.Completion.CabalFields as CabalFields
38
51
import qualified Ide.Plugin.Cabal.Completion.Completer.Types as CompleterTypes
@@ -52,23 +65,9 @@ import qualified Language.LSP.Protocol.Lens as JL
52
65
import qualified Language.LSP.Protocol.Message as LSP
53
66
import Language.LSP.Protocol.Types
54
67
import qualified Language.LSP.VFS as VFS
55
-
56
- import Debug.Trace
57
- import Distribution.PackageDescription (Benchmark (.. ),
58
- BuildInfo (.. ),
59
- Executable (.. ),
60
- ForeignLib (.. ),
61
- Library (.. ),
62
- LibraryName (LMainLibName , LSubLibName ),
63
- PackageDescription (.. ),
64
- TestSuite (.. ),
65
- library ,
66
- unUnqualComponentName )
67
- import Distribution.PackageDescription.Configuration (flattenPackageDescription )
68
- import Distribution.Utils.Path (getSymbolicPath )
69
- import System.Directory (doesFileExist )
70
- import System.FilePath ((</>) , takeDirectory )
71
- import Distribution.Utils.Generic (safeHead )
68
+ import System.Directory (doesFileExist )
69
+ import System.FilePath (takeDirectory ,
70
+ (</>) )
72
71
73
72
data Log
74
73
= LogModificationTime NormalizedFilePath FileVersion
@@ -302,11 +301,12 @@ fieldSuggestCodeAction recorder ide _ (CodeActionParams _ _ (TextDocumentIdentif
302
301
303
302
-- | CodeActions for going to definitions.
304
303
--
305
- -- Provides a CodeAction for going to a definition when clicking on an identifier.
304
+ -- Provides a CodeAction for going to a definition when clicking on an identifier
305
+ -- and clicking on exposed-module or other-module field.
306
306
-- The definition is found by traversing the sections and comparing their name to
307
- -- the clicked identifier.
307
+ -- the clicked identifier. If it's not in sections it attempts to find it in module names.
308
308
--
309
- -- TODO: Support more definitions than sections .
309
+ -- TODO: Resolve more cases for go-to definition .
310
310
gotoDefinition :: PluginMethodHandler IdeState LSP. Method_TextDocumentDefinition
311
311
gotoDefinition ideState _ msgParam = do
312
312
case uriToFilePath' uri of
@@ -340,13 +340,10 @@ gotoDefinition ideState _ msgParam = do
340
340
mBuildTargetNames
341
341
sourceDirs = map getSymbolicPath $ concatMap hsSourceDirs buildInfos
342
342
potentialPaths = map (\ dir -> takeDirectory filePath </> dir </> toHaskellFile moduleName) sourceDirs
343
- traceShowM (" potentialPaths" , potentialPaths)
344
343
allPaths <- liftIO $ filterM doesFileExist potentialPaths
345
- traceShowM (" allPaths" , allPaths)
346
344
let locations = map (\ pth -> Location (filePathToUri pth) (mkRange 0 0 0 0 )) allPaths
347
- traceShowM (" locations" , locations)
348
- case safeHead locations of
349
- Nothing -> pure $ InR $ InR Null
345
+ case safeHead locations of -- We assume there could be only one source location
346
+ Nothing -> pure $ InR $ InR Null
350
347
Just location -> pure $ InL $ Definition $ InL location
351
348
where
352
349
cursor = Types. lspPositionToCabalPosition (msgParam ^. JL. position)
0 commit comments