@@ -65,6 +65,10 @@ import Distribution.PackageDescription (Benchmark (..),
65
65
library ,
66
66
unUnqualComponentName )
67
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
72
69
73
data Log
70
74
= LogModificationTime NormalizedFilePath FileVersion
@@ -325,23 +329,25 @@ gotoDefinition ideState _ msgParam = do
325
329
let mModuleNames = CabalFields. getModulesNames <$> mCabalFields
326
330
mModuleName = find (isModuleName cursorText) =<< mModuleNames
327
331
case mModuleName of
328
- Nothing -> traceShowM ( " NOT A MODULE " )
332
+ Nothing -> pure $ InR $ InR Null
329
333
Just (mBuildTargetNames, moduleName) -> do
330
- traceShowM (" IS A MODULE" , moduleName, " at" , mBuildTargetNames)
331
334
mGPD <- liftIO $ runAction " cabal.GPD" ideState $ useWithStale ParseCabalFile $ toNormalizedFilePath filePath
332
335
case mGPD of
333
- Nothing -> traceShowM ( " failed to get GPD " )
336
+ Nothing -> pure $ InR $ InR Null
334
337
Just (gpd, _) -> do
335
- let debug = map (lookupBuildTargetPackageDescription
336
- (flattenPackageDescription gpd))
337
- mBuildTargetNames
338
- traceShowM (" debug is" , debug)
339
338
let buildInfos = foldMap (lookupBuildTargetPackageDescription
340
339
(flattenPackageDescription gpd))
341
340
mBuildTargetNames
342
- traceShowM (" buildInfos is" , buildInfos)
343
- traceShowM (" Found hsSourceDirs" , map hsSourceDirs buildInfos)
344
- pure $ InR $ InR Null
341
+ sourceDirs = map getSymbolicPath $ concatMap hsSourceDirs buildInfos
342
+ potentialPaths = map (\ dir -> takeDirectory filePath </> dir </> toHaskellFile moduleName) sourceDirs
343
+ traceShowM (" potentialPaths" , potentialPaths)
344
+ allPaths <- liftIO $ filterM doesFileExist potentialPaths
345
+ traceShowM (" allPaths" , allPaths)
346
+ 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
350
+ Just location -> pure $ InL $ Definition $ InL location
345
351
where
346
352
cursor = Types. lspPositionToCabalPosition (msgParam ^. JL. position)
347
353
uri = msgParam ^. JL. textDocument . JL. uri
@@ -390,6 +396,10 @@ gotoDefinition ideState _ msgParam = do
390
396
if T. pack (unUnqualComponentName benchmarkName) == buildTargetName
391
397
then Just benchmarkBuildInfo
392
398
else Nothing
399
+
400
+ toHaskellFile :: T. Text -> FilePath
401
+ toHaskellFile moduleName = foldl1 (</>) (map T. unpack $ T. splitOn " ." moduleName) ++ " .hs"
402
+
393
403
-- ----------------------------------------------------------------
394
404
-- Cabal file of Interest rules and global variable
395
405
-- ----------------------------------------------------------------
0 commit comments