Skip to content

Commit 7639c4d

Browse files
committed
WIP
1 parent 87690de commit 7639c4d

File tree

3 files changed

+69
-13
lines changed

3 files changed

+69
-13
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ 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)
4546

4647
data Log
4748
= LogModificationTime NormalizedFilePath FileVersion
@@ -286,9 +287,11 @@ completion _ide _ complParams = do
286287
result (Just prefix) fp cnts
287288
| Just ctx <- context = do
288289
let completer = contextToCompleter ctx
290+
traceShowM ("AHHHHHHHHHHHHH", completionContext)
289291
completions <- completer completionContext
292+
traceShowM ("Final compls", completions)
290293
-- genPkgDesc <- readGenericPackageDescription silent fp
291-
pure $ J.List $ makeCompletionItems completions
294+
pure $ J.List $ traceShowId $ makeCompletionItems completions
292295
| otherwise = pure $ J.List []
293296
where
294297
(Position linePos charPos) = VFS.cursorPos prefix

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ 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)
2728

2829
-- | Takes information needed to build possible completion items
2930
-- and returns the list of possible completion items
@@ -280,10 +281,14 @@ filePathCompleter :: Completer
280281
filePathCompleter ctx = do
281282
let suffix = fromMaybe "" $ completionSuffix ctx
282283
complInfo = pathCompletionInfoFromCompletionContext ctx
284+
traceShowM ("---> COMPLETER", complInfo)
283285
filePathCompletions <- listFileCompletions complInfo
286+
traceShowM ("Completions: ", filePathCompletions) -- ("Completions: ",["MyLib.hs"])
287+
traceShowM ("LeftOver", prefixLeftOver complInfo) -- ""
284288
let scored = Fuzzy.simpleFilter 1000 10 (prefixLeftOver complInfo) (map T.pack filePathCompletions)
289+
--[Scored {score = 0, original = "MyLib.hs"}]
285290
forM
286-
scored
291+
(traceShowId scored)
287292
( \compl' -> do
288293
let compl = Fuzzy.original compl'
289294
withSuffix <- addSuffixIfFilePath suffix compl
@@ -329,7 +334,7 @@ directoryCompleter ctx = do
329334
pathCompletionInfoFromCompletionContext :: CabalCompletionContext -> PathCompletionInfo
330335
pathCompletionInfoFromCompletionContext ctx = PathCompletionInfo
331336
{ prefixLeftOver = dirNamePrefix
332-
, prefixPathInfo = takeDirectory prefix
337+
, prefixPathInfo = addTrailingPathSeparator $ takeDirectory prefix
333338
, cabalFilePathInfo = fp}
334339
where
335340
prefix = T.unpack $ completionPrefix ctx

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

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,37 @@ filePathCompletionContextTests =
128128
testGroup
129129
"File Path Completion Context Tests"
130130
[ testCase "empty line" $ do
131-
(completionSuffix $ getFilePathCompletionContext "" (simplePosPrefixInfo " " 0 3)) @?= Just ""
132-
, testCase "simple filepath" $ do
133-
(completionSuffix $ getFilePathCompletionContext "" (simplePosPrefixInfo " src/" 0 7)) @?= Just ""
131+
let complContext = getFilePathCompletionContext "" (simplePosPrefixInfo " " 0 3)
132+
completionSuffix complContext @?= Just ""
133+
completionPrefix complContext @?= ""
134+
, testCase "simple filepath" $ do
135+
let complContext = getFilePathCompletionContext "" (simplePosPrefixInfo " src/" 0 7)
136+
completionSuffix complContext @?= Just ""
137+
completionPrefix complContext @?= "src/"
134138
, testCase "simple filepath - starting apostrophe" $ do
135-
(completionSuffix $ getFilePathCompletionContext "" (simplePosPrefixInfo " \"src/" 0 7)) @?= Just "\""
139+
let complContext = getFilePathCompletionContext "" (simplePosPrefixInfo " \"src/" 0 8)
140+
completionSuffix complContext @?= Just "\""
141+
completionPrefix complContext @?= "src/"
136142
, testCase "simple filepath - starting apostrophe, already closed" $ do
137-
(completionSuffix $ getFilePathCompletionContext "" (simplePosPrefixInfo " \"src/\"" 0 7)) @?= Just ""
143+
let complContext = getFilePathCompletionContext "" (simplePosPrefixInfo " \"src/\"" 0 8)
144+
completionSuffix complContext @?= Just ""
145+
completionPrefix complContext @?= "src/"
138146
, testCase "second filepath - starting apostrophe" $ do
139-
(completionSuffix $ getFilePathCompletionContext "" (simplePosPrefixInfo "fp.txt \"src/" 0 12)) @?= Just "\""
147+
let complContext = getFilePathCompletionContext "" (simplePosPrefixInfo "fp.txt \"src/" 0 12)
148+
completionSuffix complContext @?= Just "\""
149+
completionPrefix complContext @?= "src/"
140150
, testCase "middle filepath - starting apostrophe" $ do
141-
(completionSuffix $ getFilePathCompletionContext "" (simplePosPrefixInfo "fp.txt \"src/ fp2.txt" 0 12)) @?= Just "\""
151+
let complContext = getFilePathCompletionContext "" (simplePosPrefixInfo "fp.txt \"src/ fp2.txt" 0 12)
152+
completionSuffix complContext @?= Just "\""
153+
completionPrefix complContext @?= "src/"
142154
, testCase "middle filepath - starting apostrophe, already closed" $ do
143-
(completionSuffix $ getFilePathCompletionContext "" (simplePosPrefixInfo "fp.t xt \"src\" fp2.txt" 0 12)) @?= Just ""
155+
let complContext = getFilePathCompletionContext "" (simplePosPrefixInfo "fp.t xt \"src\" fp2.txt" 0 12)
156+
completionSuffix complContext @?= Just ""
157+
completionPrefix complContext @?= "src"
144158
, testCase "middle filepath - starting apostrophe, already closed" $ do
145-
(completionSuffix $ getFilePathCompletionContext "" (simplePosPrefixInfo "\"fp.txt\" \"src fp2.txt" 0 11)) @?= Just "\""
159+
let complContext = getFilePathCompletionContext "" (simplePosPrefixInfo "\"fp.txt\" \"src fp2.txt" 0 13)
160+
completionSuffix complContext @?= Just "\""
161+
completionPrefix complContext @?= "src"
146162
]
147163
where
148164
simplePosPrefixInfo :: T.Text -> UInt -> UInt -> VFS.PosPrefixInfo
@@ -155,9 +171,10 @@ filePathCompletionContextTests =
155171
}
156172

