Skip to content

Commit 1b2dd28

Browse files
dylan-thinnesJaro Reinders
authored and
Jaro Reinders
committed
Fix plugins where necessary for new diagnostic structure
1 parent 869edd6 commit 1b2dd28

File tree

4 files changed

+36
-32
lines changed

4 files changed

+36
-32
lines changed

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Diagnostics.hs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ module Ide.Plugin.Cabal.Diagnostics
1111
)
1212
where
1313

14+
import Control.Lens ((.~), (&))
1415
import qualified Data.Text as T
1516
import Development.IDE (FileDiagnostic,
1617
ShowDiagnostic (ShowDiag))
18+
import Development.IDE.Types.Diagnostics (fdLspDiagnosticL, ideErrorWithSource)
1719
import Distribution.Fields (showPError, showPWarning)
1820
import qualified Distribution.Parsec as Syntax
1921
import Ide.PluginUtils (extendNextLine)
@@ -23,6 +25,7 @@ import Language.LSP.Protocol.Types (Diagnostic (..),
2325
Position (Position),
2426
Range (Range),
2527
fromNormalizedFilePath)
28+
import Language.LSP.Protocol.Lens (range)
2629

2730
-- | Produce a diagnostic for a fatal Cabal parser error.
2831
fatalParseErrorDiagnostic :: NormalizedFilePath -> T.Text -> FileDiagnostic
@@ -80,15 +83,11 @@ mkDiag
8083
-> T.Text
8184
-- ^ The message displayed by the editor
8285
-> FileDiagnostic
83-
mkDiag file diagSource sev loc msg = (file, ShowDiag,)
84-
Diagnostic
85-
{ _range = loc
86-
, _severity = Just sev
87-
, _source = Just diagSource
88-
, _message = msg
89-
, _code = Nothing
90-
, _tags = Nothing
91-
, _relatedInformation = Nothing
92-
, _codeDescription = Nothing
93-
, _data_ = Nothing
94-
}
86+
mkDiag file diagSource sev loc msg =
87+
ideErrorWithSource
88+
(Just diagSource)
89+
(Just sev)
90+
file
91+
msg
92+
Nothing
93+
& fdLspDiagnosticL . range .~ loc

plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ rules recorder plugin = do
211211

212212
diagnostics :: NormalizedFilePath -> Either ParseError [Idea] -> [FileDiagnostic]
213213
diagnostics file (Right ideas) =
214-
(file, ShowDiag,) <$> catMaybes [ideaToDiagnostic i | i <- ideas]
214+
[ideErrorFromLspDiag diag file Nothing | i <- ideas, Just diag <- [ideaToDiagnostic i]]
215215
diagnostics file (Left parseErr) =
216-
[(file, ShowDiag, parseErrorToDiagnostic parseErr)]
216+
[ideErrorFromLspDiag (parseErrorToDiagnostic parseErr) file Nothing]
217217

218218

219219
ideaToDiagnostic :: Idea -> Maybe Diagnostic
@@ -371,9 +371,11 @@ codeActionProvider ideState _pluginId (CodeActionParams _ _ documentId _ context
371371
allDiagnostics <- atomically $ getDiagnostics ideState
372372

373373
let numHintsInDoc = length
374-
[diagnostic | (diagnosticNormalizedFilePath, _, diagnostic) <- allDiagnostics
375-
, validCommand diagnostic
376-
, diagnosticNormalizedFilePath == docNormalizedFilePath
374+
[lspDiagnostic
375+
| diag <- allDiagnostics
376+
, let lspDiagnostic = fdLspDiagnostic diag
377+
, validCommand lspDiagnostic
378+
, fdFilePath diag == docNormalizedFilePath
377379
]
378380
let numHintsInContext = length
379381
[diagnostic | diagnostic <- diags

plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import Development.IDE.Plugin.TypeLenses (suggestSigna
6868
import Development.IDE.Types.Exports
6969
import Development.IDE.Types.Location
7070
import Development.IDE.Types.Options
71+
import Development.IDE.Types.Diagnostics
7172
import GHC (AddEpAnn (AddEpAnn),
7273
AnnsModule (am_main),
7374
DeltaPos (..),
@@ -125,7 +126,7 @@ codeAction state _ (CodeActionParams _ _ (TextDocumentIdentifier uri) range _) =
125126
contents <- liftIO $ runAction "hls-refactor-plugin.codeAction.getUriContents" state $ getUriContents $ toNormalizedUri uri
126127
liftIO $ do
127128
let mbFile = toNormalizedFilePath' <$> uriToFilePath uri
128-
allDiags <- atomically $ fmap (\(_, _, d) -> d) . filter (\(p, _, _) -> mbFile == Just p) <$> getDiagnostics state
129+
allDiags <- atomically $ fmap fdLspDiagnostic . filter (\d -> mbFile == Just (fdFilePath d)) <$> getDiagnostics state
129130
(join -> parsedModule) <- runAction "GhcideCodeActions.getParsedModule" state $ getParsedModule `traverse` mbFile
130131
let
131132
textContents = fmap Rope.toText contents

plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import qualified Data.HashMap.Strict as HM
1212
import Data.Maybe (mapMaybe)
1313
import qualified Data.Text as T
1414
import Development.IDE
15+
import Development.IDE.Types.Diagnostics
1516
import Development.IDE.Core.Rules (getHieFile)
1617
import qualified Development.IDE.Core.Shake as Shake
1718
import GHC.Generics (Generic)
@@ -187,17 +188,18 @@ rules recorder plId = do
187188
"Possible solutions:"
188189
]
189190
++ map (" - " <>) (inspectionSolution inspection)
190-
return ( file,
191-
ShowDiag,
192-
LSP.Diagnostic
193-
{ _range = realSrcSpanToRange observationSrcSpan,
194-
_severity = Just LSP.DiagnosticSeverity_Hint,
195-
_code = Just (LSP.InR $ unId (inspectionId inspection)),
196-
_source = Just "stan",
197-
_message = message,
198-
_relatedInformation = Nothing,
199-
_tags = Nothing,
200-
_codeDescription = Nothing,
201-
_data_ = Nothing
202-
}
203-
)
191+
return $
192+
ideErrorFromLspDiag
193+
LSP.Diagnostic
194+
{ _range = realSrcSpanToRange observationSrcSpan,
195+
_severity = Just LSP.DiagnosticSeverity_Hint,
196+
_code = Just (LSP.InR $ unId (inspectionId inspection)),
197+
_source = Just "stan",
198+
_message = message,
199+
_relatedInformation = Nothing,
200+
_tags = Nothing,
201+
_codeDescription = Nothing,
202+
_data_ = Nothing
203+
}
204+
file
205+
Nothing

0 commit comments

Comments
 (0)