@@ -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
@@ -166,7 +165,7 @@ getContext pos ls =
166
165
-}
167
166
getKeyWordContext :: Position -> [T. Text ] -> Map KeyWordName a -> Maybe KeyWordContext
168
167
getKeyWordContext pos ls keywords = do
169
- case traceShowId $ lastNonEmptyLineM of
168
+ case lastNonEmptyLineM of
170
169
Nothing -> Just None
171
170
Just lastLine' -> do
172
171
let (whiteSpaces, lastLine) = T. span (== ' ' ) lastLine'
@@ -181,14 +180,13 @@ getKeyWordContext pos ls keywords = do
181
180
Just kw -> Just $ KeyWord kw
182
181
else Just None
183
182
where
183
+ currentLineM = ls Extra. !? (fromIntegral $ pos ^. JL. line)
184
+ lastNonEmptyLineM :: Maybe T. Text
184
185
lastNonEmptyLineM = do
185
186
cur' <- currentLineM
186
- traceShowM (" cur line" , cur')
187
187
let cur = stripPartiallyWritten $ T. take (fromIntegral $ pos ^. JL. character) cur'
188
- traceShowM (" cur line before pref" , cur)
189
188
List. find (not . T. null . T. stripEnd)
190
189
$ cur : previousLines pos ls
191
- currentLineM = ls Extra. !? (fromIntegral $ pos ^. JL. line)
192
190
193
191
{- | Parse the given set of lines (starting before current cursor position
194
192
up to the start of the file) to find the nearest stanza declaration,
@@ -237,8 +235,8 @@ stripPartiallyWritten = T.dropWhileEnd (\y -> (y /= ' ') && (y /= ':'))
237
235
checks whether a suffix needs to be completed,
238
236
and calculates the range in the document in which to complete
239
237
-}
240
- getFilePathCompletionContext :: FilePath -> VFS. PosPrefixInfo -> CabalCompletionContext
241
- getFilePathCompletionContext dir prefixInfo =
238
+ getCabalCompletionContext :: FilePath -> VFS. PosPrefixInfo -> CabalCompletionContext
239
+ getCabalCompletionContext dir prefixInfo =
242
240
CabalCompletionContext
243
241
{ completionPrefix = filepathPrefix
244
242
, completionSuffix = Just suffix
@@ -264,7 +262,7 @@ getFilePathCompletionContext dir prefixInfo =
264
262
cursorColumn = fromIntegral $ VFS. cursorPos prefixInfo ^. JL. character
265
263
-- if the filepath is inside apostrophes, we parse until the apostrophe,
266
264
-- otherwise we parse until a space occurs
267
- stopConditionChars = apostropheOrSpaceSeparator : [' ,' ]
265
+ stopConditionChars = apostropheOrSpaceSeparator : [' ,' , ' : ' ]
268
266
269
267
buildCompletion :: CabalCompletionItem -> J. CompletionItem
270
268
buildCompletion completionItem =
@@ -317,8 +315,9 @@ filePathCompleter :: Completer
317
315
filePathCompleter ctx = do
318
316
let suffix = fromMaybe " " $ completionSuffix ctx
319
317
complInfo = pathCompletionInfoFromCompletionContext ctx
318
+ toMatch = fromMaybe " " $ T. stripPrefix " ./" $ partialFileName complInfo
320
319
filePathCompletions <- listFileCompletions complInfo
321
- let scored = Fuzzy. simpleFilter 1000 10 (partialFileName complInfo) (map T. pack filePathCompletions)
320
+ let scored = Fuzzy. simpleFilter 1000 10 toMatch (map T. pack filePathCompletions)
322
321
forM
323
322
scored
324
323
( \ compl' -> do
@@ -327,7 +326,7 @@ filePathCompleter ctx = do
327
326
pure $ makeCabalCompletionItem (completionRange ctx) fullFilePath fullFilePath
328
327
)
329
328
where
330
- -- \| Takes a suffix, a completed path and a pathCompletionInfo and
329
+ -- Takes a suffix, a completed path and a pathCompletionInfo and
331
330
-- generates the whole filepath including the already written prefix
332
331
-- and the suffix in case the completed path is a filepath
333
332
makeFullFilePath :: T. Text -> T. Text -> PathCompletionInfo -> IO T. Text
@@ -354,7 +353,7 @@ directoryCompleter ctx = do
354
353
pure $ makeCabalCompletionItem (completionRange ctx) fullDirPath fullDirPath
355
354
)
356
355
where
357
- -- \| Takes a directory and PathCompletionInfo and
356
+ -- Takes a directory and PathCompletionInfo and
358
357
-- returns the whole path including the prefix that was already written
359
358
makeFullDirPath :: T. Text -> PathCompletionInfo -> IO T. Text
360
359
makeFullDirPath completion' complInfo = do
0 commit comments