Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 656daff

Browse files
committed
Add Documentation for Pragmas Plugin
1 parent faee856 commit 656daff

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/Haskell/Ide/Engine/Plugin/Pragmas.hs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@ pragmasDescriptor plId = PluginDescriptor
3232

3333
-- ---------------------------------------------------------------------
3434

35+
-- | Parameters for the addPragma PluginCommand.
3536
data AddPragmaParams = AddPragmaParams
36-
{ file :: Uri
37-
, pragma :: T.Text
37+
{ file :: Uri -- ^ Uri of the file to add the pragma to
38+
, pragma :: T.Text -- ^ Name of the Pragma to add
3839
}
3940
deriving (Show, Eq, Generics.Generic, ToJSON, FromJSON)
4041

42+
-- | Add a Pragma to the given URI at the top of the file.
43+
-- Pragma is added to the first line of the Uri.
44+
-- It is assumed that the pragma name is a valid pragma,
45+
-- thus, not validated.
4146
addPragmaCmd :: CommandFunc AddPragmaParams J.WorkspaceEdit
4247
addPragmaCmd = CmdSync $ \(AddPragmaParams uri pragmaName) -> do
4348
let
@@ -53,15 +58,22 @@ addPragmaCmd = CmdSync $ \(AddPragmaParams uri pragmaName) -> do
5358

5459
-- ---------------------------------------------------------------------
5560

61+
-- | Offer to add a missing Language Pragma to the top of a file.
62+
-- Pragmas are defined by a curated list of known pragmas, see 'possiblePragmas'.
63+
-- May also offer to add unknown pragmas, if the pragma is a subexpression of
64+
-- an existing plugin.
5665
codeActionProvider :: CodeActionProvider
5766
codeActionProvider plId docId _ (J.CodeActionContext (J.List diags) _monly) = do
5867
cmds <- mapM mkCommand pragmas
5968
return $ IdeResultOk cmds
6069
where
70+
-- Filter diagnostics that are from ghcmod
6171
ghcDiags = filter (\d -> d ^. J.source == Just "ghcmod") diags
72+
-- Get all potential Pragmas for all diagnostics.
6273
pragmas = concatMap (\d -> findPragma (d ^. J.message)) ghcDiags
6374
mkCommand pragmaName = do
6475
let
76+
-- | Code Action for the given command.
6577
codeAction :: J.Command -> J.CodeAction
6678
codeAction cmd = J.CodeAction title (Just J.CodeActionQuickFix) (Just (J.List [])) Nothing (Just cmd)
6779
title = "Add \"" <> pragmaName <> "\""
@@ -71,13 +83,16 @@ codeActionProvider plId docId _ (J.CodeActionContext (J.List diags) _monly) = do
7183

7284
-- ---------------------------------------------------------------------
7385

86+
-- | Find all Pragmas that have the search term as infix.
7487
findPragma :: T.Text -> [T.Text]
7588
findPragma str = concatMap check possiblePragmas
7689
where
7790
check p = [p | T.isInfixOf p str]
7891

7992
-- ---------------------------------------------------------------------
8093

94+
-- | Possible Pragama names.
95+
-- Is non-exhaustive, and may be extended.
8196
possiblePragmas :: [T.Text]
8297
possiblePragmas =
8398
[

0 commit comments

Comments
 (0)