Skip to content

Commit 48a228f

Browse files
committed
WIP, prior to rebase for experimental
1 parent d7e8c87 commit 48a228f

File tree

9 files changed

+36
-65
lines changed

9 files changed

+36
-65
lines changed

ghcide

haskell-language-server.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ source-repository head
2727

2828
library
2929
exposed-modules:
30-
Ide.Compat
3130
Ide.Cradle
3231
Ide.Logger
3332
Ide.Plugin

src/Ide/Compat.hs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/Ide/Plugin.hs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import Development.IDE.Types.Diagnostics as D
3535
import Development.IDE.Types.Logger
3636
import Development.Shake hiding ( Diagnostic, command )
3737
import GHC.Generics
38-
import Ide.Compat
3938
import Ide.Plugin.Config
4039
import Ide.Plugin.Formatter
4140
import Ide.Types
@@ -115,7 +114,7 @@ makeCodeAction :: [(PluginId, CodeActionProvider)]
115114
makeCodeAction cas lf ideState (CodeActionParams docId range context _) = do
116115
let caps = LSP.clientCapabilities lf
117116
unL (List ls) = ls
118-
r <- mapM (\(pid,provider) -> provider ideState pid docId range context) cas
117+
r <- mapM (\(pid,provider) -> provider lf ideState pid docId range context) cas
119118
let actions = filter wasRequested . concat $ map unL $ rights r
120119
res <- send caps actions
121120
return $ Right res
@@ -171,11 +170,11 @@ makeCodeLens :: [(PluginId, CodeLensProvider)]
171170
-> IdeState
172171
-> CodeLensParams
173172
-> IO (Either ResponseError (List CodeLens))
174-
makeCodeLens cas _lf ideState params = do
173+
makeCodeLens cas lf ideState params = do
175174
logInfo (ideLogger ideState) "Plugin.makeCodeLens (ideLogger)" -- AZ
176175
let
177176
makeLens (pid, provider) = do
178-
r <- provider ideState pid params
177+
r <- provider lf ideState pid params
179178
return (pid, r)
180179
breakdown :: [(PluginId, Either ResponseError a)] -> ([(PluginId, ResponseError)], [(PluginId, a)])
181180
breakdown ls = (concatMap doOneLeft ls, concatMap doOneRight ls)
@@ -362,9 +361,6 @@ mkLspCmdId :: T.Text -> PluginId -> CommandId -> T.Text
362361
mkLspCmdId pid (PluginId plid) (CommandId cid)
363362
= pid <> ":" <> plid <> ":" <> cid
364363

365-
getPid :: IO T.Text
366-
getPid = T.pack . show <$> getProcessID
367-
368364
allLspCmdIds :: T.Text -> [(PluginId, [PluginCommand])] -> [T.Text]
369365
allLspCmdIds pid commands = concat $ map go commands
370366
where

src/Ide/Plugin/Example.hs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,8 @@ mkDiag file diagSource sev loc msg = (file, D.ShowDiag,)
107107
-- ---------------------------------------------------------------------
108108

