-
-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,53 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Ide.Plugin.ExampleCabal where | ||
|
||
import Data.Aeson | ||
import qualified Data.HashMap.Strict as Map | ||
import qualified Data.Text as T | ||
import Development.IDE as D | ||
import qualified Development.IDE.Core.Shake as Shake | ||
import GHC.Generics | ||
import Ide.Types | ||
import Language.LSP.Server | ||
import Language.LSP.Types | ||
import Text.Regex.TDFA.Text () | ||
|
||
|
||
newtype Log = LogShake Shake.Log deriving Show | ||
|
||
instance Pretty Log where | ||
pretty = \case | ||
LogShake log -> pretty log | ||
|
||
descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState | ||
descriptor _recorder plId = (defaultCabalPluginDescriptor plId) | ||
{ pluginCommands = [PluginCommand "codelens.todo" "example adding" addTodoCmd] | ||
} | ||
|
||
-- --------------------------------------------------------------------- | ||
-- | Parameters for the addTodo PluginCommand. | ||
data AddTodoParams = AddTodoParams | ||
{ file :: Uri -- ^ Uri of the file to add the pragma to | ||
, todoText :: T.Text | ||
} | ||
deriving (Show, Eq, Generic, ToJSON, FromJSON) | ||
|
||
addTodoCmd :: CommandFunction IdeState AddTodoParams | ||
addTodoCmd _ide (AddTodoParams uri todoText) = do | ||
let | ||
pos = Position 3 0 | ||
textEdits = List | ||
[TextEdit (Range pos pos) | ||
("-- TODO:" <> todoText <> "\n") | ||
] | ||
res = WorkspaceEdit | ||
(Just $ Map.singleton uri textEdits) | ||
Nothing | ||
Nothing | ||
_ <- sendRequest SWorkspaceApplyEdit (ApplyWorkspaceEditParams Nothing res) (\_ -> pure ()) | ||
return $ Right Null | ||
|
||
-- --------------------------------------------------------------------- |