@@ -27,7 +27,6 @@ import System.Directory (doesDirectoryExist,
2727import qualified System.FilePath as FP
2828import qualified System.FilePath.Posix as Posix
2929import qualified Text.Fuzzy.Parallel as Fuzzy
30- import Debug.Trace (traceShowM , traceShowId )
3130
3231{- | Takes information needed to build possible completion items
3332and returns the list of possible completion items
@@ -166,7 +165,7 @@ getContext pos ls =
166165-}
167166getKeyWordContext :: Position -> [T. Text ] -> Map KeyWordName a -> Maybe KeyWordContext
168167getKeyWordContext pos ls keywords = do
169- case traceShowId $ lastNonEmptyLineM of
168+ case lastNonEmptyLineM of
170169 Nothing -> Just None
171170 Just lastLine' -> do
172171 let (whiteSpaces, lastLine) = T. span (== ' ' ) lastLine'
@@ -181,14 +180,13 @@ getKeyWordContext pos ls keywords = do
181180 Just kw -> Just $ KeyWord kw
182181 else Just None
183182 where
183+ currentLineM = ls Extra. !? (fromIntegral $ pos ^. JL. line)
184+ lastNonEmptyLineM :: Maybe T. Text
184185 lastNonEmptyLineM = do
185186 cur' <- currentLineM
186- traceShowM (" cur line" , cur')
187187 let cur = stripPartiallyWritten $ T. take (fromIntegral $ pos ^. JL. character) cur'
188- traceShowM (" cur line before pref" , cur)
189188 List. find (not . T. null . T. stripEnd)
190189 $ cur : previousLines pos ls
191- currentLineM = ls Extra. !? (fromIntegral $ pos ^. JL. line)
192190
193191{- | Parse the given set of lines (starting before current cursor position
194192 up to the start of the file) to find the nearest stanza declaration,
@@ -237,8 +235,8 @@ stripPartiallyWritten = T.dropWhileEnd (\y -> (y /= ' ') && (y /= ':'))
237235 checks whether a suffix needs to be completed,
238236 and calculates the range in the document in which to complete
239237-}
240- getFilePathCompletionContext :: FilePath -> VFS. PosPrefixInfo -> CabalCompletionContext
241- getFilePathCompletionContext dir prefixInfo =
238+ getCabalCompletionContext :: FilePath -> VFS. PosPrefixInfo -> CabalCompletionContext
239+ getCabalCompletionContext dir prefixInfo =
242240 CabalCompletionContext
243241 { completionPrefix = filepathPrefix
244242 , completionSuffix = Just suffix
@@ -264,7 +262,7 @@ getFilePathCompletionContext dir prefixInfo =
264262 cursorColumn = fromIntegral $ VFS. cursorPos prefixInfo ^. JL. character
265263 -- if the filepath is inside apostrophes, we parse until the apostrophe,
266264 -- otherwise we parse until a space occurs
267- stopConditionChars = apostropheOrSpaceSeparator : [' ,' ]
265+ stopConditionChars = apostropheOrSpaceSeparator : [' ,' , ' : ' ]
268266
269267buildCompletion :: CabalCompletionItem -> J. CompletionItem
270268buildCompletion completionItem =
@@ -317,8 +315,9 @@ filePathCompleter :: Completer
317315filePathCompleter ctx = do
318316 let suffix = fromMaybe " " $ completionSuffix ctx
319317 complInfo = pathCompletionInfoFromCompletionContext ctx
318+ toMatch = fromMaybe " " $ T. stripPrefix " ./" $ partialFileName complInfo
320319 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)
322321 forM
323322 scored
324323 ( \ compl' -> do
@@ -327,7 +326,7 @@ filePathCompleter ctx = do
327326 pure $ makeCabalCompletionItem (completionRange ctx) fullFilePath fullFilePath
328327 )
329328 where
330- -- \| Takes a suffix, a completed path and a pathCompletionInfo and
329+ -- Takes a suffix, a completed path and a pathCompletionInfo and
331330 -- generates the whole filepath including the already written prefix
332331 -- and the suffix in case the completed path is a filepath
333332 makeFullFilePath :: T. Text -> T. Text -> PathCompletionInfo -> IO T. Text
@@ -354,7 +353,7 @@ directoryCompleter ctx = do
354353 pure $ makeCabalCompletionItem (completionRange ctx) fullDirPath fullDirPath
355354 )
356355 where
357- -- \| Takes a directory and PathCompletionInfo and
356+ -- Takes a directory and PathCompletionInfo and
358357 -- returns the whole path including the prefix that was already written
359358 makeFullDirPath :: T. Text -> PathCompletionInfo -> IO T. Text
360359 makeFullDirPath completion' complInfo = do
0 commit comments