109109
-- | Generate code actions.
110-
codeAction
111-
:: IdeState
112-
-> PluginId
113-
-> TextDocumentIdentifier
114-
-> Range
115-
-> CodeActionContext
116-
-> IO (Either ResponseError (List CAResult))
117-
codeAction _state _pid (TextDocumentIdentifier uri) _range CodeActionContext{_diagnostics=List _xs} = do
110+
codeAction :: CodeActionProvider
111+
codeAction _lf _state _pid (TextDocumentIdentifier uri) _range CodeActionContext{_diagnostics=List _xs} = do
118112
let
119113
title = "Add TODO Item 1"
120114
tedit = [TextEdit (Range (Position 2 0) (Position 2 0))
@@ -125,12 +119,8 @@ codeAction _state _pid (TextDocumentIdentifier uri) _range CodeActionContext{_di
125119

126120
-- ---------------------------------------------------------------------
127121

128-
codeLens
129-
:: IdeState
130-
-> PluginId
131-
-> CodeLensParams
132-
-> IO (Either ResponseError (List CodeLens))
133-
codeLens ideState plId CodeLensParams{_textDocument=TextDocumentIdentifier uri} = do
122+
codeLens :: CodeLensProvider
123+
codeLens _lf ideState plId CodeLensParams{_textDocument=TextDocumentIdentifier uri} = do
134124
logInfo (ideLogger ideState) "Example.codeLens entered (ideLogger)" -- AZ
135125
case uriToFilePath' uri of
136126
Just (toNormalizedFilePath -> filePath) -> do

src/Ide/Plugin/Example2.hs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,8 @@ mkDiag file diagSource sev loc msg = (file, D.ShowDiag,)
107107
-- ---------------------------------------------------------------------
108108

109109
-- | Generate code actions.
110-
codeAction
111-
:: IdeState
112-
-> PluginId
113-
-> TextDocumentIdentifier
114-
-> Range
115-
-> CodeActionContext
116-
-> IO (Either ResponseError (List CAResult))
117-
codeAction _state _pid (TextDocumentIdentifier uri) _range CodeActionContext{_diagnostics=List _xs} = do
110+
codeAction :: CodeActionProvider
111+
codeAction _lf _state _pid (TextDocumentIdentifier uri) _range CodeActionContext{_diagnostics=List _xs} = do
118112
let
119113
title = "Add TODO2 Item"
120114
tedit = [TextEdit (Range (Position 3 0) (Position 3 0))
@@ -125,12 +119,8 @@ codeAction _state _pid (TextDocumentIdentifier uri) _range CodeActionContext{_di
125119

126120
-- ---------------------------------------------------------------------
127121

128-
codeLens
129-
:: IdeState
130-
-> PluginId
131-
-> CodeLensParams
132-
-> IO (Either ResponseError (List CodeLens))
133-
codeLens ideState plId CodeLensParams{_textDocument=TextDocumentIdentifier uri} = do
122+
codeLens :: CodeLensProvider
123+
codeLens _lf ideState plId CodeLensParams{_textDocument=TextDocumentIdentifier uri} = do
134124
logInfo (ideLogger ideState) "Example2.codeLens entered (ideLogger)" -- AZ
135125
case uriToFilePath' uri of
136126
Just (toNormalizedFilePath -> filePath) -> do

src/Ide/Plugin/GhcIde.hs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
{-# LANGUAGE DuplicateRecordFields #-}
12
{-# LANGUAGE OverloadedStrings #-}
23
module Ide.Plugin.GhcIde
34
(
45
descriptor
56
) where
67

8+
import Development.IDE.Core.Service
9+
import Development.IDE.LSP.HoverDefinition
710
import Development.IDE.Types.Logger
811
import Ide.Types
9-
import Development.IDE.LSP.HoverDefinition
10-
import Development.IDE.Core.Shake
12+
import Text.Regex.TDFA.Text()
13+
import Development.IDE.Plugin.CodeAction
1114

1215
-- ---------------------------------------------------------------------
1316

@@ -16,8 +19,8 @@ descriptor plId = PluginDescriptor
1619
{ pluginId = plId
1720
, pluginRules = mempty
1821
, pluginCommands = []
19-
, pluginCodeActionProvider = Nothing
20-
, pluginCodeLensProvider = Nothing
22+
, pluginCodeActionProvider = Just codeAction'
23+
, pluginCodeLensProvider = Just codeLens'
2124
, pluginDiagnosticProvider = Nothing
2225
, pluginHoverProvider = Just hover'
2326
, pluginSymbolsProvider = Nothing
@@ -33,3 +36,13 @@ hover' ideState params = do
3336
hover ideState params
3437

3538
-- ---------------------------------------------------------------------
39+
40+
codeAction' :: CodeActionProvider
41+
codeAction' lf ide _ doc range context = codeAction lf ide doc range context
42+
43+
-- ---------------------------------------------------------------------
44+
45+
codeLens' :: CodeLensProvider
46+
codeLens' lf ide _ params = codeLens lf ide params
47+
48+
-- ---------------------------------------------------------------------

src/Ide/Plugin/Pragmas.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ addPragmaCmd (AddPragmaParams uri pragmaName) = do
7676
-- | Offer to add a missing Language Pragma to the top of a file.
7777
-- Pragmas are defined by a curated list of known pragmas, see 'possiblePragmas'.
7878
codeActionProvider :: CodeActionProvider
79-
codeActionProvider _ plId docId _ (J.CodeActionContext (J.List diags) _monly) = do
79+
codeActionProvider _ _ plId docId _ (J.CodeActionContext (J.List diags) _monly) = do
8080
cmds <- mapM mkCommand pragmas
8181
-- cmds <- mapM mkCommand ("FooPragma":pragmas)
8282
return $ Right $ List cmds

src/Ide/Types.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ import qualified Data.Set as S
2727
import Data.String
2828
import qualified Data.Text as T
2929
import Development.IDE.Core.Rules
30-
-- import Development.IDE.Plugin
3130
import Development.IDE.Types.Diagnostics as D
3231
import Development.IDE.Types.Location
3332
import Development.Shake
34-
-- import Development.Shake.Classes
33+
import Ide.Plugin.Config
34+
import qualified Language.Haskell.LSP.Core as LSP
3535
import Language.Haskell.LSP.Types
3636
import Text.Regex.TDFA.Text()
3737

@@ -84,15 +84,17 @@ data PluginCommand = forall a. (FromJSON a) =>
8484
}
8585
-- ---------------------------------------------------------------------
8686

87-
type CodeActionProvider = IdeState
87+
type CodeActionProvider = LSP.LspFuncs Config
88+
-> IdeState
8889
-> PluginId
8990
-> TextDocumentIdentifier
9091
-> Range
9192
-> CodeActionContext
9293
-> IO (Either ResponseError (List CAResult))
9394

9495

95-
type CodeLensProvider = IdeState
96+
type CodeLensProvider = LSP.LspFuncs Config
97+
-> IdeState
9698
-> PluginId
9799
-> CodeLensParams
98100
-> IO (Either ResponseError (List CodeLens))

0 commit comments

Comments
 (0)