From 656daff2b22ca2d230ef7f4de1f9e770b90146f4 Mon Sep 17 00:00:00 2001 From: fendor Date: Tue, 30 Apr 2019 16:02:57 +0200 Subject: [PATCH 1/2] Add Documentation for Pragmas Plugin --- src/Haskell/Ide/Engine/Plugin/Pragmas.hs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Haskell/Ide/Engine/Plugin/Pragmas.hs b/src/Haskell/Ide/Engine/Plugin/Pragmas.hs index 408090b4b..53fcb0313 100644 --- a/src/Haskell/Ide/Engine/Plugin/Pragmas.hs +++ b/src/Haskell/Ide/Engine/Plugin/Pragmas.hs @@ -32,12 +32,17 @@ pragmasDescriptor plId = PluginDescriptor -- --------------------------------------------------------------------- +-- | Parameters for the addPragma PluginCommand. data AddPragmaParams = AddPragmaParams - { file :: Uri - , pragma :: T.Text + { file :: Uri -- ^ Uri of the file to add the pragma to + , pragma :: T.Text -- ^ Name of the Pragma to add } deriving (Show, Eq, Generics.Generic, ToJSON, FromJSON) +-- | Add a Pragma to the given URI at the top of the file. +-- Pragma is added to the first line of the Uri. +-- It is assumed that the pragma name is a valid pragma, +-- thus, not validated. addPragmaCmd :: CommandFunc AddPragmaParams J.WorkspaceEdit addPragmaCmd = CmdSync $ \(AddPragmaParams uri pragmaName) -> do let @@ -53,15 +58,22 @@ addPragmaCmd = CmdSync $ \(AddPragmaParams uri pragmaName) -> do -- --------------------------------------------------------------------- +-- | Offer to add a missing Language Pragma to the top of a file. +-- Pragmas are defined by a curated list of known pragmas, see 'possiblePragmas'. +-- May also offer to add unknown pragmas, if the pragma is a subexpression of +-- an existing plugin. codeActionProvider :: CodeActionProvider codeActionProvider plId docId _ (J.CodeActionContext (J.List diags) _monly) = do cmds <- mapM mkCommand pragmas return $ IdeResultOk cmds where + -- Filter diagnostics that are from ghcmod ghcDiags = filter (\d -> d ^. J.source == Just "ghcmod") diags + -- Get all potential Pragmas for all diagnostics. pragmas = concatMap (\d -> findPragma (d ^. J.message)) ghcDiags mkCommand pragmaName = do let + -- | Code Action for the given command. codeAction :: J.Command -> J.CodeAction codeAction cmd = J.CodeAction title (Just J.CodeActionQuickFix) (Just (J.List [])) Nothing (Just cmd) title = "Add \"" <> pragmaName <> "\"" @@ -71,6 +83,7 @@ codeActionProvider plId docId _ (J.CodeActionContext (J.List diags) _monly) = do -- --------------------------------------------------------------------- +-- | Find all Pragmas that have the search term as infix. findPragma :: T.Text -> [T.Text] findPragma str = concatMap check possiblePragmas where @@ -78,6 +91,8 @@ findPragma str = concatMap check possiblePragmas -- --------------------------------------------------------------------- +-- | Possible Pragama names. +-- Is non-exhaustive, and may be extended. possiblePragmas :: [T.Text] possiblePragmas = [ From a451a5cfa9a43e73ae68c638b1a8dffbf485710c Mon Sep 17 00:00:00 2001 From: fendor Date: Tue, 30 Apr 2019 20:21:23 +0200 Subject: [PATCH 2/2] Improve documentation --- src/Haskell/Ide/Engine/Plugin/Pragmas.hs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Haskell/Ide/Engine/Plugin/Pragmas.hs b/src/Haskell/Ide/Engine/Plugin/Pragmas.hs index 53fcb0313..f075f7139 100644 --- a/src/Haskell/Ide/Engine/Plugin/Pragmas.hs +++ b/src/Haskell/Ide/Engine/Plugin/Pragmas.hs @@ -60,8 +60,6 @@ addPragmaCmd = CmdSync $ \(AddPragmaParams uri pragmaName) -> do -- | Offer to add a missing Language Pragma to the top of a file. -- Pragmas are defined by a curated list of known pragmas, see 'possiblePragmas'. --- May also offer to add unknown pragmas, if the pragma is a subexpression of --- an existing plugin. codeActionProvider :: CodeActionProvider codeActionProvider plId docId _ (J.CodeActionContext (J.List diags) _monly) = do cmds <- mapM mkCommand pragmas @@ -83,7 +81,7 @@ codeActionProvider plId docId _ (J.CodeActionContext (J.List diags) _monly) = do -- --------------------------------------------------------------------- --- | Find all Pragmas that have the search term as infix. +-- | Find all Pragmas are an infix of the search term. findPragma :: T.Text -> [T.Text] findPragma str = concatMap check possiblePragmas where @@ -91,7 +89,7 @@ findPragma str = concatMap check possiblePragmas -- --------------------------------------------------------------------- --- | Possible Pragama names. +-- | Possible Pragma names. -- Is non-exhaustive, and may be extended. possiblePragmas :: [T.Text] possiblePragmas =