@@ -27,7 +27,6 @@ import System.Directory (doesDirectoryExist,
27
27
import qualified System.FilePath as FP
28
28
import qualified System.FilePath.Posix as Posix
29
29
import qualified Text.Fuzzy.Parallel as Fuzzy
30
- import Debug.Trace (traceShowM , traceShowId )
31
30
32
31
{- | Takes information needed to build possible completion items
33
32
and returns the list of possible completion items
@@ -77,7 +76,17 @@ data KeyWordContext
77
76
type KeyWordName = T. Text
78
77
type StanzaName = T. Text
79
78
80
- -- Information about the current completion status
79
+ {- | Information about the current completion status
80
+
81
+ Example: @"dir1/fi@ having been written to the file
82
+ would correspond to:
83
+
84
+ @
85
+ completionPrefix = "dir1/fi"
86
+ completionSuffix = Just "\\""
87
+ ...
88
+ @
89
+ -}
81
90
data CabalCompletionContext = CabalCompletionContext
82
91
{ completionPrefix :: T. Text
83
92
-- ^ text prefix to complete
@@ -166,7 +175,7 @@ getContext pos ls =
166
175
-}
167
176
getKeyWordContext :: Position -> [T. Text ] -> Map KeyWordName a -> Maybe KeyWordContext
168
177
getKeyWordContext pos ls keywords = do
169
- case traceShowId $ lastNonEmptyLineM of
178
+ case lastNonEmptyLineM of
170
179
Nothing -> Just None
171
180
Just lastLine' -> do
172
181
let (whiteSpaces, lastLine) = T. span (== ' ' ) lastLine'
@@ -181,14 +190,13 @@ getKeyWordContext pos ls keywords = do
181
190
Just kw -> Just $ KeyWord kw
182
191
else Just None
183
192
where
193
+ currentLineM = ls Extra. !? (fromIntegral $ pos ^. JL. line)
194
+ lastNonEmptyLineM :: Maybe T. Text
184
195
lastNonEmptyLineM = do
185
196
cur' <- currentLineM
186
- traceShowM (" cur line" , cur')
187
197
let cur = stripPartiallyWritten $ T. take (fromIntegral $ pos ^. JL. character) cur'
188
- traceShowM (" cur line before pref" , cur)
189
198
List. find (not . T. null . T. stripEnd)
190
199
$ cur : previousLines pos ls
191
- currentLineM = ls Extra. !? (fromIntegral $ pos ^. JL. line)
192
200
193
201
{- | Parse the given set of lines (starting before current cursor position
194
202
up to the start of the file) to find the nearest stanza declaration,
@@ -237,8 +245,8 @@ stripPartiallyWritten = T.dropWhileEnd (\y -> (y /= ' ') && (y /= ':'))
237
245
checks whether a suffix needs to be completed,
238
246
and calculates the range in the document in which to complete
239
247
-}
240
- getFilePathCompletionContext :: FilePath -> VFS. PosPrefixInfo -> CabalCompletionContext
241
- getFilePathCompletionContext dir prefixInfo =
248
+ getCabalCompletionContext :: FilePath -> VFS. PosPrefixInfo -> CabalCompletionContext
249
+ getCabalCompletionContext dir prefixInfo =
242
250
CabalCompletionContext
243
251
{ completionPrefix = filepathPrefix
244
252
, completionSuffix = Just suffix
@@ -264,7 +272,7 @@ getFilePathCompletionContext dir prefixInfo =
264
272
cursorColumn = fromIntegral $ VFS. cursorPos prefixInfo ^. JL. character
265
273
-- if the filepath is inside apostrophes, we parse until the apostrophe,
266
274
-- otherwise we parse until a space occurs
267
- stopConditionChars = apostropheOrSpaceSeparator : [' ,' ]
275
+ stopConditionChars = apostropheOrSpaceSeparator : [' ,' , ' : ' ]
268
276
269
277
buildCompletion :: CabalCompletionItem -> J. CompletionItem
270
278
buildCompletion completionItem =
@@ -317,8 +325,9 @@ filePathCompleter :: Completer
317
325
filePathCompleter ctx = do
318
326
let suffix = fromMaybe " " $ completionSuffix ctx
319
327
complInfo = pathCompletionInfoFromCompletionContext ctx
328
+ toMatch = fromMaybe " " $ T. stripPrefix " ./" $ partialFileName complInfo
320
329
filePathCompletions <- listFileCompletions complInfo
321
- let scored = Fuzzy. simpleFilter 1000 10 (partialFileName complInfo) (map T. pack filePathCompletions)
330
+ let scored = Fuzzy. simpleFilter 1000 10 toMatch (map T. pack filePathCompletions)
322
331
forM
323
332
scored
324
333
( \ compl' -> do
@@ -327,7 +336,7 @@ filePathCompleter ctx = do
327
336
pure $ makeCabalCompletionItem (completionRange ctx) fullFilePath fullFilePath
328
337
)
329
338
where
330
- -- \| Takes a suffix, a completed path and a pathCompletionInfo and
339
+ -- Takes a suffix, a completed path and a pathCompletionInfo and
331
340
-- generates the whole filepath including the already written prefix
332
341
-- and the suffix in case the completed path is a filepath
333
342
makeFullFilePath :: T. Text -> T. Text -> PathCompletionInfo -> IO T. Text
@@ -354,7 +363,7 @@ directoryCompleter ctx = do
354
363
pure $ makeCabalCompletionItem (completionRange ctx) fullDirPath fullDirPath
355
364
)
356
365
where
357
- -- \| Takes a directory and PathCompletionInfo and
366
+ -- Takes a directory and PathCompletionInfo and
358
367
-- returns the whole path including the prefix that was already written
359
368
makeFullDirPath :: T. Text -> PathCompletionInfo -> IO T. Text
360
369
makeFullDirPath completion' complInfo = do
@@ -420,6 +429,16 @@ mkDirFromCWD complInfo fp = Posix.addTrailingPathSeparator $ mkCompletionDirecto
420
429
421
430
Note that partialFileName combined with partialFileDir results in
422
431
the original prefix.
432
+
433
+ Example:
434
+ On the written filepath: @dir1/fi@ the
435
+ resulting PathCompletionInfo would be:
436
+
437
+ @
438
+ partialFileName = "fi"
439
+ partialFileDir = "dir1/dir2/fi"
440
+ ...
441
+ @
423
442
-}
424
443
data PathCompletionInfo = PathCompletionInfo
425
444
{ partialFileName :: T. Text
0 commit comments