-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b05ff6
commit 91f5e31
Showing
4 changed files
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,4 +62,7 @@ tests: | |
- lambdananas-language-server | ||
- hspec | ||
- megaparsec | ||
- text | ||
- lsp-types | ||
- lsp-test | ||
- filepath |
53 changes: 53 additions & 0 deletions
53
language-server/test/LambdananasTest/LanguageServer/CodeActions.hs
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,53 @@ | ||
{-# LANGUAGE ExplicitNamespaces #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-} | ||
|
||
module LambdananasTest.LanguageServer.CodeActions (specs) where | ||
|
||
import Control.Monad.IO.Class | ||
import Data.List (find) | ||
import qualified Data.Text as T | ||
import Language.LSP.Protocol.Message (SMethod (SMethod_TextDocumentDidSave)) | ||
import Language.LSP.Protocol.Types (CodeAction (..), Diagnostic (..), DidSaveTextDocumentParams (DidSaveTextDocumentParams), Position (Position), Range (Range), type (|?) (..)) | ||
import Language.LSP.Test | ||
import System.FilePath | ||
import Test.Hspec | ||
|
||
specs :: Spec | ||
specs = | ||
describe "Code Action" $ do | ||
it "should not suggest code actions" $ | ||
runLLSSession $ do | ||
doc <- openDoc "./src/MyPutStr.hs" "haskell" | ||
_ <- waitForDiagnostics | ||
let range = Range (Position 2 0) (Position 2 0) | ||
ca <- getCodeActions doc range | ||
liftIO $ ca `shouldBe` [] | ||
|
||
it "should suggest code action (insert header)" $ | ||
runLLSSession $ do | ||
let src = "./src/MyPutStr.hs" | ||
fullsrc = combine "./test/assets" src | ||
doc <- openDoc src "haskell" | ||
oldcontent <- documentContents doc | ||
diags <- waitForDiagnostics | ||
liftIO $ length diags `shouldBe` 3 | ||
let range = Range (Position 0 0) (Position 0 0) | ||
actions <- getCodeActions doc range | ||
liftIO $ length actions `shouldBe` 1 | ||
let InR action = head actions | ||
liftIO $ _title action `shouldBe` T.pack "Insert EPITECH Header" | ||
-- Executing an action does not actually write the src file | ||
-- So what we do is simulate a 'save' operation | ||
-- to trigger recomputation of diagnostics | ||
_ <- resolveAndExecuteCodeAction action | ||
content <- documentContents doc | ||
_ <- liftIO $ writeFile fullsrc $ T.unpack content | ||
_ <- sendNotification SMethod_TextDocumentDidSave (DidSaveTextDocumentParams doc (Just content)) | ||
newdiags <- waitForDiagnostics | ||
liftIO $ writeFile fullsrc $ T.unpack oldcontent | ||
liftIO $ do | ||
length newdiags `shouldBe` length diags - 1 | ||
find (\d -> _code d == Just (InR "H-G1")) newdiags `shouldBe` Nothing | ||
where | ||
runLLSSession = runSession "lambdananas-language-server" fullCaps "./test/assets" |
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