157173
pathCompleterTests :: TestTree
158-
pathCompleterTests = testGroup "Path Completer Tests"
174+
pathCompleterTests = testGroup "Path Completion Tests"
159175
[ fileCompleterTests
160176
, directoryCompleterTests
177+
, pathCompletionInfoFromCompletionContextTests
161178
, testGroup "Helper - List File Completion Tests"
162179
[ testCase "Current Directory" $ do
163180
testDir <- getTestDir
@@ -190,6 +207,37 @@ pathCompleterTests = testGroup "Path Completer Tests"
190207
getTestDir = do
191208
cwd <- getCurrentDirectory
192209
pure $ cwd </> "test/testdata/filepath-completions/"
210+
pathCompletionInfoFromCompletionContextTests :: TestTree
211+
pathCompletionInfoFromCompletionContextTests = testGroup "Completion Info to Completion Context Tests"
212+
[ testCase "Current Directory" $ do
213+
testDir <- getTestDir
214+
let complInfo = pathCompletionInfoFromCompletionContext $ simpleCabalCompletionContext "" testDir
215+
prefixPathInfo complInfo @?= "./",
216+
testCase "Current Directory - partly written next" $ do
217+
testDir <- getTestDir
218+
let complInfo = pathCompletionInfoFromCompletionContext $ simpleCabalCompletionContext "di" testDir
219+
prefixPathInfo complInfo @?= "./"
220+
prefixLeftOver complInfo @?= "di",
221+
testCase "Current Directory - alternative writing" $ do
222+
testDir <- getTestDir
223+
let complInfo = pathCompletionInfoFromCompletionContext $ simpleCabalCompletionContext "./" testDir
224+
prefixPathInfo complInfo @?= "./",
225+
testCase "Subdirectory" $ do
226+
testDir <- getTestDir
227+
let complInfo = pathCompletionInfoFromCompletionContext $ simpleCabalCompletionContext "dir1/" testDir
228+
prefixPathInfo complInfo @?= "dir1/"
229+
prefixLeftOver complInfo @?= "",
230+
testCase "Subdirectory - partly written next" $ do
231+
testDir <- getTestDir
232+
let complInfo = pathCompletionInfoFromCompletionContext $ simpleCabalCompletionContext "dir1/d" testDir
233+
prefixPathInfo complInfo @?= "dir1/"
234+
prefixLeftOver complInfo @?= "d",
235+
testCase "Subdirectory - partly written next" $ do
236+
testDir <- getTestDir
237+
let complInfo = pathCompletionInfoFromCompletionContext $ simpleCabalCompletionContext "dir1/dir2/d" testDir
238+
prefixPathInfo complInfo @?= "dir1/dir2/"
239+
prefixLeftOver complInfo @?= "d"
240+
]
193241
directoryCompleterTests :: TestTree
194242
directoryCompleterTests = testGroup "Directory Completer Tests"
195243
[ testCase "Current Directory" $ do

0 commit comments

Comments
 (0)