diff --git a/ghcide/src/Development/IDE/Core/PluginUtils.hs b/ghcide/src/Development/IDE/Core/PluginUtils.hs index 330468affe..4f3c88f2e0 100644 --- a/ghcide/src/Development/IDE/Core/PluginUtils.hs +++ b/ghcide/src/Development/IDE/Core/PluginUtils.hs @@ -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] diff --git a/hls-plugin-api/src/Ide/PluginUtils.hs b/hls-plugin-api/src/Ide/PluginUtils.hs index e34d19f8b0..69f2bdb793 100644 --- a/hls-plugin-api/src/Ide/PluginUtils.hs +++ b/hls-plugin-api/src/Ide/PluginUtils.hs @@ -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) @@ -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 -- --------------------------------------------------------------------- diff --git a/plugins/hls-refactor-plugin/test/Main.hs b/plugins/hls-refactor-plugin/test/Main.hs index 0897b1ca03..8d6ef15f0c 100644 --- a/plugins/hls-refactor-plugin/test/Main.hs +++ b/plugins/hls-refactor-plugin/test/Main.hs @@ -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" @@ -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 @@ -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