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

Commit eb8110a

Browse files
authored
Merge pull request #1222 from fendor/document-pragmas
Add Documentation for Pragmas Plugin
2 parents ac38be3 + a451a5c commit eb8110a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

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

+15-2
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,20 @@ 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'.
5663
codeActionProvider :: CodeActionProvider
5764
codeActionProvider plId docId _ (J.CodeActionContext (J.List diags) _monly) = do
5865
cmds <- mapM mkCommand pragmas
5966
return $ IdeResultOk cmds
6067
where
68+
-- Filter diagnostics that are from ghcmod
6169
ghcDiags = filter (\d -> d ^. J.source == Just "ghcmod") diags
70+
-- Get all potential Pragmas for all diagnostics.
6271
pragmas = concatMap (\d -> findPragma (d ^. J.message)) ghcDiags
6372
mkCommand pragmaName = do
6473
let
74+
-- | Code Action for the given command.
6575
codeAction :: J.Command -> J.CodeAction
6676
codeAction cmd = J.CodeAction title (Just J.CodeActionQuickFix) (Just (J.List [])) Nothing (Just cmd)
6777
title = "Add \"" <> pragmaName <> "\""
@@ -71,13 +81,16 @@ codeActionProvider plId docId _ (J.CodeActionContext (J.List diags) _monly) = do
7181

7282
-- ---------------------------------------------------------------------
7383

84+
-- | Find all Pragmas are an infix of the search term.
7485
findPragma :: T.Text -> [T.Text]
7586
findPragma str = concatMap check possiblePragmas
7687
where
7788
check p = [p | T.isInfixOf p str]
7889

7990
-- ---------------------------------------------------------------------
8091

92+
-- | Possible Pragma names.
93+
-- Is non-exhaustive, and may be extended.
8194
possiblePragmas :: [T.Text]
8295
possiblePragmas =
8396
[

0 commit comments

Comments
 (0)