Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Retrie plugin #266

Merged
merged 13 commits into from
Aug 3, 2020
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ This is *very* early stage software.

This will cause compilation errors if a dependency contains invalid Haddock markup, though in a future version of GHC (hopefully 8.12), [these will be demoted to warnings](https://gitlab.haskell.org/ghc/ghc/-/merge_requests/2377).

- Integration with [retrie](https://hackage.haskell.org/package/retrie)

![Retrie](https://i.imgur.com/VFKx1He.gif)
pepeiborra marked this conversation as resolved.
Show resolved Hide resolved

- Many more (TBD)

## Installation
Expand Down
2 changes: 2 additions & 0 deletions exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import Ide.Plugin.GhcIde as GhcIde
import Ide.Plugin.Floskell as Floskell
import Ide.Plugin.Ormolu as Ormolu
import Ide.Plugin.StylishHaskell as StylishHaskell
import Ide.Plugin.Retrie as Retrie
#if AGPL
import Ide.Plugin.Brittany as Brittany
#endif
Expand Down Expand Up @@ -105,6 +106,7 @@ idePlugins includeExamples = pluginDescToIdePlugins allPlugins
-- , ghcmodDescriptor "ghcmod"
, Ormolu.descriptor "ormolu"
, StylishHaskell.descriptor "stylish-haskell"
, Retrie.descriptor "retrie"
#if AGPL
, Brittany.descriptor "brittany"
#endif
Expand Down
3 changes: 3 additions & 0 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ library
Ide.Plugin.GhcIde
Ide.Plugin.Ormolu
Ide.Plugin.Pragmas
Ide.Plugin.Retrie
Ide.Plugin.Floskell
Ide.Plugin.Formatter
Ide.Plugin.StylishHaskell
Expand Down Expand Up @@ -83,6 +84,8 @@ library
, optparse-simple
, process
, regex-tdfa >= 1.3.1.0
, retrie >= 0.1.1.0
, safe-exceptions
, shake >= 0.17.5
, stylish-haskell == 0.11.*
, temporary
Expand Down
4 changes: 3 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ let defaultCompiler = "ghc" + lib.replaceStrings ["."] [""] haskellPackages.ghc.
# for all other compilers there is no Nix cache so dont bother building deps with NIx
else haskell.packages.${compiler}.ghcWithPackages (_: []);

compilerWithPackages = haskellPackagesForProject(p:
retrie = with haskell.lib; dontCheck(disableLibraryProfiling(haskellPackages.retrie));
compilerWithPackages = haskellPackagesForProject(p:
with p;
[
Diff
Expand Down Expand Up @@ -66,6 +67,7 @@ let defaultCompiler = "ghc" + lib.replaceStrings ["."] [""] haskellPackages.ghc.
primes
psqueues
regex-tdfa
retrie
rope-utf16-splay
safe-exceptions
shake
Expand Down
11 changes: 10 additions & 1 deletion src/Ide/Plugin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module Ide.Plugin
, responseError
) where

import Control.Exception(SomeException, catch)
import Control.Lens ( (^.) )
import Control.Monad
import qualified Data.Aeson as J
Expand Down Expand Up @@ -206,7 +207,7 @@ executeCommandHandlers ecs = PartialHandlers $ \WithMessage{..} x -> return x{
-- -> ExecuteCommandParams
-- -> IO (Either ResponseError Value, Maybe (ServerMethod, ApplyWorkspaceEditParams))
makeExecuteCommands :: [(PluginId, [PluginCommand])] -> LSP.LspFuncs Config -> ExecuteCommandProvider
makeExecuteCommands ecs lf ide = do
makeExecuteCommands ecs lf ide = wrapUnhandledExceptions $ do
let
pluginMap = Map.fromList ecs
parseCmdId :: T.Text -> Maybe (PluginId, CommandId)
Expand Down Expand Up @@ -334,6 +335,14 @@ makeExecuteCommands ecs lf ide = do

-- | Runs a plugin command given a PluginId, CommandId and
-- arguments in the form of a JSON object.
wrapUnhandledExceptions ::
pepeiborra marked this conversation as resolved.
Show resolved Hide resolved
(a -> IO (Either ResponseError J.Value, Maybe b)) ->
a -> IO (Either ResponseError J.Value, Maybe b)
wrapUnhandledExceptions action input =
catch (action input) $ \(e::SomeException) -> do
let resp = ResponseError InternalError (T.pack $ show e) Nothing
return (Left resp, Nothing)

runPluginCommand :: Map.Map PluginId [PluginCommand]
-> LSP.LspFuncs Config
-> IdeState
Expand Down
Loading