From d78953d2379edf4eceeaf24aff88cc3fdec25146 Mon Sep 17 00:00:00 2001 From: Lutz Date: Thu, 26 Oct 2023 17:00:22 +0800 Subject: [PATCH] Fix https://github.com/haskell/haskell-language-server/issues/3847 --- hls-plugin-api/src/Ide/PluginUtils.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hls-plugin-api/src/Ide/PluginUtils.hs b/hls-plugin-api/src/Ide/PluginUtils.hs index 2813132fba..bb340d5dac 100644 --- a/hls-plugin-api/src/Ide/PluginUtils.hs +++ b/hls-plugin-api/src/Ide/PluginUtils.hs @@ -236,7 +236,13 @@ usePropertyLsp kn pId p = do extractTextInRange :: Range -> T.Text -> T.Text extractTextInRange (Range (Position sl sc) (Position el ec)) s = newS where - focusLines = take (fromIntegral $ el - sl + 1) $ drop (fromIntegral sl) $ T.lines s + -- NOTE: Always append an empty line to the end to ensure there are + -- sufficient lines to take from. + focusLines = + T.lines s + & (++ [""]) + & drop (fromIntegral sl) + & take (fromIntegral $ el - sl + 1) -- NOTE: We have to trim the last line first to handle the single-line case newS = focusLines