From 1408e3437b5bfe3cba0d691c4d63440ffcf2864a Mon Sep 17 00:00:00 2001 From: Abdelrahman Abounegm Date: Mon, 27 Nov 2023 16:06:30 +0300 Subject: [PATCH] Map the new `FormattingEdit` to LSP's `TextEdit` --- rzk/src/Language/Rzk/VSCode/Lsp.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/rzk/src/Language/Rzk/VSCode/Lsp.hs b/rzk/src/Language/Rzk/VSCode/Lsp.hs index 514f8eeaa..a66f61471 100644 --- a/rzk/src/Language/Rzk/VSCode/Lsp.hs +++ b/rzk/src/Language/Rzk/VSCode/Lsp.hs @@ -21,7 +21,17 @@ import Language.Rzk.VSCode.Env import Language.Rzk.VSCode.Handlers import Language.Rzk.VSCode.Logging import Language.Rzk.VSCode.Tokenize (tokenizeModule) -import Rzk.Format (formatTextEdits) +import Rzk.Format (FormattingEdit (..), + formatTextEdits) + +formattingEditToTextEdit :: FormattingEdit -> TextEdit +formattingEditToTextEdit (FormattingEdit startLine startCol endLine endCol newText) = + TextEdit + (Range + (Position (fromIntegral startLine - 1) (fromIntegral startCol - 1)) + (Position (fromIntegral endLine - 1) (fromIntegral endCol - 1)) + ) + (T.pack newText) -- | The maximum number of diagnostic messages to send to the client maxDiagnosticCount :: Int @@ -82,7 +92,7 @@ handlers = mdoc <- getVirtualFile doc possibleEdits <- case virtualFileText <$> mdoc of Nothing -> return (Left "Failed to get file contents") - Just sourceCode -> return (Right $ formatTextEdits (filter (/= '\r') $ T.unpack sourceCode)) + Just sourceCode -> return (Right $ map formattingEditToTextEdit $ formatTextEdits (filter (/= '\r') $ T.unpack sourceCode)) case possibleEdits of Left err -> res $ Left $ ResponseError (InR ErrorCodes_InternalError) err Nothing Right edits -> res $ Right $ InL edits