Skip to content

Commit

Permalink
Bracketing for snippet completions (#1709)
Browse files Browse the repository at this point in the history
* Enhancement: #1700

* changed bracketed typed hole completions to regular bracketed completions

* removed redudant comment

* removed whitespace

* Updated test cases to expect bracketed completions, Type constructors with no arguments no longer bracketed

* Updated hls tests for bracketed completions

* added missing ghcide/example/HLS file

* moved ghcide/examoke.HLS to ghcide/bench/example/HLS

* Restored ghcide/bench/example/HLS

* restored ghcide/bench/example/HLS

* removed unnecessary 'T.pack' (OverloadedStrings)

Co-authored-by: Oliver Madine <[email protected]>
Co-authored-by: Junyoung/Clare Jang <[email protected]>
Co-authored-by: Potato Hatsue <[email protected]>
  • Loading branch information
4 people authored Apr 13, 2021
1 parent d2bb0d9 commit f933011
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
12 changes: 10 additions & 2 deletions ghcide/src/Development/IDE/Plugin/Completions/Logic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = []
Expand Down
8 changes: 4 additions & 4 deletions ghcide/test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions test/functional/Completion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit f933011

Please sign in to comment.