@@ -6,26 +6,16 @@ import Control.Monad (filterM)
6
6
import Control.Monad.Extra (concatForM ,
7
7
forM )
8
8
import Data.List (stripPrefix )
9
- import qualified Data.List as List
10
9
import Data.Maybe (fromMaybe )
11
10
import qualified Data.Text as T
12
- import Distribution.PackageDescription (Benchmark (.. ),
13
- BuildInfo (.. ),
14
- CondTree (condTreeData ),
15
- Executable (.. ),
16
- GenericPackageDescription (.. ),
17
- Library (.. ),
18
- UnqualComponentName ,
19
- mkUnqualComponentName ,
20
- testBuildInfo )
21
- import Distribution.Utils.Path (getSymbolicPath )
11
+ import Distribution.PackageDescription (GenericPackageDescription )
22
12
import Ide.Logger (Priority (.. ),
23
13
Recorder ,
24
14
WithPriority ,
25
15
logWith )
26
- import Ide.Plugin.Cabal.Completion.Completer.FilePath (PathCompletionInfo (.. ),
27
- listFileCompletions ,
16
+ import Ide.Plugin.Cabal.Completion.Completer.FilePath (listFileCompletions ,
28
17
mkCompletionDirectory )
18
+ import Ide.Plugin.Cabal.Completion.Completer.Paths
29
19
import Ide.Plugin.Cabal.Completion.Completer.Simple
30
20
import Ide.Plugin.Cabal.Completion.Completer.Types
31
21
import Ide.Plugin.Cabal.Completion.Types
@@ -53,56 +43,6 @@ modulesCompleter extractionFunction recorder cData = do
53
43
sName = stanzaName cData
54
44
prefInfo = cabalPrefixInfo cData
55
45
56
- -- | Extracts the source directories of the library stanza.
57
- sourceDirsExtractionLibrary :: Maybe StanzaName -> GenericPackageDescription -> [FilePath ]
58
- sourceDirsExtractionLibrary Nothing gpd =
59
- -- we use condLibrary to get the information contained in the library stanza
60
- -- since the library in PackageDescription is not populated by us
61
- case libM of
62
- Just lib -> do
63
- map getSymbolicPath $ hsSourceDirs $ libBuildInfo $ condTreeData lib
64
- Nothing -> []
65
- where
66
- libM = condLibrary gpd
67
- sourceDirsExtractionLibrary name gpd = extractRelativeDirsFromStanza name gpd condSubLibraries libBuildInfo
68
-
69
- -- | Extracts the source directories of the executable stanza with the given name.
70
- sourceDirsExtractionExecutable :: Maybe StanzaName -> GenericPackageDescription -> [FilePath ]
71
- sourceDirsExtractionExecutable name gpd = extractRelativeDirsFromStanza name gpd condExecutables buildInfo
72
-
73
- -- | Extracts the source directories of the test suite stanza with the given name.
74
- sourceDirsExtractionTestSuite :: Maybe StanzaName -> GenericPackageDescription -> [FilePath ]
75
- sourceDirsExtractionTestSuite name gpd = extractRelativeDirsFromStanza name gpd condTestSuites testBuildInfo
76
-
77
- -- | Extracts the source directories of benchmark stanza with the given name.
78
- sourceDirsExtractionBenchmark :: Maybe StanzaName -> GenericPackageDescription -> [FilePath ]
79
- sourceDirsExtractionBenchmark name gpd = extractRelativeDirsFromStanza name gpd condBenchmarks benchmarkBuildInfo
80
-
81
- -- | Takes a possible stanza name, a GenericPackageDescription,
82
- -- a function to access the stanza information we are interested in
83
- -- and a function to access the build info from the specific stanza.
84
- --
85
- -- Returns a list of relative source directory paths specified for the extracted stanza.
86
- extractRelativeDirsFromStanza ::
87
- Maybe StanzaName ->
88
- GenericPackageDescription ->
89
- (GenericPackageDescription -> [(UnqualComponentName , CondTree b c a )]) ->
90
- (a -> BuildInfo ) ->
91
- [FilePath ]
92
- extractRelativeDirsFromStanza Nothing _ _ _ = []
93
- extractRelativeDirsFromStanza (Just name) gpd getStanza getBuildInfo
94
- | Just stanza <- stanzaM = map getSymbolicPath $ hsSourceDirs $ getBuildInfo stanza
95
- | otherwise = []
96
- where
97
- stanzaM = fmap (condTreeData . snd ) res
98
- allStanzasM = getStanza gpd
99
- res =
100
- List. find
101
- ( \ (n, _) ->
102
- n == mkUnqualComponentName (T. unpack name)
103
- )
104
- allStanzasM
105
-
106
46
-- | Takes a list of source directories and returns a list of path completions
107
47
-- relative to any of the passed source directories which fit the passed prefix info.
108
48
filePathsForExposedModules :: Recorder (WithPriority Log ) -> [FilePath ] -> CabalPrefixInfo -> IO [T. Text ]
@@ -111,34 +51,36 @@ filePathsForExposedModules recorder srcDirs prefInfo = do
111
51
srcDirs
112
52
( \ dir' -> do
113
53
let dir = FP. normalise dir'
114
- let pInfo =
115
- PathCompletionInfo
116
- { isStringNotationPath = Nothing ,
117
- pathSegment = T. pack $ FP. takeFileName prefix,
118
- queryDirectory = FP. addTrailingPathSeparator $ FP. takeDirectory prefix,
119
- workingDirectory = completionWorkingDir prefInfo FP. </> dir
120
- }
121
- completions <- listFileCompletions recorder pInfo
122
- validExposedCompletions <- filterM (isValidExposedModulePath pInfo) completions
123
- let toMatch = pathSegment pInfo
124
- scored = Fuzzy. simpleFilter Fuzzy. defChunkSize Fuzzy. defMaxResults toMatch (map T. pack validExposedCompletions)
54
+ pathInfo = pathCompletionInfoFromCabalPrefixInfo dir modPrefInfo
55
+ completions <- listFileCompletions recorder pathInfo
56
+ validExposedCompletions <- filterM (isValidExposedModulePath pathInfo) completions
57
+ let toMatch = pathSegment pathInfo
58
+ scored = Fuzzy. simpleFilter
59
+ Fuzzy. defChunkSize
60
+ Fuzzy. defMaxResults
61
+ toMatch
62
+ (map T. pack validExposedCompletions)
125
63
forM
126
64
scored
127
65
( \ compl' -> do
128
66
let compl = Fuzzy. original compl'
129
- fullFilePath <- mkExposedModulePathCompletion pInfo $ T. unpack compl
67
+ fullFilePath <- mkExposedModulePathCompletion pathInfo $ T. unpack compl
130
68
pure fullFilePath
131
69
)
132
70
)
133
71
where
134
72
prefix =
135
- exposedModulePathToFp $
73
+ T. pack $ exposedModulePathToFp $
136
74
completionPrefix prefInfo
137
- -- \| Takes a PathCompletionInfo and a path segment and checks whether
75
+ -- build completion info relative to the source dir,
76
+ -- we overwrite the prefix written in the cabal file with its translation
77
+ -- to filepath syntax, since it is in exposed module syntax
78
+ modPrefInfo = prefInfo{completionPrefix= prefix}
79
+
80
+ -- Takes a PathCompletionInfo and a path segment and checks whether
138
81
-- the path segment can be completed for an exposed module.
139
82
--
140
83
-- This is the case if the segment represents either a directory or a Haskell file.
141
- --
142
84
isValidExposedModulePath :: PathCompletionInfo -> FilePath -> IO Bool
143
85
isValidExposedModulePath pInfo path = do
144
86
let dir = mkCompletionDirectory pInfo
0 commit comments