lsp-test 0.5.0.2 → 0.5.1.0
raw patch · 9 files changed
+43/−8 lines, 9 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
+ Language.Haskell.LSP.Test: UnexpectedServerTermination :: SessionException
+ Language.Haskell.LSP.Test: getTypeDefinitions :: TextDocumentIdentifier -> Position -> Session [Location]
Files
- ChangeLog.md +4/−0
- README.md +8/−3
- lsp-test.cabal +3/−3
- src/Language/Haskell/LSP/Test.hs +9/−0
- src/Language/Haskell/LSP/Test/Decoding.hs +4/−1
- src/Language/Haskell/LSP/Test/Exceptions.hs +2/−0
- src/Language/Haskell/LSP/Test/Messages.hs +1/−0
- src/Language/Haskell/LSP/Test/Session.hs +5/−1
- test/Test.hs +7/−0
ChangeLog.md view
@@ -1,5 +1,9 @@ # Revision history for lsp-test +## 0.5.1.0 -- 2019-04-07++* Add getTypeDefinitions (@fendor) + ## 0.5.0.2 -- 2018-12-05 * Fix loose threads when exceptions are thrown
README.md view
@@ -38,6 +38,11 @@ For more examples check the [Wiki](https://github.com/bubba/lsp-test/wiki/Introduction) ## Developing-To test make sure you have the following language servers installed:-- [haskell-ide-engine](https://github.com/haskell/haskell-ide-engine)-- [javascript-typescript-langserver](https://github.com/sourcegraph/javascript-typescript-langserver)+The tests are integration tests, so make sure you have the following language servers installed and on your PATH:+### [haskell-ide-engine](https://github.com/haskell/haskell-ide-engine)+- Check out a relatively recent version of the repo, or see `.travis.yml` to get the exact commit used for CI.+- `stack install`+### [javascript-typescript-langserver](https://github.com/sourcegraph/javascript-typescript-langserver)+`npm i -g javascript-typescript-langserver`++Then run the tests with `stack test` or `cabal new-test`.
lsp-test.cabal view
@@ -1,5 +1,5 @@ name: lsp-test-version: 0.5.0.2+version: 0.5.1.0 synopsis: Functional test framework for LSP servers. description: A test framework for writing tests against @@ -15,13 +15,13 @@ maintainer: luke_lau@icloud.com stability: experimental bug-reports: https://github.com/Bubba/haskell-lsp-test/issues-copyright: 2018 Luke Lau+copyright: 2019 Luke Lau category: Testing build-type: Simple cabal-version: 2.0 extra-source-files: README.md , ChangeLog.md-tested-with: GHC == 8.2.2 , GHC == 8.4.2 , GHC == 8.4.3+tested-with: GHC == 8.2.2 , GHC == 8.4.2 , GHC == 8.4.3, GHC == 8.6.4 source-repository head type: git
src/Language/Haskell/LSP/Test.hs view
@@ -65,6 +65,7 @@ , getReferences -- ** Definitions , getDefinitions+ , getTypeDefinitions -- ** Renaming , rename -- ** Hover@@ -493,6 +494,14 @@ getDefinitions doc pos = let params = TextDocumentPositionParams doc pos in getResponseResult <$> request TextDocumentDefinition params++-- | Returns the type definition(s) for the term at the specified position.+getTypeDefinitions :: TextDocumentIdentifier -- ^ The document the term is in.+ -> Position -- ^ The position the term is at.+ -> Session [Location] -- ^ The location(s) of the definitions+getTypeDefinitions doc pos =+ let params = TextDocumentPositionParams doc pos+ in getResponseResult <$> request TextDocumentTypeDefinition params -- | Renames the term at the specified position. rename :: TextDocumentIdentifier -> Position -> String -> Session ()
src/Language/Haskell/LSP/Test/Decoding.hs view
@@ -13,6 +13,7 @@ import Language.Haskell.LSP.Types.Lens hiding ( error ) import Language.Haskell.LSP.Messages+import Language.Haskell.LSP.Test.Exceptions import qualified Data.HashMap.Strict as HM getAllMessages :: Handle -> IO [B.ByteString]@@ -49,7 +50,7 @@ let (name, val) = span (/= ':') l if null val then return [] else ((name, drop 2 val) :) <$> getHeaders h where eofHandler e- | isEOFError e = error "Language Server unexpectedly terminated"+ | isEOFError e = throw UnexpectedServerTermination | otherwise = throw e type RequestMap = HM.HashMap LspId ClientMethod@@ -71,6 +72,7 @@ (ReqCompletionItemResolve val) -> insert val acc (ReqSignatureHelp val) -> insert val acc (ReqDefinition val) -> insert val acc+ (ReqTypeDefinition val) -> insert val acc (ReqFindReferences val) -> insert val acc (ReqDocumentHighlights val) -> insert val acc (ReqDocumentSymbols val) -> insert val acc@@ -98,6 +100,7 @@ CompletionItemResolve -> RspCompletionItemResolve . decoded TextDocumentSignatureHelp -> RspSignatureHelp . decoded TextDocumentDefinition -> RspDefinition . decoded+ TextDocumentTypeDefinition -> RspTypeDefinition . decoded TextDocumentReferences -> RspFindReferences . decoded TextDocumentDocumentHighlight -> RspDocumentHighlights . decoded TextDocumentDocumentSymbol -> RspDocumentSymbols . decoded
src/Language/Haskell/LSP/Test/Exceptions.hs view
@@ -17,6 +17,7 @@ | UnexpectedDiagnostics | IncorrectApplyEditRequest String | UnexpectedResponseError LspIdRsp ResponseError+ | UnexpectedServerTermination deriving Eq instance Exception SessionException@@ -42,6 +43,7 @@ ++ msgStr show (UnexpectedResponseError lid e) = "Received an exepected error in a response for id " ++ show lid ++ ":\n" ++ show e+ show UnexpectedServerTermination = "Language server unexpectedly terminated" -- | A predicate that matches on any 'SessionException' anySessionException :: SessionException -> Bool
src/Language/Haskell/LSP/Test/Messages.hs view
@@ -13,6 +13,7 @@ isServerResponse (RspCompletionItemResolve _) = True isServerResponse (RspSignatureHelp _) = True isServerResponse (RspDefinition _) = True+isServerResponse (RspTypeDefinition _) = True isServerResponse (RspFindReferences _) = True isServerResponse (RspDocumentHighlights _) = True isServerResponse (RspDocumentSymbols _) = True
src/Language/Haskell/LSP/Test/Session.hs view
@@ -201,9 +201,12 @@ messageChan <- newChan initRsp <- newEmptyMVar + mainThreadId <- myThreadId+ let context = SessionContext serverIn absRootDir messageChan reqMap initRsp config caps initState = SessionState (IdInt 0) mempty mempty 0 False Nothing- launchServerHandler = forkIO $ void $ serverHandler serverOut context+ launchServerHandler = forkIO $ catch (serverHandler serverOut context)+ (throwTo mainThreadId :: SessionException -> IO ()) (result, _) <- bracket launchServerHandler killThread $ const $ runSession context initState session @@ -332,3 +335,4 @@ | otherwise = Cyan showPretty = B.unpack . encodePretty+
test/Test.hs view
@@ -259,6 +259,13 @@ defs <- getDefinitions doc pos liftIO $ defs `shouldBe` [Location (doc ^. uri) (mkRange 28 0 28 7)] + -- describe "getTypeDefinitions" $+ -- it "works" $ runSession "hie" fullCaps "test/data/renamePass" $ do+ -- doc <- openDoc "Desktop/simple.hs" "haskell"+ -- let pos = Position 20 23 -- Quit value+ -- defs <- getTypeDefinitions doc pos+ -- liftIO $ defs `shouldBe` [Location (doc ^. uri) (mkRange 10 5 10 12)] -- Type definition+ describe "waitForDiagnosticsSource" $ it "works" $ runSession "hie" fullCaps "test/data" $ do openDoc "Error.hs" "haskell"