Skip to content

Commit ba46353

Browse files
authored
Merge pull request #266 from pepeiborra/retrie
Initial Retrie plugin
2 parents 6c7b43a + 366e8b6 commit ba46353

14 files changed

+600
-36
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ This is *very* early stage software.
7171
7272
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).
7373
74+
- Integration with [retrie](https://hackage.haskell.org/package/retrie)
75+
76+
![Retrie](https://i.imgur.com/fEKjrUG.gif)
77+
7478
- Many more (TBD)
7579
7680
## Installation

exe/Main.hs

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import Ide.Plugin.GhcIde as GhcIde
6969
import Ide.Plugin.Floskell as Floskell
7070
import Ide.Plugin.Ormolu as Ormolu
7171
import Ide.Plugin.StylishHaskell as StylishHaskell
72+
import Ide.Plugin.Retrie as Retrie
7273
#if AGPL
7374
import Ide.Plugin.Brittany as Brittany
7475
#endif
@@ -105,6 +106,7 @@ idePlugins includeExamples = pluginDescToIdePlugins allPlugins
105106
-- , ghcmodDescriptor "ghcmod"
106107
, Ormolu.descriptor "ormolu"
107108
, StylishHaskell.descriptor "stylish-haskell"
109+
, Retrie.descriptor "retrie"
108110
#if AGPL
109111
, Brittany.descriptor "brittany"
110112
#endif

haskell-language-server.cabal

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ build-type: Simple
1515
extra-source-files:
1616
README.md
1717
ChangeLog.md
18+
include/ghc-api-version.h
1819

1920
flag agpl
2021
Description: Enable AGPL dependencies
@@ -47,6 +48,7 @@ library
4748
Ide.Plugin.GhcIde
4849
Ide.Plugin.Ormolu
4950
Ide.Plugin.Pragmas
51+
Ide.Plugin.Retrie
5052
Ide.Plugin.Floskell
5153
Ide.Plugin.Formatter
5254
Ide.Plugin.StylishHaskell
@@ -83,13 +85,17 @@ library
8385
, optparse-simple
8486
, process
8587
, regex-tdfa >= 1.3.1.0
88+
, retrie >= 0.1.1.0
89+
, safe-exceptions
8690
, shake >= 0.17.5
8791
, stylish-haskell == 0.11.*
8892
, temporary
8993
, text
9094
, time
9195
, transformers
9296
, unordered-containers
97+
include-dirs:
98+
include
9399
if os(windows)
94100
build-depends: Win32
95101
else

include/ghc-api-version.h

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef GHC_API_VERSION_H
2+
#define GHC_API_VERSION_H
3+
4+
#ifdef GHC_LIB
5+
#define MIN_GHC_API_VERSION(x,y,z) MIN_VERSION_ghc_lib(x,y,z)
6+
#else
7+
#define MIN_GHC_API_VERSION(x,y,z) MIN_VERSION_ghc(x,y,z)
8+
#endif
9+
10+
#endif

shell.nix

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ let defaultCompiler = "ghc" + lib.replaceStrings ["."] [""] haskellPackages.ghc.
1717
# for all other compilers there is no Nix cache so dont bother building deps with NIx
1818
else haskell.packages.${compiler}.ghcWithPackages (_: []);
1919

20-
compilerWithPackages = haskellPackagesForProject(p:
20+
retrie = with haskell.lib; dontCheck(disableLibraryProfiling(haskellPackages.retrie));
21+
compilerWithPackages = haskellPackagesForProject(p:
2122
with p;
2223
[
2324
Diff
@@ -66,6 +67,7 @@ let defaultCompiler = "ghc" + lib.replaceStrings ["."] [""] haskellPackages.ghc.
6667
primes
6768
psqueues
6869
regex-tdfa
70+
retrie
6971
rope-utf16-splay
7072
safe-exceptions
7173
shake

src/Ide/Plugin.hs

+10-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module Ide.Plugin
1818
, responseError
1919
) where
2020

21+
import Control.Exception(SomeException, catch)
2122
import Control.Lens ( (^.) )
2223
import Control.Monad
2324
import qualified Data.Aeson as J
@@ -206,7 +207,7 @@ executeCommandHandlers ecs = PartialHandlers $ \WithMessage{..} x -> return x{
206207
-- -> ExecuteCommandParams
207208
-- -> IO (Either ResponseError Value, Maybe (ServerMethod, ApplyWorkspaceEditParams))
208209
makeExecuteCommands :: [(PluginId, [PluginCommand])] -> LSP.LspFuncs Config -> ExecuteCommandProvider
209-
makeExecuteCommands ecs lf ide = do
210+
makeExecuteCommands ecs lf ide = wrapUnhandledExceptions $ do
210211
let
211212
pluginMap = Map.fromList ecs
212213
parseCmdId :: T.Text -> Maybe (PluginId, CommandId)
@@ -331,6 +332,14 @@ makeExecuteCommands ecs lf ide = do
331332
-}
332333

333334
-- -----------------------------------------------------------
335+
wrapUnhandledExceptions ::
336+
(a -> IO (Either ResponseError J.Value, Maybe b)) ->
337+
a -> IO (Either ResponseError J.Value, Maybe b)
338+
wrapUnhandledExceptions action input =
339+
catch (action input) $ \(e::SomeException) -> do
340+
let resp = ResponseError InternalError (T.pack $ show e) Nothing
341+
return (Left resp, Nothing)
342+
334343

335344
-- | Runs a plugin command given a PluginId, CommandId and
336345
-- arguments in the form of a JSON object.

0 commit comments

Comments
 (0)