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
6 changes: 6 additions & 0 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ build-type: Simple
extra-source-files:
README.md
ChangeLog.md
include/ghc-api-version.h

flag agpl
Description: Enable AGPL dependencies
Expand Down Expand Up @@ -47,6 +48,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,13 +85,17 @@ 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
, text
, time
, transformers
, unordered-containers
include-dirs:
include
if os(windows)
build-depends: Win32
else
Expand Down
10 changes: 10 additions & 0 deletions include/ghc-api-version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef GHC_API_VERSION_H
#define GHC_API_VERSION_H

#ifdef GHC_LIB
#define MIN_GHC_API_VERSION(x,y,z) MIN_VERSION_ghc_lib(x,y,z)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean we can build hls with -fghc-lib now? That might solve the hlint ghc-lib mismatch issue @jneira

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know about that, I have never tried to build ghcide with ghc-lib. Ping @cocreature

#else
#define MIN_GHC_API_VERSION(x,y,z) MIN_VERSION_ghc(x,y,z)
#endif

#endif
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 @@ -331,6 +332,14 @@ makeExecuteCommands ecs lf ide = do
-}

-- -----------------------------------------------------------
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)


-- | Runs a plugin command given a PluginId, CommandId and
-- arguments in the form of a JSON object.
Expand Down
Loading