Skip to content

Commit 81791f1

Browse files
committed
move options pragmas to pragmas plugin
return empty list from logic completions when opts or pragma start fix empty list logic
1 parent 560aa7b commit 81791f1

File tree

2 files changed

+22
-18
lines changed
  • ghcide/src/Development/IDE/Plugin/Completions
  • plugins/hls-pragmas-plugin/src/Ide/Plugin

2 files changed

+22
-18
lines changed

ghcide/src/Development/IDE/Plugin/Completions/Logic.hs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -596,26 +596,18 @@ getCompletions plId ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls, qu
596596
]
597597

598598
filtImportCompls = filtListWith (mkImportCompl enteredQual) importableModules
599-
filtOptsCompls = filtListWith mkExtCompl
600599
filtKeywordCompls
601600
| T.null prefixModule = filtListWith mkExtCompl (optKeywords ideOpts)
602601
| otherwise = []
603602

604-
stripLeading :: Char -> String -> String
605-
stripLeading _ [] = []
606-
stripLeading c (s:ss)
607-
| s == c = ss
608-
| otherwise = s:ss
609603

610604
if
611605
| "import " `T.isPrefixOf` fullLine
612606
-> return filtImportCompls
613607
-- we leave this condition here to avoid duplications and return empty list
614-
-- since HLS implements this completion (#haskell-language-server/pull/662)
615-
| "{-# language" `T.isPrefixOf` T.toLower fullLine
608+
-- since HLS implements these completions (#haskell-language-server/pull/662)
609+
| "{-# " `T.isPrefixOf` fullLine
616610
-> return []
617-
| "{-# options_ghc" `T.isPrefixOf` T.toLower fullLine
618-
-> return $ filtOptsCompls (map (T.pack . stripLeading '-') $ flagsForCompletion False)
619611
| otherwise -> do
620612
-- assumes that nubOrdBy is stable
621613
let uniqueFiltCompls = nubOrdBy uniqueCompl filtCompls
@@ -637,14 +629,6 @@ uniqueCompl x y =
637629
then EQ
638630
else compare (insertText x) (insertText y)
639631
other -> other
640-
-- ---------------------------------------------------------------------
641-
-- helper functions for pragmas
642-
-- ---------------------------------------------------------------------
643-
644-
pragmaSuffix :: T.Text -> T.Text
645-
pragmaSuffix fullLine
646-
| "}" `T.isSuffixOf` fullLine = mempty
647-
| otherwise = " #-}"
648632

649633
-- ---------------------------------------------------------------------
650634
-- helper functions for infix backticks

plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ allPragmas =
150150

151151
-- ---------------------------------------------------------------------
152152

153+
flags :: [T.Text]
154+
flags = map (T.pack . stripLeading '-') $ flagsForCompletion False
155+
153156
completion :: PluginMethodHandler IdeState 'J.TextDocumentCompletion
154157
completion _ide _ complParams = do
155158
let (J.TextDocumentIdentifier uri) = complParams ^. J.textDocument
@@ -163,6 +166,9 @@ completion _ide _ complParams = do
163166
| "{-# LANGUAGE" `T.isPrefixOf` VFS.fullLine pfix
164167
= J.List $ map buildCompletion
165168
(Fuzzy.simpleFilter (VFS.prefixText pfix) allPragmas)
169+
| "{-# options_ghc" `T.isPrefixOf` T.toLower (VFS.fullLine pfix)
170+
= J.List $ map mkExtCompl
171+
(Fuzzy.simpleFilter (VFS.prefixText pfix) flags)
166172
-- if there already is a closing bracket - complete without one
167173
| isPragmaPrefix (VFS.fullLine pfix) && "}" `T.isSuffixOf` VFS.fullLine pfix
168174
= J.List $ map (\(a, b, c) -> mkPragmaCompl a b c) (validPragmas Nothing)
@@ -248,3 +254,17 @@ checkPragma name = check
248254
check l = isPragma l && getName l == name
249255
getName l = T.take (T.length name) $ T.dropWhile isSpace $ T.drop 3 l
250256
isPragma = T.isPrefixOf "{-#"
257+
258+
259+
stripLeading :: Char -> String -> String
260+
stripLeading _ [] = []
261+
stripLeading c (s:ss)
262+
| s == c = ss
263+
| otherwise = s:ss
264+
265+
266+
mkExtCompl :: T.Text -> J.CompletionItem
267+
mkExtCompl label =
268+
J.CompletionItem label (Just J.CiKeyword) Nothing Nothing
269+
Nothing Nothing Nothing Nothing Nothing Nothing Nothing
270+
Nothing Nothing Nothing Nothing Nothing Nothing

0 commit comments

Comments
 (0)