@@ -201,15 +201,12 @@ getFilePathCompletionContext dir prefixInfo =
201
201
CabalCompletionContext
202
202
{ completionPrefix = filepathPrefix
203
203
, completionSuffix = Just suffix
204
- , completionRange = editRange
204
+ , completionRange = Range completionStart completionEnd
205
205
, completionCabalFilePath = dir
206
206
}
207
207
where
208
- (Position linePos charPos) = VFS. cursorPos prefixInfo
209
- editRange =
210
- Range
211
- (Position linePos (fromIntegral charPos - fromIntegral (T. length filepathPrefix)))
212
- (Position linePos charPos)
208
+ completionEnd = VFS. cursorPos prefixInfo
209
+ completionStart = Position (_line completionEnd) (_character completionEnd - (fromIntegral $ T. length filepathPrefix))
213
210
filepathPrefix = T. takeWhileEnd (not . (`elem` stopConditionChars)) prevLineText
214
211
(prevLineText, endLineText) = T. splitAt cursorColumn $ VFS. fullLine prefixInfo
215
212
suffix = if (apostropheOrSpaceSeparator == ' \" ' ) && even (T. count " \" " endLineText) then " \" " else " "
@@ -246,15 +243,15 @@ buildCompletion completionItem =
246
243
-- Completor API
247
244
-- ----------------------------------------------------------------
248
245
249
- {- | Returns a CabalCompletionItem with the given range
250
- and text to be inserted with no suffix to be written
246
+ {- | Returns a CabalCompletionItem with the given starting position
247
+ and text to be inserted where the displayed text is the same as the inserted text
251
248
after the inserted text
252
249
-}
253
250
makeSimpleCabalCompletionItem :: Range -> T. Text -> CabalCompletionItem
254
251
makeSimpleCabalCompletionItem r txt = CabalCompletionItem txt Nothing r
255
252
256
- {- | Returns a CabalCompletionItem with the given range ,
257
- text to be inserted and suffix to be written after the inserted text
253
+ {- | Returns a CabalCompletionItem with the given starting position ,
254
+ text to be inserted and text to be displayed in completionsuggestion
258
255
-}
259
256
makeCabalCompletionItem :: Range -> T. Text -> T. Text -> CabalCompletionItem
260
257
makeCabalCompletionItem r insertTxt displayTxt = CabalCompletionItem insertTxt (Just displayTxt) r
@@ -271,7 +268,9 @@ noopCompleter _ = pure []
271
268
constantCompleter :: [T. Text ] -> Completer
272
269
constantCompleter completions ctxInfo = do
273
270
let scored = Fuzzy. simpleFilter 1000 10 (completionPrefix ctxInfo) completions
274
- pure $ map (makeSimpleCabalCompletionItem (completionRange ctxInfo) . Fuzzy. original) scored
271
+ let range = completionRange ctxInfo
272
+ pure $ map (makeSimpleCabalCompletionItem range . Fuzzy. original) scored
273
+
275
274
276
275
{- | Completer to be used when a file path can be
277
276
completed for the field, takes the file path of the directory to start from,
@@ -283,24 +282,29 @@ filePathCompleter ctx = do
283
282
complInfo = pathCompletionInfoFromCompletionContext ctx
284
283
traceShowM (" ---> COMPLETER" , complInfo)
285
284
filePathCompletions <- listFileCompletions complInfo
286
- traceShowM (" Completions: " , filePathCompletions) -- ("Completions: ",["MyLib.hs"])
287
- traceShowM (" LeftOver" , prefixLeftOver complInfo) -- ""
285
+ traceShowM (" Completions: " , filePathCompletions)
286
+ traceShowM (" LeftOver" , prefixLeftOver complInfo)
288
287
let scored = Fuzzy. simpleFilter 1000 10 (prefixLeftOver complInfo) (map T. pack filePathCompletions)
289
- -- [Scored {score = 0, original = "MyLib.hs"}]
290
288
forM
291
289
(traceShowId scored)
292
290
( \ compl' -> do
293
291
let compl = Fuzzy. original compl'
294
- withSuffix <- addSuffixIfFilePath suffix compl
295
- pure $ makeCabalCompletionItem (completionRange ctx) (T. pack (prefixPathInfo complInfo) <> " /" <> withSuffix) (T. pack (prefixPathInfo complInfo) <> " /" <> compl)
292
+ fullFilePath <- makeFullFilePath suffix compl complInfo
293
+ let charCursorPos = _character $ _end (completionRange ctx)
294
+ let newEndChar = charCursorPos + ((fromIntegral $ T. length compl) - (fromIntegral (T. length $ prefixLeftOver complInfo)))
295
+ let actualRange = Range (_start (completionRange ctx)) (Position (_line $ _end (completionRange ctx)) newEndChar)
296
+ pure $ makeCabalCompletionItem actualRange fullFilePath fullFilePath
296
297
)
297
298
298
299
where
299
- addSuffixIfFilePath :: T. Text -> T. Text -> IO T. Text
300
- addSuffixIfFilePath suffix' completion' = do
301
- isFilePath <- doesFileExist $ T. unpack completion'
302
- let completion = if isFilePath then T. append completion' suffix' else completion'
303
- pure completion
300
+ -- | Takes a suffix and a text and returns filepath with the suffix
301
+ makeFullFilePath :: T. Text -> T. Text -> PathCompletionInfo -> IO T. Text
302
+ makeFullFilePath suffix' completion' complInfo = do
303
+ let fullPath' = prefixPathInfo complInfo </> T. unpack completion'
304
+ traceShowM (" full path" ,fullPath')
305
+ isFilePath <- doesFileExist fullPath'
306
+ let fullPath = if isFilePath then fullPath' ++ T. unpack suffix' else fullPath'
307
+ pure $ T. pack fullPath
304
308
305
309
listFileCompletions :: PathCompletionInfo -> IO [FilePath ]
306
310
listFileCompletions complInfo = do
0 commit comments