Skip to content

Commit

Permalink
Return completion snippets only when client supports it (haskell/ghci…
Browse files Browse the repository at this point in the history
…de#929)

* Use the real client capabilities on completions

* Return completion snippets only when supported by the client

Restored from haskell/ghcide#900
  • Loading branch information
pepeiborra authored Nov 29, 2020
1 parent 5905aa8 commit 219ee8b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions ghcide/src/Development/IDE/Core/Service.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ initialise caps mainRule getLspId toDiags wProg wIndefProg logger debouncer opti
toDiags
wProg
wIndefProg
caps
logger
debouncer
(optShakeProfiling options)
Expand Down
5 changes: 4 additions & 1 deletion ghcide/src/Development/IDE/Core/Shake.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ import UniqSupply
import PrelInfo
import Data.Int (Int64)
import qualified Data.HashSet as HSet
import Language.Haskell.LSP.Types.Capabilities

-- information we stash inside the shakeExtra field
data ShakeExtras = ShakeExtras
Expand Down Expand Up @@ -164,6 +165,7 @@ data ShakeExtras = ShakeExtras
,exportsMap :: Var ExportsMap
-- | A work queue for actions added via 'runInShakeSession'
,actionQueue :: ActionQueue
,clientCapabilities :: ClientCapabilities
}

-- | A mapping of module name to known files
Expand Down Expand Up @@ -401,6 +403,7 @@ shakeOpen :: IO LSP.LspId
-> (LSP.FromServerMessage -> IO ()) -- ^ diagnostic handler
-> WithProgressFunc
-> WithIndefiniteProgressFunc
-> ClientCapabilities
-> Logger
-> Debouncer NormalizedUri
-> Maybe FilePath
Expand All @@ -409,7 +412,7 @@ shakeOpen :: IO LSP.LspId
-> ShakeOptions
-> Rules ()
-> IO IdeState
shakeOpen getLspId eventer withProgress withIndefiniteProgress logger debouncer
shakeOpen getLspId eventer withProgress withIndefiniteProgress clientCapabilities logger debouncer
shakeProfileDir (IdeReportProgress reportProgress) ideTesting@(IdeTesting testing) opts rules = mdo

inProgress <- newVar HMap.empty
Expand Down
7 changes: 3 additions & 4 deletions ghcide/src/Development/IDE/Plugin/Completions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Language.Haskell.LSP.Messages
import Language.Haskell.LSP.Types
import qualified Language.Haskell.LSP.Core as LSP
import qualified Language.Haskell.LSP.VFS as VFS
import Language.Haskell.LSP.Types.Capabilities

import Development.Shake.Classes
import Development.Shake
import GHC.Generics
Expand Down Expand Up @@ -142,9 +142,8 @@ getCompletionsLSP lsp ide
(Just (VFS.PosPrefixInfo _ "" _ _), Just CompletionContext { _triggerCharacter = Just "."})
-> return (Completions $ List [])
(Just pfix', _) -> do
-- TODO pass the real capabilities here (or remove the logic for snippets)
let fakeClientCapabilities = ClientCapabilities Nothing Nothing Nothing Nothing
Completions . List <$> getCompletions ideOpts cci' parsedMod bindMap pfix' fakeClientCapabilities (WithSnippets True)
let clientCaps = clientCapabilities $ shakeExtras ide
Completions . List <$> getCompletions ideOpts cci' parsedMod bindMap pfix' clientCaps (WithSnippets True)
_ -> return (Completions $ List [])
_ -> return (Completions $ List [])
_ -> return (Completions $ List [])
Expand Down
9 changes: 6 additions & 3 deletions ghcide/src/Development/IDE/Plugin/Completions/Logic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,13 @@ newtype WithSnippets = WithSnippets Bool

toggleSnippets :: ClientCapabilities -> WithSnippets -> CompletionItem -> CompletionItem
toggleSnippets ClientCapabilities { _textDocument } (WithSnippets with) x
| with = x
| with && supported = x
| otherwise = x { _insertTextFormat = Just PlainText
, _insertText = Nothing
}
, _insertText = Nothing
}
where
supported =
Just True == (_textDocument >>= _completion >>= _completionItem >>= _snippetSupport)

-- | Returns the cached completions for the given module and position.
getCompletions
Expand Down

0 comments on commit 219ee8b

Please sign in to comment.