From 769fb91347f07b3a5a290b7eaa668ac692236ba7 Mon Sep 17 00:00:00 2001 From: Oliver Madine Date: Sun, 11 Apr 2021 11:55:23 +0100 Subject: [PATCH 01/11] Enhancement: #1700 --- ghcide/src/Development/IDE/Plugin/Completions/Logic.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs index dcbe94376d..e9a759d1ae 100644 --- a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs +++ b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs @@ -247,7 +247,7 @@ 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 (\i t -> T.pack "(_ :: " <> snippet i t <> T.pack ")") 1 argTypes snippet :: Int -> Type -> T.Text snippet i t = "${" <> T.pack (show i) <> ":" <> showGhc t <> "}" getArgs :: Type -> [Type] From 0fe27e6b872337ab8ac8b886a9614898a90952b4 Mon Sep 17 00:00:00 2001 From: Oliver Madine Date: Mon, 12 Apr 2021 00:25:52 +0100 Subject: [PATCH 02/11] changed bracketed typed hole completions to regular bracketed completions --- .../Development/IDE/Plugin/Completions/Logic.hs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs index e9a759d1ae..466820f6ac 100644 --- a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs +++ b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs @@ -43,7 +43,7 @@ import Data.Functor import qualified Data.Set as Set import Development.IDE.Core.Compile import Development.IDE.Core.PositionMapping -import Development.IDE.GHC.Compat as GHC +import Development.IDE.GHC.Compat as GHC hiding (FunTy) import Development.IDE.GHC.Error import Development.IDE.GHC.Util import Development.IDE.Plugin.Completions.Types @@ -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,15 @@ mkNameCompItem doc thingParent origName origMod thingType isInfix docs !imp = CI where argTypes = getArgs typ argText :: T.Text - argText = mconcat $ List.intersperse " " $ zipWithFrom (\i t -> T.pack "(_ :: " <> snippet i t <> T.pack ")") 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 + _ -> snippetText i (T.pack "(" <> showGhc t <> T.pack ")") + where + snippetText i t = "${" <> T.pack (show i) <> ":" <> t <> "}" + noParensSnippet = snippetText i (showGhc t) getArgs :: Type -> [Type] getArgs t | isPredTy t = [] @@ -762,3 +769,5 @@ getImportQual :: LImportDecl GhcPs -> Maybe T.Text getImportQual (L _ imp) | isQualifiedImport imp = Just $ T.pack $ moduleNameString $ maybe (unLoc $ ideclName imp) unLoc (ideclAs imp) | otherwise = Nothing + +--foo = CI CompletionItemKind Text Either SrcSpan Text Maybe Text Text Maybe Backtick SpanDoc Bool Maybe ExtendImport From 3d55a8c44b5f174f30ea97f9beca32c1d2ea495e Mon Sep 17 00:00:00 2001 From: Oliver Madine Date: Mon, 12 Apr 2021 00:30:24 +0100 Subject: [PATCH 03/11] removed redudant comment --- ghcide/src/Development/IDE/Plugin/Completions/Logic.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs index 466820f6ac..110192e6a7 100644 --- a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs +++ b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs @@ -770,4 +770,3 @@ getImportQual (L _ imp) | isQualifiedImport imp = Just $ T.pack $ moduleNameString $ maybe (unLoc $ ideclName imp) unLoc (ideclAs imp) | otherwise = Nothing ---foo = CI CompletionItemKind Text Either SrcSpan Text Maybe Text Text Maybe Backtick SpanDoc Bool Maybe ExtendImport From f0b0b66a8e0dfd8ec5e20ab334a607cdc798022b Mon Sep 17 00:00:00 2001 From: Oliver Madine Date: Mon, 12 Apr 2021 00:31:57 +0100 Subject: [PATCH 04/11] removed whitespace --- ghcide/src/Development/IDE/Plugin/Completions/Logic.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs index 110192e6a7..eba515ba4c 100644 --- a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs +++ b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs @@ -769,4 +769,3 @@ getImportQual :: LImportDecl GhcPs -> Maybe T.Text getImportQual (L _ imp) | isQualifiedImport imp = Just $ T.pack $ moduleNameString $ maybe (unLoc $ ideclName imp) unLoc (ideclAs imp) | otherwise = Nothing - From a4780775326b121d0e9ae5b421bb3806e0ce3721 Mon Sep 17 00:00:00 2001 From: Oliver Madine Date: Mon, 12 Apr 2021 05:28:32 +0100 Subject: [PATCH 05/11] Updated test cases to expect bracketed completions, Type constructors with no arguments no longer bracketed --- ghcide/bench/example/HLS | 1 - ghcide/src/Development/IDE/Plugin/Completions/Logic.hs | 9 +++++---- ghcide/test/exe/Main.hs | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) delete mode 120000 ghcide/bench/example/HLS diff --git a/ghcide/bench/example/HLS b/ghcide/bench/example/HLS deleted file mode 120000 index a8a4f8c212..0000000000 --- a/ghcide/bench/example/HLS +++ /dev/null @@ -1 +0,0 @@ -../../.. \ No newline at end of file diff --git a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs index eba515ba4c..14c4a66585 100644 --- a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs +++ b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs @@ -251,12 +251,13 @@ mkNameCompItem doc thingParent origName origMod thingType isInfix docs !imp = CI argText = mconcat $ List.intersperse " " $ zipWithFrom snippet 1 argTypes snippet :: Int -> Type -> T.Text snippet i t = case t of - (TyVarTy _) -> noParensSnippet - (LitTy _) -> noParensSnippet - _ -> snippetText i (T.pack "(" <> showGhc t <> T.pack ")") + (TyVarTy _) -> noParensSnippet + (LitTy _) -> noParensSnippet + (TyConApp _ []) -> noParensSnippet + _ -> snippetText i (T.pack "(" <> showGhc t <> T.pack ")") where - snippetText i t = "${" <> T.pack (show i) <> ":" <> t <> "}" 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" From bc8dc5ff24450fefca0b5827bc8689404be9a9e6 Mon Sep 17 00:00:00 2001 From: Oliver Madine Date: Mon, 12 Apr 2021 07:24:45 +0100 Subject: [PATCH 06/11] Updated hls tests for bracketed completions --- ghcide/src/Development/IDE/Plugin/Completions/Logic.hs | 2 +- test/functional/Completion.hs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs index 14c4a66585..65f079d619 100644 --- a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs +++ b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs @@ -43,7 +43,7 @@ import Data.Functor import qualified Data.Set as Set import Development.IDE.Core.Compile import Development.IDE.Core.PositionMapping -import Development.IDE.GHC.Compat as GHC hiding (FunTy) +import Development.IDE.GHC.Compat as GHC import Development.IDE.GHC.Error import Development.IDE.GHC.Util import Development.IDE.Plugin.Completions.Types 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" From a935c51a73bf774af2670e462bd20a915f4f6f6a Mon Sep 17 00:00:00 2001 From: Oliver Madine Date: Mon, 12 Apr 2021 07:48:05 +0100 Subject: [PATCH 07/11] added missing ghcide/example/HLS file --- ghcide/example/HLS | 1 + 1 file changed, 1 insertion(+) create mode 100644 ghcide/example/HLS diff --git a/ghcide/example/HLS b/ghcide/example/HLS new file mode 100644 index 0000000000..f95f775b78 --- /dev/null +++ b/ghcide/example/HLS @@ -0,0 +1 @@ +../../.. From 4732c54f0d6de8aa903eacf630b0c04a6aa7bd03 Mon Sep 17 00:00:00 2001 From: Oliver Madine Date: Mon, 12 Apr 2021 07:50:53 +0100 Subject: [PATCH 08/11] moved ghcide/examoke.HLS to ghcide/bench/example/HLS --- ghcide/example/HLS | 1 - 1 file changed, 1 deletion(-) delete mode 100644 ghcide/example/HLS diff --git a/ghcide/example/HLS b/ghcide/example/HLS deleted file mode 100644 index f95f775b78..0000000000 --- a/ghcide/example/HLS +++ /dev/null @@ -1 +0,0 @@ -../../.. From 53c4be9ef1877f33096de99b3cbf353f1d3412fe Mon Sep 17 00:00:00 2001 From: Oliver Madine <30090176+OliverMadine@users.noreply.github.com> Date: Mon, 12 Apr 2021 18:08:21 +0100 Subject: [PATCH 09/11] Restored ghcide/bench/example/HLS --- ghcide/bench/example/HLS | 1 + 1 file changed, 1 insertion(+) create mode 100644 ghcide/bench/example/HLS diff --git a/ghcide/bench/example/HLS b/ghcide/bench/example/HLS new file mode 100644 index 0000000000..f95f775b78 --- /dev/null +++ b/ghcide/bench/example/HLS @@ -0,0 +1 @@ +../../.. From 4756478aeb76c2779e6b938a325709f2fed6e887 Mon Sep 17 00:00:00 2001 From: Oliver Madine Date: Mon, 12 Apr 2021 18:14:10 +0100 Subject: [PATCH 10/11] restored ghcide/bench/example/HLS --- ghcide/bench/example/HLS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 120000 ghcide/bench/example/HLS diff --git a/ghcide/bench/example/HLS b/ghcide/bench/example/HLS deleted file mode 100644 index f95f775b78..0000000000 --- a/ghcide/bench/example/HLS +++ /dev/null @@ -1 +0,0 @@ -../../.. diff --git a/ghcide/bench/example/HLS b/ghcide/bench/example/HLS new file mode 120000 index 0000000000..a8a4f8c212 --- /dev/null +++ b/ghcide/bench/example/HLS @@ -0,0 +1 @@ +../../.. \ No newline at end of file From fe6f7d88f4cc44ebba5377d0791cbc958ce4ec67 Mon Sep 17 00:00:00 2001 From: Oliver Madine Date: Tue, 13 Apr 2021 03:07:29 +0100 Subject: [PATCH 11/11] removed unnecessary 'T.pack' (OverloadedStrings) --- ghcide/src/Development/IDE/Plugin/Completions/Logic.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs index 65f079d619..1e5ec214df 100644 --- a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs +++ b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs @@ -254,7 +254,7 @@ mkNameCompItem doc thingParent origName origMod thingType isInfix docs !imp = CI (TyVarTy _) -> noParensSnippet (LitTy _) -> noParensSnippet (TyConApp _ []) -> noParensSnippet - _ -> snippetText i (T.pack "(" <> showGhc t <> T.pack ")") + _ -> snippetText i ("(" <> showGhc t <> ")") where noParensSnippet = snippetText i (showGhc t) snippetText i t = "${" <> T.pack (show i) <> ":" <> t <> "}"