Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump LSP dependencies of dhall-lsp-server package #2634

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dhall-lsp-server/dhall-lsp-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.1 && < 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
Expand Down
15 changes: 14 additions & 1 deletion dhall-lsp-server/src/Dhall/LSP/Handlers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -226,15 +231,23 @@ 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 {..}]

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 {..}]
Expand Down
8 changes: 8 additions & 0 deletions dhall-lsp-server/src/Dhall/LSP/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
46 changes: 31 additions & 15 deletions dhall-lsp-server/tests/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..)
Expand All @@ -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
Expand All @@ -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"

Expand Down Expand Up @@ -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"
Expand All @@ -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})
Expand All @@ -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})
Expand All @@ -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})
Expand All @@ -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})
Expand All @@ -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})
Expand All @@ -162,15 +178,15 @@ 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"
liftIO $ 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"
Expand All @@ -179,15 +195,15 @@ 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"
liftIO $ 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"
Expand All @@ -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"
Expand Down
Loading