Skip to content

Commit ae0830d

Browse files
committed
Move a few more things into the LanguageServer
1 parent 67badc8 commit ae0830d

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic.hs

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,11 @@ descriptor plId = (defaultPluginDescriptor plId)
5858
(tacticDesc $ tcCommandName tc)
5959
(tacticCmd $ commandTactic tc))
6060
[minBound .. maxBound]
61-
, pluginHandlers = mkPluginHandler STextDocumentCodeAction codeActionProvider
61+
, pluginHandlers =
62+
mkPluginHandler STextDocumentCodeAction codeActionProvider
6263
}
6364

6465

65-
tacticDesc :: T.Text -> T.Text
66-
tacticDesc name = "fill the hole using the " <> name <> " tactic"
67-
68-
69-
------------------------------------------------------------------------------
70-
-- | The name of the command for the LS.
71-
tcCommandName :: TacticCommand -> T.Text
72-
tcCommandName = T.pack . show
73-
74-
7566

7667
codeActionProvider :: PluginMethodHandler IdeState TextDocumentCodeAction
7768
codeActionProvider state plId (CodeActionParams _ _ (TextDocumentIdentifier uri) range _ctx)
@@ -188,22 +179,23 @@ mergeFunBindMatches
188179
-> SrcSpan
189180
-> HsBind GhcPs
190181
-> Either String (HsBind GhcPs)
191-
mergeFunBindMatches make_decl span (fb@FunBind {fun_matches = mg@MG {mg_alts = L alts_src alts}}) =
192-
pure $
193-
fb
194-
{ fun_matches = mg
195-
{ mg_alts = L alts_src $ do
196-
alt@(L alt_src match) <- alts
197-
case span `isSubspanOf` alt_src of
198-
True -> do
199-
let pats = fmap fromPatCompatPs $ m_pats match
200-
(L _ (ValD _ (FunBind {fun_matches = MG {mg_alts = L _ to_add}}))) =
201-
make_decl pats
202-
to_add
203-
False -> pure alt
204-
}
182+
mergeFunBindMatches make_decl span
183+
(fb@FunBind {fun_matches = mg@MG {mg_alts = L alts_src alts}}) =
184+
pure $ fb
185+
{ fun_matches = mg
186+
{ mg_alts = L alts_src $ do
187+
alt@(L alt_src match) <- alts
188+
case span `isSubspanOf` alt_src of
189+
True -> do
190+
let pats = fmap fromPatCompatPs $ m_pats match
191+
L _ (ValD _ (FunBind {fun_matches = MG
192+
{mg_alts = L _ to_add}})) = make_decl pats
193+
to_add
194+
False -> pure alt
205195
}
206-
mergeFunBindMatches _ _ _ = Left "mergeFunBindMatches: called on something that isnt a funbind"
196+
}
197+
mergeFunBindMatches _ _ _ =
198+
Left "mergeFunBindMatches: called on something that isnt a funbind"
207199

208200

209201
throwError :: String -> TransformT (Either String) a
@@ -226,13 +218,16 @@ graftDecl span
226218
-- TODO(sandy): add another case for default methods in class definitions
227219
graftDecl span
228220
make_decl
229-
(L src (InstD ext cid@ClsInstD{cid_inst = cidi@ClsInstDecl{cid_sigs = _sigs, cid_binds = binds}}))
221+
(L src (InstD ext
222+
cid@ClsInstD{cid_inst =
223+
cidi@ClsInstDecl{cid_sigs = _sigs, cid_binds = binds}}))
230224
= do
231225
binds' <-
232226
for (bagToList binds) $ \b@(L bsrc bind) -> do
233227
case bind of
234-
fb@FunBind{}
235-
| span `isSubspanOf` bsrc -> either throwError (pure . L bsrc) $ mergeFunBindMatches make_decl span fb
228+
fb@FunBind{} | span `isSubspanOf` bsrc ->
229+
either throwError (pure . L bsrc) $
230+
mergeFunBindMatches make_decl span fb
236231
_ -> pure b
237232

238233
pure $ Just $ pure $ L src $ InstD ext $ cid
@@ -241,8 +236,12 @@ graftDecl span
241236
}
242237
}
243238
graftDecl span _ x = do
244-
traceMX "biggest" $ unsafeRender $ locateBiggest @(Match GhcPs (LHsExpr GhcPs)) span x
245-
traceMX "first" $ unsafeRender $ locateFirst @(Match GhcPs (LHsExpr GhcPs)) x
239+
traceMX "biggest" $
240+
unsafeRender $
241+
locateBiggest @(Match GhcPs (LHsExpr GhcPs)) span x
242+
traceMX "first" $
243+
unsafeRender $
244+
locateFirst @(Match GhcPs (LHsExpr GhcPs)) x
246245
throwError "graftDecl: don't know about this AST form"
247246

248247

plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/LanguageServer.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import qualified Data.Map as M
1717
import Data.Maybe
1818
import Data.Monoid
1919
import qualified Data.Set as S
20+
import qualified Data.Text as T
2021
import Data.Traversable
2122
import Development.IDE.Core.PositionMapping
2223
import Development.IDE.Core.RuleTypes
@@ -32,6 +33,7 @@ import Ide.Plugin.Tactic.Context
3233
import Ide.Plugin.Tactic.GHC
3334
import Ide.Plugin.Tactic.Judgements
3435
import Ide.Plugin.Tactic.Range
36+
import Ide.Plugin.Tactic.TestTypes (TacticCommand)
3537
import Ide.Plugin.Tactic.Types
3638
import Language.LSP.Types
3739
import OccName
@@ -40,6 +42,16 @@ import SrcLoc (containsSpan)
4042
import TcRnTypes (tcg_binds)
4143

4244

45+
tacticDesc :: T.Text -> T.Text
46+
tacticDesc name = "fill the hole using the " <> name <> " tactic"
47+
48+
49+
------------------------------------------------------------------------------
50+
-- | The name of the command for the LS.
51+
tcCommandName :: TacticCommand -> T.Text
52+
tcCommandName = T.pack . show
53+
54+
4355
runIde :: IdeState -> Action a -> IO a
4456
runIde state = runAction "tactic" state
4557

0 commit comments

Comments
 (0)