Skip to content

Commit 466ec47

Browse files
committed
Remove snippets for infix forms
1 parent 843cad2 commit 466ec47

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

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

+27-7
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,21 @@ showModName = T.pack . moduleNameString
159159
-- Nothing Nothing Nothing Nothing Nothing
160160

161161
mkCompl :: PluginId -> IdeOptions -> CompItem -> IO CompletionItem
162-
mkCompl pId IdeOptions{..} CI{compKind,insertText, importedFrom,typeText,label,docs, additionalTextEdits} = do
162+
mkCompl
163+
pId
164+
IdeOptions {..}
165+
CI
166+
{ compKind,
167+
isInfix,
168+
insertText,
169+
importedFrom,
170+
typeText,
171+
label,
172+
docs,
173+
additionalTextEdits
174+
} = do
163175
mbCommand <- mkAdditionalEditsCommand pId `traverse` additionalTextEdits
164-
return CompletionItem
176+
let ci = CompletionItem
165177
{_label = label,
166178
_kind = kind,
167179
_tags = Nothing,
@@ -178,6 +190,7 @@ mkCompl pId IdeOptions{..} CI{compKind,insertText, importedFrom,typeText,label,d
178190
_commitCharacters = Nothing,
179191
_command = mbCommand,
180192
_xdata = Nothing}
193+
return $ removeSnippetsWhen (isJust isInfix) ci
181194

182195
where kind = Just compKind
183196
docs' = imported : spanDocToMarkdown docs
@@ -446,15 +459,22 @@ ppr :: Outputable a => a -> T.Text
446459
ppr = T.pack . prettyPrint
447460

448461
toggleSnippets :: ClientCapabilities -> WithSnippets -> CompletionItem -> CompletionItem
449-
toggleSnippets ClientCapabilities { _textDocument } (WithSnippets with) x
450-
| with && supported = x
451-
| otherwise = x { _insertTextFormat = Just PlainText
452-
, _insertText = Nothing
453-
}
462+
toggleSnippets ClientCapabilities {_textDocument} (WithSnippets with) =
463+
removeSnippetsWhen (not $ with && supported)
454464
where
455465
supported =
456466
Just True == (_textDocument >>= _completion >>= _completionItem >>= _snippetSupport)
457467

468+
removeSnippetsWhen :: Bool -> CompletionItem -> CompletionItem
469+
removeSnippetsWhen condition x =
470+
if condition
471+
then
472+
x
473+
{ _insertTextFormat = Just PlainText,
474+
_insertText = Nothing
475+
}
476+
else x
477+
458478
-- | Returns the cached completions for the given module and position.
459479
getCompletions
460480
:: PluginId

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

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Data.Aeson (FromJSON, ToJSON)
1414
import Data.Text (Text)
1515
import GHC.Generics (Generic)
1616
import Language.Haskell.LSP.Types (CompletionItemKind, Uri)
17+
1718
data Backtick = Surrounded | LeftSide
1819
deriving (Eq, Ord, Show)
1920

@@ -28,6 +29,7 @@ data ExtendImport = ExtendImport
2829
}
2930
deriving (Eq, Show, Generic)
3031
deriving anyclass (FromJSON, ToJSON)
32+
3133
data CompItem = CI
3234
{ compKind :: CompletionItemKind
3335
, insertText :: T.Text -- ^ Snippet for the completion

test/functional/Completion.hs

+8-8
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ snippetTests = testGroup "snippets" [
286286
liftIO $ do
287287
item ^. label @?= "filter"
288288
item ^. kind @?= Just CiFunction
289-
item ^. insertTextFormat @?= Just Snippet
290-
item ^. insertText @?= Just "filter ${1:a -> Bool} ${2:[a]}"
289+
item ^. insertTextFormat @?= Just PlainText
290+
item ^. insertText @?= Nothing
291291

292292
, testCase "work for infix functions in backticks" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do
293293
doc <- openDoc "Completion.hs" "haskell"
@@ -300,8 +300,8 @@ snippetTests = testGroup "snippets" [
300300
liftIO $ do
301301
item ^. label @?= "filter"
302302
item ^. kind @?= Just CiFunction
303-
item ^. insertTextFormat @?= Just Snippet
304-
item ^. insertText @?= Just "filter ${1:a -> Bool} ${2:[a]}"
303+
item ^. insertTextFormat @?= Just PlainText
304+
item ^. insertText @?= Nothing
305305

306306
, testCase "work for qualified infix functions" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do
307307
doc <- openDoc "Completion.hs" "haskell"
@@ -314,8 +314,8 @@ snippetTests = testGroup "snippets" [
314314
liftIO $ do
315315
item ^. label @?= "intersperse"
316316
item ^. kind @?= Just CiFunction
317-
item ^. insertTextFormat @?= Just Snippet
318-
item ^. insertText @?= Just "intersperse ${1:a} ${2:[a]}"
317+
item ^. insertTextFormat @?= Just PlainText
318+
item ^. insertText @?= Nothing
319319

320320
, testCase "work for qualified infix functions in backticks" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do
321321
doc <- openDoc "Completion.hs" "haskell"
@@ -328,8 +328,8 @@ snippetTests = testGroup "snippets" [
328328
liftIO $ do
329329
item ^. label @?= "intersperse"
330330
item ^. kind @?= Just CiFunction
331-
item ^. insertTextFormat @?= Just Snippet
332-
item ^. insertText @?= Just "intersperse ${1:a} ${2:[a]}"
331+
item ^. insertTextFormat @?= Just PlainText
332+
item ^. insertText @?= Nothing
333333

334334
, testCase "respects lsp configuration" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do
335335
doc <- openDoc "Completion.hs" "haskell"

0 commit comments

Comments
 (0)