Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions ghcide/src/Development/IDE/Core/PluginUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,13 @@ activeDiagnosticsInRangeMT ide nfp range = do
case mDiags of
Nothing -> pure Nothing
Just fileDiags -> do
pure $ Just $ filter diagRangeOverlaps fileDiags
pure $ Just $ filter (diagRangeOverlaps range) fileDiags
where
diagRangeOverlaps = \fileDiag ->
rangesOverlap range (fileDiag ^. fdLspDiagnosticL . LSP.range)
-- TODO: document this
diagRangeOverlaps range@(LSP.Range b e) fileDiag
| b /= e = rangesOverlap range diagRange
| otherwise = LSP.positionInRange b diagRange || b == diagEnd
where diagRange@(LSP.Range _ diagEnd) = fileDiag ^. fdLspDiagnosticL . LSP.range

-- | Just like 'activeDiagnosticsInRangeMT'. See the docs of 'activeDiagnosticsInRangeMT' for details.
activeDiagnosticsInRange :: MonadIO m => Shake.ShakeExtras -> NormalizedFilePath -> LSP.Range -> m [FileDiagnostic]
Expand Down
9 changes: 7 additions & 2 deletions hls-plugin-api/src/Ide/PluginUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,11 @@ subRange :: Range -> Range -> Bool
subRange = isSubrangeOf


-- | Check whether the two 'Range's overlap in any way.
-- | Check whether the two 'Range's overlap in any way, taking into account
-- that, as per the LSP spec, 'Range's are right-open half-open intervals.
--
-- >>> rangesOverlap (mkRange 1 0 1 2) (mkRange 1 4 1 6)
-- False
-- >>> rangesOverlap (mkRange 1 0 1 4) (mkRange 1 2 1 5)
-- True
-- >>> rangesOverlap (mkRange 1 2 1 5) (mkRange 1 0 1 4)
Expand All @@ -289,9 +292,11 @@ subRange = isSubrangeOf
-- True
-- >>> rangesOverlap (mkRange 1 2 1 4) (mkRange 1 0 1 6)
-- True
-- >>> rangesOverlap (mkRange 1 2 1 4) (mkRange 1 4 1 6)
-- False
rangesOverlap :: Range -> Range -> Bool
rangesOverlap r1 r2 =
r1 ^. L.start <= r2 ^. L.end && r2 ^. L.start <= r1 ^. L.end
r1 ^. L.start < r2 ^. L.end && r2 ^. L.start < r1 ^. L.end

-- ---------------------------------------------------------------------

Expand Down
6 changes: 3 additions & 3 deletions plugins/hls-refactor-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ extendImportTests = testGroup "extend import actions"
, "b :: A"
, "b = 0"
])
(Range (Position 2 5) (Position 2 5))
(Range (Position 2 5) (Position 2 6))
["Add A to the import list of ModuleA"]
(T.unlines
[ "module ModuleB where"
Expand Down Expand Up @@ -2958,7 +2958,7 @@ fillTypedHoleTests = let
]
doc <- createDoc "Test.hs" "haskell" $ mkDoc "_"
_ <- waitForDiagnostics
actions <- getCodeActions doc (Range (Position 2 13) (Position 2 14))
actions <- getCodeActions doc (Range (Position 2 12) (Position 2 13))
chosen <- pickActionWithTitle "Replace _ with (<$>)" actions
executeCodeAction chosen
modifiedCode <- documentContents doc
Expand All @@ -2971,7 +2971,7 @@ fillTypedHoleTests = let
]
doc <- createDoc "Test.hs" "haskell" $ mkDoc "`_`"
_ <- waitForDiagnostics
actions <- getCodeActions doc (Range (Position 2 16) (Position 2 19))
actions <- getCodeActions doc (Range (Position 2 18) (Position 2 19))
chosen <- pickActionWithTitle "Replace _ with (<$>)" actions
executeCodeAction chosen
modifiedCode <- documentContents doc
Expand Down
Loading