-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new handler: inspect and insert proof template
- Loading branch information
Vince
committed
Feb 20, 2024
1 parent
289b27f
commit e0cbc2c
Showing
10 changed files
with
405 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE BlockArguments #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
module Server.Handler2.CustomMethod.HelloWorld (handler) where | ||
|
||
import Data.String (fromString) | ||
import Data.Loc.Range (Range (..), rangeFile, rangeStart, rangeEnd) | ||
|
||
import Render (Section (..), Deco (..), Block (..)) | ||
import Error (Error(..)) | ||
|
||
import Server.Monad (ServerM) | ||
import Server.Handler2.Utils | ||
|
||
|
||
handler :: Range -> ([ResKind] -> ServerM ()) -> (Error -> ServerM ()) -> ServerM () | ||
handler range onFinish onError = do | ||
let filepath :: FilePath = rangeFile range | ||
replaceWithHelloworld filepath range (do | ||
let helloWorldRange = rangeAfterReplacedWithHelloWorld range | ||
let diagnosticOnHelloWorld = makeDiagnostic Nothing helloWorldRange "Hello, World?" "This is a warning" | ||
_ <- sendDiagnostics filepath [diagnosticOnHelloWorld] | ||
version <- bumpVersion | ||
onFinish [ | ||
ResDisplay version [ | ||
Section Blue [ | ||
Header "Hello, world" Nothing | ||
, Paragraph $ fromString "LSP server successfully responded." | ||
] | ||
] | ||
] | ||
) onError | ||
|
||
replaceWithHelloworld :: FilePath -> Range -> ServerM () -> (Error -> ServerM ()) -> ServerM () | ||
replaceWithHelloworld filepath range onFinish onError = do | ||
maybeSource <- getSource filepath | ||
case maybeSource of | ||
Nothing -> onError (CannotReadFile filepath) | ||
Just source -> do | ||
logText "before replacement" | ||
logText source | ||
logText "\n" | ||
editText range "Hello, World!\n" $ do | ||
maybeSource' <- getSource filepath | ||
case maybeSource' of | ||
Nothing -> onError (CannotReadFile filepath) | ||
Just source' -> do | ||
logText "after replacement" | ||
logText source' | ||
logText "\n" | ||
onFinish | ||
|
||
rangeAfterReplacedWithHelloWorld :: Range -> Range | ||
rangeAfterReplacedWithHelloWorld range = | ||
Range (rangeStart range) (addToCoff 13 $ rangeEnd range) | ||
where | ||
addToCoff :: Int -> Pos -> Pos | ||
addToCoff offset pos = Pos (posFile pos) (posLine pos) (posCol pos) (posCoff pos + offset) |
Oops, something went wrong.