@@ -92,11 +92,11 @@ contextToCompleter :: Context -> Completer
92
92
-- if we are in the top level of the cabal file and not in a keyword context,
93
93
-- we can write any top level keywords or a stanza declaration
94
94
contextToCompleter (TopLevel , None ) =
95
- constantCompleter $ Map. keys (cabalKeywords <> cabalVersionKeyword ) ++ Map. keys stanzaKeywordMap
95
+ constantCompleter $ Map. keys (cabalVersionKeyword <> cabalKeywords ) ++ Map. keys stanzaKeywordMap
96
96
-- if we are in a keyword context in the top level,
97
97
-- we look up that keyword in the top level context and can complete its possible values
98
98
contextToCompleter (TopLevel , KeyWord kw) =
99
- case Map. lookup kw (cabalKeywords <> cabalVersionKeyword ) of
99
+ case Map. lookup kw (cabalVersionKeyword <> cabalKeywords ) of
100
100
Nothing -> noopCompleter
101
101
Just l -> l
102
102
-- if we are in a stanza and not in a keyword context,
@@ -290,16 +290,20 @@ filePathCompleter ctx = do
290
290
fullFilePath <- makeFullFilePath suffix compl complInfo
291
291
pure $ makeCabalCompletionItem (completionRange ctx) fullFilePath fullFilePath
292
292
)
293
-
294
- where
295
- -- | Takes a suffix and a text and returns filepath with the suffix
296
- makeFullFilePath :: T. Text -> T. Text -> PathCompletionInfo -> IO T. Text
297
- makeFullFilePath suffix' completion' complInfo = do
298
- let fullPath' = prefixPathInfo complInfo Posix. </> T. unpack completion'
299
- isFilePath <- doesFileExist fullPath'
300
- let fullPath = if isFilePath then fullPath' ++ T. unpack suffix' else fullPath'
301
- pure $ T. pack fullPath
302
-
293
+ where
294
+ -- | Takes a suffix, a completed path and a pathCompletionInfo and
295
+ -- generates the whole filepath including the already written prefix
296
+ -- and the suffix in case the completed path is a filepath
297
+ makeFullFilePath :: T. Text -> T. Text -> PathCompletionInfo -> IO T. Text
298
+ makeFullFilePath suffix' completion' complInfo = do
299
+ let fullPath' = prefixPathInfo complInfo Posix. </> T. unpack completion'
300
+ isFilePath <- doesFileExist fullPath'
301
+ let fullPath = if isFilePath then fullPath' ++ T. unpack suffix' else fullPath'
302
+ pure $ T. pack fullPath
303
+
304
+ {- | Takes a path completion info and returns the list of files
305
+ in the directory the path completion info describes
306
+ -}
303
307
listFileCompletions :: PathCompletionInfo -> IO [FilePath ]
304
308
listFileCompletions complInfo = do
305
309
try (evaluate =<< listDirectory (mkCompletionDirectory complInfo)) >>= \ case
@@ -313,6 +317,9 @@ listFileCompletions complInfo = do
313
317
pure fixedDirs
314
318
Left (_:: IOError ) -> pure []
315
319
320
+ {- | Returns a list of all directories in the directory
321
+ described by path completion info
322
+ -}
316
323
listDirectoryCompletions :: PathCompletionInfo -> IO [FilePath ]
317
324
listDirectoryCompletions complInfo = do
318
325
filepaths <- listFileCompletions complInfo
@@ -327,7 +334,21 @@ directoryCompleter ctx = do
327
334
let complInfo = pathCompletionInfoFromCompletionContext ctx
328
335
directoryCompletions <- listDirectoryCompletions complInfo
329
336
let scored = Fuzzy. simpleFilter 1000 10 (prefixLeftOver complInfo) (map T. pack directoryCompletions)
330
- pure $ map (makeSimpleCabalCompletionItem (completionRange ctx) . Fuzzy. original) scored
337
+ forM
338
+ scored
339
+ ( \ compl' -> do
340
+ let compl = Fuzzy. original compl'
341
+ fullDirPath <- makeFullDirPath compl complInfo
342
+ pure $ makeCabalCompletionItem (completionRange ctx) fullDirPath fullDirPath
343
+ )
344
+ where
345
+ -- | Takes a directory and PathCompletionInfo and
346
+ -- returns the whole path including the prefix that was already written
347
+ makeFullDirPath :: T. Text -> PathCompletionInfo -> IO T. Text
348
+ makeFullDirPath completion' complInfo = do
349
+ let fullPath = prefixPathInfo complInfo Posix. </> T. unpack completion'
350
+ pure $ T. pack fullPath
351
+
331
352
332
353
pathCompletionInfoFromCompletionContext :: CabalCompletionContext -> PathCompletionInfo
333
354
pathCompletionInfoFromCompletionContext ctx = PathCompletionInfo
@@ -339,6 +360,8 @@ pathCompletionInfoFromCompletionContext ctx = PathCompletionInfo
339
360
dirNamePrefix = T. pack $ Posix. takeFileName prefix
340
361
fp = Posix. takeDirectory $ completionCabalFilePath ctx
341
362
363
+ {- | Returns
364
+ -}
342
365
mkCompletionDirectory :: PathCompletionInfo -> FilePath
343
366
mkCompletionDirectory complInfo = FP. addTrailingPathSeparator $ cabalFilePathInfo complInfo FP. </> (FP. normalise $ prefixPathInfo complInfo)
344
367
0 commit comments