1
+ {-# LANGUAGE FlexibleContexts #-}
1
2
{-# LANGUAGE GADTs #-}
2
3
{-# LANGUAGE LambdaCase #-}
3
4
{-# LANGUAGE OverloadedStrings #-}
@@ -8,6 +9,8 @@ module Ide.Plugin.Tactic.LanguageServer where
8
9
import Control.Arrow
9
10
import Control.Monad
10
11
import Control.Monad.Trans.Maybe
12
+ import Data.Aeson (Value (Object ), fromJSON )
13
+ import Data.Aeson.Types (Result (Success , Error ))
11
14
import Data.Coerce
12
15
import Data.Functor ((<&>) )
13
16
import Data.Generics.Aliases (mkQ )
@@ -29,12 +32,17 @@ import Development.IDE.Spans.LocalBindings (Bindings, getDefiningBindi
29
32
import Development.Shake (RuleResult , Action )
30
33
import Development.Shake.Classes
31
34
import qualified FastString
35
+ import Ide.Plugin.Config (PluginConfig (plcConfig ))
36
+ import qualified Ide.Plugin.Config as Plugin
32
37
import Ide.Plugin.Tactic.Context
38
+ import Ide.Plugin.Tactic.FeatureSet
33
39
import Ide.Plugin.Tactic.GHC
34
40
import Ide.Plugin.Tactic.Judgements
35
41
import Ide.Plugin.Tactic.Range
36
- import Ide.Plugin.Tactic.TestTypes (TacticCommand )
42
+ import Ide.Plugin.Tactic.TestTypes (cfg_feature_set , TacticCommand )
37
43
import Ide.Plugin.Tactic.Types
44
+ import Ide.PluginUtils (getPluginConfig )
45
+ import Language.LSP.Server (MonadLsp )
38
46
import Language.LSP.Types
39
47
import OccName
40
48
import Prelude hiding (span )
@@ -69,6 +77,16 @@ runStaleIde
69
77
runStaleIde state nfp a = MaybeT $ runIde state $ useWithStale a nfp
70
78
71
79
80
+ ------------------------------------------------------------------------------
81
+ -- | Get the current feature set from the plugin config.
82
+ getFeatureSet :: MonadLsp Plugin. Config m => m FeatureSet
83
+ getFeatureSet = do
84
+ pcfg <- getPluginConfig " tactics"
85
+ pure $ case fromJSON $ Object $ plcConfig pcfg of
86
+ Success cfg -> cfg_feature_set cfg
87
+ Error _ -> defaultFeatures
88
+
89
+
72
90
getIdeDynflags
73
91
:: IdeState
74
92
-> NormalizedFilePath
@@ -87,8 +105,9 @@ judgementForHole
87
105
:: IdeState
88
106
-> NormalizedFilePath
89
107
-> Range
108
+ -> FeatureSet
90
109
-> MaybeT IO (Range , Judgement , Context , DynFlags )
91
- judgementForHole state nfp range = do
110
+ judgementForHole state nfp range features = do
92
111
(asts, amapping) <- runStaleIde state nfp GetHieAst
93
112
case asts of
94
113
HAR _ _ _ _ (HieFromDisk _) -> fail " Need a fresh hie file"
@@ -97,21 +116,22 @@ judgementForHole state nfp range = do
97
116
(tcmod, _) <- runStaleIde state nfp TypeCheck
98
117
(rss, g) <- liftMaybe $ getSpanAndTypeAtHole amapping range hf
99
118
resulting_range <- liftMaybe $ toCurrentRange amapping $ realSrcSpanToRange rss
100
- let (jdg, ctx) = mkJudgementAndContext g binds rss tcmod
119
+ let (jdg, ctx) = mkJudgementAndContext features g binds rss tcmod
101
120
dflags <- getIdeDynflags state nfp
102
121
pure (resulting_range, jdg, ctx, dflags)
103
122
104
123
105
124
mkJudgementAndContext
106
- :: Type
125
+ :: FeatureSet
126
+ -> Type
107
127
-> Bindings
108
128
-> RealSrcSpan
109
129
-> TcModuleResult
110
130
-> (Judgement , Context )
111
- mkJudgementAndContext g binds rss tcmod = do
131
+ mkJudgementAndContext features g binds rss tcmod = do
112
132
let tcg = tmrTypechecked tcmod
113
133
tcs = tcg_binds tcg
114
- ctx = mkContext
134
+ ctx = mkContext features
115
135
(mapMaybe (sequenceA . (occName *** coerce))
116
136
$ getDefiningBindings binds rss)
117
137
tcg
0 commit comments