@@ -27,7 +27,7 @@ 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 )
30+ import Debug.Trace (traceShowM )
3131
3232{- | Takes information needed to build possible completion items
3333and returns the list of possible completion items
@@ -77,7 +77,17 @@ data KeyWordContext
7777type KeyWordName = T. Text
7878type StanzaName = T. Text
7979
80- -- Information about the current completion status
80+ {- | Information about the current completion status
81+
82+ Example: @"dir1/fi@ having been written to the file
83+ would correspond to:
84+
85+ @
86+ completionPrefix = "dir1/fi"
87+ completionSuffix = Just "\\""
88+ ...
89+ @
90+ -}
8191data CabalCompletionContext = CabalCompletionContext
8292 { completionPrefix :: T. Text
8393 -- ^ text prefix to complete
@@ -166,7 +176,7 @@ getContext pos ls =
166176-}
167177getKeyWordContext :: Position -> [T. Text ] -> Map KeyWordName a -> Maybe KeyWordContext
168178getKeyWordContext pos ls keywords = do
169- case traceShowId $ lastNonEmptyLineM of
179+ case lastNonEmptyLineM of
170180 Nothing -> Just None
171181 Just lastLine' -> do
172182 let (whiteSpaces, lastLine) = T. span (== ' ' ) lastLine'
@@ -181,14 +191,13 @@ getKeyWordContext pos ls keywords = do
181191 Just kw -> Just $ KeyWord kw
182192 else Just None
183193 where
194+ currentLineM = ls Extra. !? (fromIntegral $ pos ^. JL. line)
195+ lastNonEmptyLineM :: Maybe T. Text
184196 lastNonEmptyLineM = do
185197 cur' <- currentLineM
186- traceShowM (" cur line" , cur')
187198 let cur = stripPartiallyWritten $ T. take (fromIntegral $ pos ^. JL. character) cur'
188- traceShowM (" cur line before pref" , cur)
189199 List. find (not . T. null . T. stripEnd)
190200 $ cur : previousLines pos ls
191- currentLineM = ls Extra. !? (fromIntegral $ pos ^. JL. line)
192201
193202{- | Parse the given set of lines (starting before current cursor position
194203 up to the start of the file) to find the nearest stanza declaration,
@@ -237,8 +246,8 @@ stripPartiallyWritten = T.dropWhileEnd (\y -> (y /= ' ') && (y /= ':'))
237246 checks whether a suffix needs to be completed,
238247 and calculates the range in the document in which to complete
239248-}
240- getFilePathCompletionContext :: FilePath -> VFS. PosPrefixInfo -> CabalCompletionContext
241- getFilePathCompletionContext dir prefixInfo =
249+ getCabalCompletionContext :: FilePath -> VFS. PosPrefixInfo -> CabalCompletionContext
250+ getCabalCompletionContext dir prefixInfo =
242251 CabalCompletionContext
243252 { completionPrefix = filepathPrefix
244253 , completionSuffix = Just suffix
@@ -264,7 +273,7 @@ getFilePathCompletionContext dir prefixInfo =
264273 cursorColumn = fromIntegral $ VFS. cursorPos prefixInfo ^. JL. character
265274 -- if the filepath is inside apostrophes, we parse until the apostrophe,
266275 -- otherwise we parse until a space occurs
267- stopConditionChars = apostropheOrSpaceSeparator : [' ,' ]
276+ stopConditionChars = apostropheOrSpaceSeparator : [' ,' , ' : ' ]
268277
269278buildCompletion :: CabalCompletionItem -> J. CompletionItem
270279buildCompletion completionItem =
@@ -317,8 +326,12 @@ filePathCompleter :: Completer
317326filePathCompleter ctx = do
318327 let suffix = fromMaybe " " $ completionSuffix ctx
319328 complInfo = pathCompletionInfoFromCompletionContext ctx
329+ toMatch = fromMaybe (partialFileName complInfo) $ T. stripPrefix " ./" $ partialFileName complInfo
320330 filePathCompletions <- listFileCompletions complInfo
321- let scored = Fuzzy. simpleFilter 1000 10 (partialFileName complInfo) (map T. pack filePathCompletions)
331+ traceShowM (" match string:" , toMatch)
332+ traceShowM (" completions:" , filePathCompletions)
333+ let scored = Fuzzy. simpleFilter 1000 10 toMatch (map T. pack filePathCompletions)
334+ traceShowM (" scored:" , scored)
322335 forM
323336 scored
324337 ( \ compl' -> do
@@ -327,7 +340,7 @@ filePathCompleter ctx = do
327340 pure $ makeCabalCompletionItem (completionRange ctx) fullFilePath fullFilePath
328341 )
329342 where
330- -- \| Takes a suffix, a completed path and a pathCompletionInfo and
343+ -- Takes a suffix, a completed path and a pathCompletionInfo and
331344 -- generates the whole filepath including the already written prefix
332345 -- and the suffix in case the completed path is a filepath
333346 makeFullFilePath :: T. Text -> T. Text -> PathCompletionInfo -> IO T. Text
@@ -354,7 +367,7 @@ directoryCompleter ctx = do
354367 pure $ makeCabalCompletionItem (completionRange ctx) fullDirPath fullDirPath
355368 )
356369 where
357- -- \| Takes a directory and PathCompletionInfo and
370+ -- Takes a directory and PathCompletionInfo and
358371 -- returns the whole path including the prefix that was already written
359372 makeFullDirPath :: T. Text -> PathCompletionInfo -> IO T. Text
360373 makeFullDirPath completion' complInfo = do
@@ -420,6 +433,16 @@ mkDirFromCWD complInfo fp = Posix.addTrailingPathSeparator $ mkCompletionDirecto
420433
421434 Note that partialFileName combined with partialFileDir results in
422435 the original prefix.
436+
437+ Example:
438+ On the written filepath: @dir1/fi@ the
439+ resulting PathCompletionInfo would be:
440+
441+ @
442+ partialFileName = "fi"
443+ partialFileDir = "dir1/dir2/fi"
444+ ...
445+ @
423446-}
424447data PathCompletionInfo = PathCompletionInfo
425448 { partialFileName :: T. Text
0 commit comments