Skip to content

Commit 386bf8a

Browse files
committed
Add example plugin
1 parent 9c494ca commit 386bf8a

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

exe/Plugins.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Development.IDE (IdeState)
1313
import qualified Development.IDE.Plugin.HLS.GhcIde as GhcIde
1414
import qualified Ide.Plugin.Example as Example
1515
import qualified Ide.Plugin.Example2 as Example2
16+
import qualified Ide.Plugin.ExampleCabal as ExampleCabal
1617

1718
-- haskell-language-server optional plugins
1819
#if qualifyImportedNames
@@ -204,4 +205,5 @@ idePlugins recorder includeExamples = pluginDescToIdePlugins allPlugins
204205
examplePlugins =
205206
[Example.descriptor pluginRecorder "eg"
206207
,Example2.descriptor pluginRecorder "eg2"
208+
,ExampleCabal.descriptor pluginRecorder "ec"
207209
]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,53 @@
1+
{-# LANGUAGE LambdaCase #-}
2+
{-# LANGUAGE DeriveGeneric #-}
3+
{-# LANGUAGE DeriveAnyClass #-}
4+
{-# LANGUAGE OverloadedStrings #-}
15
module Ide.Plugin.ExampleCabal where
26

7+
import Data.Aeson
8+
import qualified Data.HashMap.Strict as Map
9+
import qualified Data.Text as T
10+
import Development.IDE as D
11+
import qualified Development.IDE.Core.Shake as Shake
12+
import GHC.Generics
13+
import Ide.Types
14+
import Language.LSP.Server
15+
import Language.LSP.Types
16+
import Text.Regex.TDFA.Text ()
17+
18+
19+
newtype Log = LogShake Shake.Log deriving Show
20+
21+
instance Pretty Log where
22+
pretty = \case
23+
LogShake log -> pretty log
24+
25+
descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState
26+
descriptor _recorder plId = (defaultCabalPluginDescriptor plId)
27+
{ pluginCommands = [PluginCommand "codelens.todo" "example adding" addTodoCmd]
28+
}
29+
30+
-- ---------------------------------------------------------------------
31+
-- | Parameters for the addTodo PluginCommand.
32+
data AddTodoParams = AddTodoParams
33+
{ file :: Uri -- ^ Uri of the file to add the pragma to
34+
, todoText :: T.Text
35+
}
36+
deriving (Show, Eq, Generic, ToJSON, FromJSON)
37+
38+
addTodoCmd :: CommandFunction IdeState AddTodoParams
39+
addTodoCmd _ide (AddTodoParams uri todoText) = do
40+
let
41+
pos = Position 3 0
42+
textEdits = List
43+
[TextEdit (Range pos pos)
44+
("-- TODO:" <> todoText <> "\n")
45+
]
46+
res = WorkspaceEdit
47+
(Just $ Map.singleton uri textEdits)
48+
Nothing
49+
Nothing
50+
_ <- sendRequest SWorkspaceApplyEdit (ApplyWorkspaceEditParams Nothing res) (\_ -> pure ())
51+
return $ Right Null
52+
53+
-- ---------------------------------------------------------------------

0 commit comments

Comments
 (0)