From bc623e2b3a4b1d360cd28b7caee9544f7ad47365 Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Thu, 30 Jan 2025 16:39:54 +0100 Subject: [PATCH 1/2] Bumped LSP dependencies of dhall-lsp-server package The following additional versions are allowed now: - lsp >=2.2 && <2.8 - lsp-types >=2.1 && <2.4 - lsp-test >=0.16 && <0.18 --- dhall-lsp-server/dhall-lsp-server.cabal | 6 +-- dhall-lsp-server/src/Dhall/LSP/Handlers.hs | 15 ++++++- dhall-lsp-server/src/Dhall/LSP/Server.hs | 8 ++++ dhall-lsp-server/tests/Main.hs | 46 +++++++++++++++------- 4 files changed, 56 insertions(+), 19 deletions(-) diff --git a/dhall-lsp-server/dhall-lsp-server.cabal b/dhall-lsp-server/dhall-lsp-server.cabal index b8b93ea43..70341d6e2 100644 --- a/dhall-lsp-server/dhall-lsp-server.cabal +++ b/dhall-lsp-server/dhall-lsp-server.cabal @@ -53,7 +53,7 @@ library , dhall >= 1.38.0 && < 1.43 , dhall-json >= 1.4 && < 1.8 , filepath >= 1.4.2 && < 1.6 - , lsp >= 2.1.0.0 && < 2.2 + , lsp >= 2.1.0.0 && < 2.8 , lens >= 4.16.1 && < 5.4 -- megaparsec follows SemVer: https://github.com/mrkkrp/megaparsec/issues/469#issuecomment-927918469 , megaparsec >= 7.0.2 && < 10 @@ -104,9 +104,9 @@ Test-Suite tests GHC-Options: -Wall Build-Depends: base >= 4.11 && < 5 , - lsp-types >= 2.0.1 && < 2.1 , + lsp-types >= 2.0.2 && < 2.4 , hspec >= 2.7 && < 2.12, - lsp-test >= 0.15.0.0 && < 0.16, + lsp-test >= 0.15.0.0 && < 0.18, tasty >= 0.11.2 && < 1.6 , tasty-hspec >= 1.1 && < 1.3 , text >= 0.11 && < 2.2 diff --git a/dhall-lsp-server/src/Dhall/LSP/Handlers.hs b/dhall-lsp-server/src/Dhall/LSP/Handlers.hs index 1ffdc5bd8..ae43474dc 100644 --- a/dhall-lsp-server/src/Dhall/LSP/Handlers.hs +++ b/dhall-lsp-server/src/Dhall/LSP/Handlers.hs @@ -91,13 +91,18 @@ import Text.Megaparsec (SourcePos (..), unPos) import qualified Data.Aeson as Aeson import qualified Data.Map.Strict as Map import qualified Data.Text as Text -import qualified Data.Text.Utf16.Rope as Rope import qualified Language.LSP.Protocol.Types as LSP.Types import qualified Language.LSP.Server as LSP import qualified Language.LSP.VFS as LSP import qualified Network.URI as URI import qualified Network.URI.Encode as URI +#if MIN_VERSION_lsp(2,4,0) +import qualified Data.Text.Utf16.Rope.Mixed as Rope +#else +import qualified Data.Text.Utf16.Rope as Rope +#endif + liftLSP :: LspT ServerConfig IO a -> HandlerM a liftLSP m = lift (lift m) @@ -226,7 +231,11 @@ documentLinkHandler = filePath <- localToPath prefix file let filePath' = basePath filePath -- absolute file path let _range = rangeToJSON range_ +#if MIN_VERSION_lsp(2,5,0) + let _target = Just (filePathToUri filePath') +#else let _target = Just (getUri (filePathToUri filePath')) +#endif let _tooltip = Nothing let _data_ = Nothing return [DocumentLink {..}] @@ -234,7 +243,11 @@ documentLinkHandler = go (range_, Import (ImportHashed _ (Remote url)) _) = do let _range = rangeToJSON range_ let url' = url { headers = Nothing } +#if MIN_VERSION_lsp(2,5,0) + let _target = Just (Uri (pretty url')) +#else let _target = Just (pretty url') +#endif let _tooltip = Nothing let _data_ = Nothing return [DocumentLink {..}] diff --git a/dhall-lsp-server/src/Dhall/LSP/Server.hs b/dhall-lsp-server/src/Dhall/LSP/Server.hs index a8e76152e..57801417e 100644 --- a/dhall-lsp-server/src/Dhall/LSP/Server.hs +++ b/dhall-lsp-server/src/Dhall/LSP/Server.hs @@ -67,7 +67,15 @@ runWith settings = withLogger $ \ioLogger -> do let defaultConfig = def +#if MIN_VERSION_lsp(2,2,0) + let configSection = "dhall" + + let onConfigChange _newConfig = return () + + let parseConfig _oldConfig json = +#else let onConfigurationChange _oldConfig json = +#endif case fromJSON json of Aeson.Success config -> Right config Aeson.Error string -> Left (Text.pack string) diff --git a/dhall-lsp-server/tests/Main.hs b/dhall-lsp-server/tests/Main.hs index 5bc44361a..bd72c7b5f 100644 --- a/dhall-lsp-server/tests/Main.hs +++ b/dhall-lsp-server/tests/Main.hs @@ -2,10 +2,13 @@ {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE OverloadedStrings #-} +{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-} + import Control.Monad.IO.Class (liftIO) import Data.Maybe (fromJust) import Language.LSP.Protocol.Types - ( CompletionItem (..) + ( ClientCapabilities + , CompletionItem (..) , Diagnostic (..) , DiagnosticSeverity (..) , Hover (..) @@ -14,25 +17,38 @@ import Language.LSP.Protocol.Types , Range (..) , toEither ) -import Language.LSP.Test import Test.Tasty import Test.Tasty.Hspec +#if MIN_VERSION_lsp_types(2,3,0) +import Language.LSP.Test hiding (fullLatestClientCaps) +#else +import Language.LSP.Test +#endif + #if MIN_VERSION_tasty_hspec(1,1,7) import Test.Hspec #endif import qualified Data.Text as T import qualified GHC.IO.Encoding +import qualified Language.LSP.Protocol.Capabilities baseDir :: FilePath -> FilePath baseDir d = "tests/fixtures/" <> d +fullLatestClientCaps :: ClientCapabilities +#if MIN_VERSION_lsp_types(2,3,0) +fullLatestClientCaps = Language.LSP.Protocol.Capabilities.fullLatestClientCaps +#else +fullLatestClientCaps = Language.LSP.Protocol.Capabilities.fullCaps +#endif + hoveringSpec :: FilePath -> Spec hoveringSpec dir = describe "Dhall.Hover" $ it "reports types on hover" - $ runSession "dhall-lsp-server" fullCaps dir + $ runSession "dhall-lsp-server" fullLatestClientCaps dir $ do docId <- openDoc "Types.dhall" "dhall" let typePos = Position 0 5 @@ -53,7 +69,7 @@ lintingSpec :: FilePath -> Spec lintingSpec fixtureDir = describe "Dhall.Lint" $ do it "reports unused bindings" - $ runSession "dhall-lsp-server" fullCaps fixtureDir + $ runSession "dhall-lsp-server" fullLatestClientCaps fixtureDir $ do _ <- openDoc "UnusedBindings.dhall" "dhall" @@ -92,7 +108,7 @@ lintingSpec fixtureDir = pure () it "reports multiple hints" - $ runSession "dhall-lsp-server" fullCaps fixtureDir + $ runSession "dhall-lsp-server" fullLatestClientCaps fixtureDir $ do _ <- openDoc "SuperfluousIn.dhall" "dhall" diags <- waitForDiagnosticsSource "Dhall.Lint" @@ -109,7 +125,7 @@ codeCompletionSpec :: FilePath -> Spec codeCompletionSpec fixtureDir = describe "Dhall.Completion" $ do it "suggests user defined types" - $ runSession "dhall-lsp-server" fullCaps fixtureDir + $ runSession "dhall-lsp-server" fullLatestClientCaps fixtureDir $ do docId <- openDoc "CustomTypes.dhall" "dhall" cs <- getCompletions docId (Position {_line = 2, _character = 35}) @@ -118,7 +134,7 @@ codeCompletionSpec fixtureDir = _label firstItem `shouldBe` "Config" _detail firstItem `shouldBe` Just "Type" it "suggests user defined functions" - $ runSession "dhall-lsp-server" fullCaps fixtureDir + $ runSession "dhall-lsp-server" fullLatestClientCaps fixtureDir $ do docId <- openDoc "CustomFunctions.dhall" "dhall" cs <- getCompletions docId (Position {_line = 6, _character = 7}) @@ -127,7 +143,7 @@ codeCompletionSpec fixtureDir = _label firstItem `shouldBe` "makeUser" _detail firstItem `shouldBe` Just "\8704(user : Text) \8594 { home : Text }" it "suggests user defined bindings" - $ runSession "dhall-lsp-server" fullCaps fixtureDir + $ runSession "dhall-lsp-server" fullLatestClientCaps fixtureDir $ do docId <- openDoc "Bindings.dhall" "dhall" cs <- getCompletions docId (Position {_line = 0, _character = 59}) @@ -136,7 +152,7 @@ codeCompletionSpec fixtureDir = _label firstItem `shouldBe` "bob" _detail firstItem `shouldBe` Just "Text" it "suggests functions from imports" - $ runSession "dhall-lsp-server" fullCaps fixtureDir + $ runSession "dhall-lsp-server" fullLatestClientCaps fixtureDir $ do docId <- openDoc "ImportedFunctions.dhall" "dhall" cs <- getCompletions docId (Position {_line = 0, _character = 33}) @@ -147,7 +163,7 @@ codeCompletionSpec fixtureDir = _detail firstItem `shouldBe` Just "\8704(user : Text) \8594 { home : Text }" _detail secondItem `shouldBe` Just "\8704(user : Text) \8594 { home : Text }" it "suggests union alternatives" - $ runSession "dhall-lsp-server" fullCaps fixtureDir + $ runSession "dhall-lsp-server" fullLatestClientCaps fixtureDir $ do docId <- openDoc "Union.dhall" "dhall" cs <- getCompletions docId (Position {_line = 2, _character = 10}) @@ -162,7 +178,7 @@ diagnosticsSpec :: FilePath -> Spec diagnosticsSpec fixtureDir = do describe "Dhall.TypeCheck" $ do it "reports unbound variables" - $ runSession "dhall-lsp-server" fullCaps fixtureDir + $ runSession "dhall-lsp-server" fullLatestClientCaps fixtureDir $ do _ <- openDoc "UnboundVar.dhall" "dhall" [diag] <- waitForDiagnosticsSource "Dhall.TypeCheck" @@ -170,7 +186,7 @@ diagnosticsSpec fixtureDir = do _severity diag `shouldBe` Just DiagnosticSeverity_Error T.unpack (_message diag) `shouldContain` "Unbound variable" it "reports wrong type" - $ runSession "dhall-lsp-server" fullCaps fixtureDir + $ runSession "dhall-lsp-server" fullLatestClientCaps fixtureDir $ do _ <- openDoc "WrongType.dhall" "dhall" [diag] <- waitForDiagnosticsSource "Dhall.TypeCheck" @@ -179,7 +195,7 @@ diagnosticsSpec fixtureDir = do T.unpack (_message diag) `shouldContain` "Expression doesn't match annotation" describe "Dhall.Import" $ do it "reports invalid imports" - $ runSession "dhall-lsp-server" fullCaps fixtureDir + $ runSession "dhall-lsp-server" fullLatestClientCaps fixtureDir $ do _ <- openDoc "InvalidImport.dhall" "dhall" [diag] <- waitForDiagnosticsSource "Dhall.Import" @@ -187,7 +203,7 @@ diagnosticsSpec fixtureDir = do _severity diag `shouldBe` Just DiagnosticSeverity_Error T.unpack (_message diag) `shouldContain` "Invalid input" it "reports missing imports" - $ runSession "dhall-lsp-server" fullCaps fixtureDir + $ runSession "dhall-lsp-server" fullLatestClientCaps fixtureDir $ do _ <- openDoc "MissingImport.dhall" "dhall" [diag] <- waitForDiagnosticsSource "Dhall.Import" @@ -196,7 +212,7 @@ diagnosticsSpec fixtureDir = do T.unpack (_message diag) `shouldContain` "Missing file" describe "Dhall.Parser" $ it "reports invalid syntax" - $ runSession "dhall-lsp-server" fullCaps fixtureDir + $ runSession "dhall-lsp-server" fullLatestClientCaps fixtureDir $ do _ <- openDoc "InvalidSyntax.dhall" "dhall" [diag] <- waitForDiagnosticsSource "Dhall.Parser" From bfc2a919de7c35c5d06d8ccf8e0b4c7e630071c8 Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Thu, 30 Jan 2025 17:03:28 +0100 Subject: [PATCH 2/2] Allow lsp-types >=2.0.1 && <2.0.2 again --- dhall-lsp-server/dhall-lsp-server.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhall-lsp-server/dhall-lsp-server.cabal b/dhall-lsp-server/dhall-lsp-server.cabal index 70341d6e2..1ed3ec7b7 100644 --- a/dhall-lsp-server/dhall-lsp-server.cabal +++ b/dhall-lsp-server/dhall-lsp-server.cabal @@ -104,7 +104,7 @@ Test-Suite tests GHC-Options: -Wall Build-Depends: base >= 4.11 && < 5 , - lsp-types >= 2.0.2 && < 2.4 , + lsp-types >= 2.0.1 && < 2.4 , hspec >= 2.7 && < 2.12, lsp-test >= 0.15.0.0 && < 0.18, tasty >= 0.11.2 && < 1.6 ,