diff --git a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs index dcbe94376d..1e5ec214df 100644 --- a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs +++ b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs @@ -60,6 +60,7 @@ import Language.LSP.Types import Language.LSP.Types.Capabilities import qualified Language.LSP.VFS as VFS import Outputable (Outputable) +import TyCoRep -- From haskell-ide-engine/hie-plugin-api/Haskell/Ide/Engine/Context.hs @@ -247,9 +248,16 @@ mkNameCompItem doc thingParent origName origMod thingType isInfix docs !imp = CI where argTypes = getArgs typ argText :: T.Text - argText = mconcat $ List.intersperse " " $ zipWithFrom snippet 1 argTypes + argText = mconcat $ List.intersperse " " $ zipWithFrom snippet 1 argTypes snippet :: Int -> Type -> T.Text - snippet i t = "${" <> T.pack (show i) <> ":" <> showGhc t <> "}" + snippet i t = case t of + (TyVarTy _) -> noParensSnippet + (LitTy _) -> noParensSnippet + (TyConApp _ []) -> noParensSnippet + _ -> snippetText i ("(" <> showGhc t <> ")") + where + noParensSnippet = snippetText i (showGhc t) + snippetText i t = "${" <> T.pack (show i) <> ":" <> t <> "}" getArgs :: Type -> [Type] getArgs t | isPredTy t = [] diff --git a/ghcide/test/exe/Main.hs b/ghcide/test/exe/Main.hs index e02f13c709..8c8e47919d 100644 --- a/ghcide/test/exe/Main.hs +++ b/ghcide/test/exe/Main.hs @@ -3900,7 +3900,7 @@ nonLocalCompletionTests = "variable" ["module A where", "f = hea"] (Position 1 7) - [("head", CiFunction, "head ${1:[a]}", True, True, Nothing)], + [("head", CiFunction, "head ${1:([a])}", True, True, Nothing)], completionTest "constructor" ["module A where", "f = Tru"] @@ -3912,20 +3912,20 @@ nonLocalCompletionTests = "type" ["{-# OPTIONS_GHC -Wall #-}", "module A () where", "f :: Bo", "f = True"] (Position 2 7) - [ ("Bounded", CiInterface, "Bounded ${1:*}", True, True, Nothing), + [ ("Bounded", CiInterface, "Bounded ${1:(*)}", True, True, Nothing), ("Bool", CiStruct, "Bool ", True, True, Nothing) ], completionTest "qualified" ["{-# OPTIONS_GHC -Wunused-binds #-}", "module A () where", "f = Prelude.hea"] (Position 2 15) - [ ("head", CiFunction, "head ${1:[a]}", True, True, Nothing) + [ ("head", CiFunction, "head ${1:([a])}", True, True, Nothing) ], completionTest "duplicate import" ["module A where", "import Data.List", "import Data.List", "f = perm"] (Position 3 8) - [ ("permutations", CiFunction, "permutations ${1:[a]}", False, False, Nothing) + [ ("permutations", CiFunction, "permutations ${1:([a])}", False, False, Nothing) ], completionTest "dont show hidden items" diff --git a/test/functional/Completion.hs b/test/functional/Completion.hs index d6deab2065..35af2387cb 100644 --- a/test/functional/Completion.hs +++ b/test/functional/Completion.hs @@ -253,7 +253,7 @@ snippetTests = testGroup "snippets" [ item ^. label @?= "foldl" item ^. kind @?= Just CiFunction item ^. insertTextFormat @?= Just Snippet - item ^. insertText @?= Just "foldl ${1:b -> a -> b} ${2:b} ${3:t a}" + item ^. insertText @?= Just "foldl ${1:(b -> a -> b)} ${2:b} ${3:(t a)}" , testCase "work for complex types" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do doc <- openDoc "Completion.hs" "haskell" @@ -267,7 +267,7 @@ snippetTests = testGroup "snippets" [ item ^. label @?= "mapM" item ^. kind @?= Just CiFunction item ^. insertTextFormat @?= Just Snippet - item ^. insertText @?= Just "mapM ${1:a -> m b} ${2:t a}" + item ^. insertText @?= Just "mapM ${1:(a -> m b)} ${2:(t a)}" , testCase "work for infix functions" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do doc <- openDoc "Completion.hs" "haskell"