on master help sign in
Support plugins (#192)
3bec234Jinwoo Lee
ghcide.cabal+1
@@ -187,6 +187,7 @@ test-suite ghcide-tests
187 ghc,
187 ghc,
188 --------------------------------------------------------------
188 --------------------------------------------------------------
189 ghcide,
189 ghcide,
190+ ghc-typelits-knownnat,
190 haskell-lsp-types,
191 haskell-lsp-types,
191 lens,
192 lens,
192 lsp-test >= 0.8,
193 lsp-test >= 0.8,
src/Development/IDE/Core/Compile.hs+17−1
@@ -28,6 +28,10 @@ import qualified GHC.LanguageExtensions.Type as GHC
28import Development.IDE.Types.Options
28import Development.IDE.Types.Options
29import Development.IDE.Types.Location
29import Development.IDE.Types.Location
30
30
31+#if MIN_GHC_API_VERSION(8,6,0)
32+import DynamicLoading (initializePlugins)
33+#endif
34+
31import GHC hiding (parseModule, typecheckModule)
35import GHC hiding (parseModule, typecheckModule)
32import qualified Parser
36import qualified Parser
33import Lexer
37import Lexer
@@ -95,11 +99,23 @@ typecheckModule (IdeDefer defer) packageState deps pm =
95 runGhcEnv packageState $
99 runGhcEnv packageState $
96 catchSrcErrors "typecheck" $ do
100 catchSrcErrors "typecheck" $ do
97 setupEnv deps
101 setupEnv deps
102+ let modSummary = pm_mod_summary pm
103+ modSummary' <- initPlugins modSummary
98 (warnings, tcm) <- withWarnings "typecheck" $ \tweak ->
104 (warnings, tcm) <- withWarnings "typecheck" $ \tweak ->
99− GHC.typecheckModule $ demoteIfDefer pm{pm_mod_summary = tweak $ pm_mod_summary pm}
105+ GHC.typecheckModule $ demoteIfDefer pm{pm_mod_summary = tweak modSummary'}
100 tcm2 <- mkTcModuleResult tcm
106 tcm2 <- mkTcModuleResult tcm
101 return (map unDefer warnings, tcm2)
107 return (map unDefer warnings, tcm2)
102
108
109+initPlugins :: GhcMonad m => ModSummary -> m ModSummary
110+initPlugins modSummary = do
111+#if MIN_GHC_API_VERSION(8,6,0)
112+ session <- getSession
113+ dflags <- liftIO $ initializePlugins session (ms_hspp_opts modSummary)
114+ return modSummary{ms_hspp_opts = dflags}
115+#else
116+ return modSummary
117+#endif
118+
103-- | Compile a single type-checked module to a 'CoreModule' value, or
119-- | Compile a single type-checked module to a 'CoreModule' value, or
104-- provide errors.
120-- provide errors.
105compileModule
121compileModule
test/exe/Main.hs+23
@@ -40,6 +40,7 @@ main = defaultMain $ testGroup "HIE"
40 , diagnosticTests
40 , diagnosticTests
41 , codeActionTests
41 , codeActionTests
42 , findDefinitionAndHoverTests
42 , findDefinitionAndHoverTests
43+ , pluginTests
43 ]
44 ]
44
45
45initializeResponseTests :: TestTree
46initializeResponseTests :: TestTree
@@ -810,6 +811,28 @@ findDefinitionAndHoverTests = let
810 broken = Just . (`xfail` "known broken")
811 broken = Just . (`xfail` "known broken")
811 -- no = const Nothing -- don't run this test at all
812 -- no = const Nothing -- don't run this test at all
812
813
814+pluginTests :: TestTree
815+pluginTests = testSessionWait "plugins" $ do
816+ let content =
817+ T.unlines
818+ [ "{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-}"
819+ , "{-# LANGUAGE DataKinds, ScopedTypeVariables, TypeOperators #-}"
820+ , "module Testing where"
821+ , "import Data.Proxy"
822+ , "import GHC.TypeLits"
823+ -- This function fails without plugins being initialized.
824+ , "f :: forall n. KnownNat n => Proxy n -> Integer"
825+ , "f _ = natVal (Proxy :: Proxy n) + natVal (Proxy :: Proxy (n+2))"
826+ , "foo :: Int -> Int -> Int"
827+ , "foo a b = a + c"
828+ ]
829+ _ <- openDoc' "Testing.hs" "haskell" content
830+ expectDiagnostics
831+ [ ( "Testing.hs",
832+ [(DsError, (8, 14), "Variable not in scope: c")]
833+ )
834+ ]
835+
813xfail :: TestTree -> String -> TestTree
836xfail :: TestTree -> String -> TestTree
814xfail = flip expectFailBecause
837xfail = flip expectFailBecause
815
838