Skip to content

Commit

Permalink
Map the new FormattingEdit to LSP's TextEdit
Browse files Browse the repository at this point in the history
  • Loading branch information
aabounegm committed Nov 27, 2023
1 parent f2dda6e commit 1408e34
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions rzk/src/Language/Rzk/VSCode/Lsp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1408e34

Please sign in to comment.