Skip to content

Commit 2c325fb

Browse files
committed
Refactor completion for cabal files
Add completer function which can be used to complete different types of values inside a cabal file
1 parent 4568c52 commit 2c325fb

File tree

4 files changed

+228
-191
lines changed

4 files changed

+228
-191
lines changed

plugins/hls-cabal-plugin/hls-cabal-plugin.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ library
6161
, text
6262
, text-rope
6363
, unordered-containers >=0.2.10.0
64+
, haskeline
6465

6566
hs-source-dirs: src
6667
default-language: Haskell2010
@@ -82,3 +83,4 @@ test-suite tests
8283
, lsp-types
8384
, tasty-hunit
8485
, text
86+

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,16 @@ completion _ide _ complParams = do
275275
fmap (Right . J.InL) $ case (contents, uriToFilePath' uri) of
276276
(Just cnts, Just _path) -> do
277277
pref <- VFS.getCompletionPrefix position cnts
278-
return $ result pref cnts
278+
liftIO $ result pref cnts
279279
_ -> return $ J.List []
280280
where
281-
result :: Maybe VFS.PosPrefixInfo -> VirtualFile -> J.List CompletionItem
282-
result Nothing _ = J.List []
281+
result :: Maybe VFS.PosPrefixInfo -> VirtualFile -> IO (J.List CompletionItem)
282+
result Nothing _ = pure $ J.List []
283283
result (Just pfix) cnts
284-
| pos ^. JL.line == 0 = case context of
285-
Just (_, kw)
286-
| KeyWord _ <- kw -> J.List $ map buildCompletion $ snd cabalVersionKeyword
287-
_ -> J.List [buildCompletion (fst cabalVersionKeyword)]
288-
| Just ctx <- context = J.List $ makeCompletionItems pfix (getCompletionsForContext ctx)
289-
| otherwise = J.List []
284+
| Just ctx <- context = do
285+
completions <- contextToCompleter ctx
286+
pure $ J.List $ makeCompletionItems pfix completions
287+
| otherwise = pure $ J.List []
290288
where
291289
pos = VFS.cursorPos pfix
292290
context = getContext pos (Rope.lines $ cnts ^. VFS.file_text)

0 commit comments

Comments
 (0)