Skip to content

Commit ec76a13

Browse files
VeryMilkyJoeVeryMilkyJoe
VeryMilkyJoe
authored andcommitted
Fix file paths completing correctly in subdirectories
1 parent 87ae166 commit ec76a13

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import qualified Language.LSP.Types as LSP
4242
import qualified Language.LSP.Types.Lens as JL
4343
import Language.LSP.VFS (VirtualFile)
4444
import qualified Language.LSP.VFS as VFS
45-
import Debug.Trace (traceShowId, traceShow, traceShowM)
4645

4746
data Log
4847
= LogModificationTime NormalizedFilePath FileVersion
@@ -287,11 +286,9 @@ completion _ide _ complParams = do
287286
result (Just prefix) fp cnts
288287
| Just ctx <- context = do
289288
let completer = contextToCompleter ctx
290-
traceShowM ("AHHHHHHHHHHHHH", completionContext)
291289
completions <- completer completionContext
292-
traceShowM ("Final compls", completions)
293290
-- genPkgDesc <- readGenericPackageDescription silent fp
294-
pure $ J.List $ traceShowId $ makeCompletionItems completions
291+
pure $ J.List $ makeCompletionItems completions
295292
| otherwise = pure $ J.List []
296293
where
297294
(Position linePos charPos) = VFS.cursorPos prefix

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Completions.hs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import System.Directory (doesDirectoryExist,
2424
doesFileExist, listDirectory)
2525
import System.FilePath
2626
import qualified Text.Fuzzy.Parallel as Fuzzy
27-
import Debug.Trace (traceShowM, traceShowId)
2827

2928
-- | Takes information needed to build possible completion items
3029
-- and returns the list of possible completion items
@@ -280,31 +279,24 @@ filePathCompleter :: Completer
280279
filePathCompleter ctx = do
281280
let suffix = fromMaybe "" $ completionSuffix ctx
282281
complInfo = pathCompletionInfoFromCompletionContext ctx
283-
traceShowM ("---> COMPLETER", complInfo)
284282
filePathCompletions <- listFileCompletions complInfo
285-
traceShowM ("Completions: ", filePathCompletions)
286-
traceShowM ("LeftOver", prefixLeftOver complInfo)
287283
let scored = Fuzzy.simpleFilter 1000 10 (prefixLeftOver complInfo) (map T.pack filePathCompletions)
288284
forM
289-
(traceShowId scored)
285+
scored
290286
( \compl' -> do
291287
let compl = Fuzzy.original compl'
292288
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
289+
pure $ makeCabalCompletionItem (completionRange ctx) fullFilePath fullFilePath
297290
)
298291

299292
where
300293
-- | Takes a suffix and a text and returns filepath with the suffix
301294
makeFullFilePath :: T.Text -> T.Text -> PathCompletionInfo -> IO T.Text
302295
makeFullFilePath suffix' completion' complInfo = do
303296
let fullPath' = prefixPathInfo complInfo </> T.unpack completion'
304-
traceShowM ("full path" ,fullPath')
305297
isFilePath <- doesFileExist fullPath'
306298
let fullPath = if isFilePath then fullPath' ++ T.unpack suffix' else fullPath'
307-
pure $ T.pack fullPath
299+
pure $ T.pack fullPath
308300

309301
listFileCompletions :: PathCompletionInfo -> IO [FilePath]
310302
listFileCompletions complInfo = do

plugins/hls-cabal-plugin/test/Main.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pathCompleterTests = testGroup "Path Completion Tests"
200200
CabalCompletionContext
201201
{ completionPrefix = prefix
202202
, completionSuffix = Nothing
203-
, completionRange = Range (Position 0 0) (Position 0 0)
203+
, completionRange = Range (Position 0 0) (Position 0 0)
204204
, completionCabalFilePath = fp </> "test.cabal"
205205
}
206206
getTestDir :: IO FilePath
@@ -282,37 +282,37 @@ pathCompleterTests = testGroup "Path Completion Tests"
282282
testDir <- getTestDir
283283
completions <- filePathCompleter $ simpleCabalCompletionContext "" testDir
284284
let insertCompletions = map itemInsert completions
285-
sort insertCompletions @?= [".hidden", "dir1/", "dir2/", "textfile.txt"],
285+
sort insertCompletions @?= ["./.hidden", "./dir1/", "./dir2/", "./textfile.txt"],
286286
testCase "Current Directory - alternative writing" $ do
287287
testDir <- getTestDir
288288
completions <- filePathCompleter $ simpleCabalCompletionContext "./" testDir
289289
let insertCompletions = map itemInsert completions
290-
sort insertCompletions @?= [".hidden", "dir1/", "dir2/", "textfile.txt"],
290+
sort insertCompletions @?= ["./.hidden", "./dir1/", "./dir2/", "./textfile.txt"],
291291
testCase "Current Directory - hidden file start" $ do
292292
testDir <- getTestDir
293293
completions <- filePathCompleter $ simpleCabalCompletionContext "." testDir
294294
let insertCompletions = map itemInsert completions
295-
sort insertCompletions @?= [".hidden", "textfile.txt"],
295+
sort insertCompletions @?= ["./.hidden", "./textfile.txt"],
296296
testCase "Current Directory - incomplete directory path written" $ do
297297
testDir <- getTestDir
298298
completions <- filePathCompleter $ simpleCabalCompletionContext "di" testDir
299299
let insertCompletions = map itemInsert completions
300-
sort insertCompletions @?= ["dir1/", "dir2/"],
300+
sort insertCompletions @?= ["./dir1/", "./dir2/"],
301301
testCase "Current Directory - incomplete filepath written" $ do
302302
testDir <- getTestDir
303303
completions <- filePathCompleter $ simpleCabalCompletionContext "te" testDir
304304
let insertCompletions = map itemInsert completions
305-
sort insertCompletions @?= ["textfile.txt"],
305+
sort insertCompletions @?= ["./textfile.txt"],
306306
testCase "Subdirectory" $ do
307307
testDir <- getTestDir
308308
completions <- filePathCompleter $ simpleCabalCompletionContext "dir1/" testDir
309309
let insertCompletions = map itemInsert completions
310-
sort insertCompletions @?= ["f1.txt", "f2.hs"],
310+
sort insertCompletions @?= ["dir1/f1.txt", "dir1/f2.hs"],
311311
testCase "Subdirectory - incomplete filepath written" $ do
312312
testDir <- getTestDir
313313
completions <- filePathCompleter $ simpleCabalCompletionContext "dir2/dir3/MA" testDir
314314
let insertCompletions = map itemInsert completions
315-
sort insertCompletions @?= ["MARKDOWN.md"],
315+
sort insertCompletions @?= ["dir2/dir3/MARKDOWN.md"],
316316
testCase "Nonexistent directory" $ do
317317
testDir <- getTestDir
318318
completions <- filePathCompleter $ simpleCabalCompletionContext "dir2/dir4/" testDir

0 commit comments

Comments
 (0)