mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-11 10:35:57 +03:00
Merge pull request #4372 from unisonweb/lsp/bump-lsp-version
Bump lsp lib and handle trace notifications
This commit is contained in:
commit
e49580c776
@ -60,8 +60,8 @@ extra-deps:
|
||||
- lock-file-0.7.0.0@sha256:3ad84b5e454145e1d928063b56abb96db24a99a21b493989520e58fa0ab37b00,4484
|
||||
- monad-validate-1.2.0.0@sha256:9850f408431098b28806dd464b6825a88a0b56c84f380d7fe0454c1df9d6f881,3505
|
||||
- recover-rtti-0.4.2@sha256:c179a303921126d8d782264e14f386c96e54a270df74be002e4c4ec3c8c7aebd,4529
|
||||
- lsp-types-2.0.1.1@sha256:fdc9e7569d5b55352ab856510b9727dd859ab6b836f276cb20b288834bca66d6,29317
|
||||
- lsp-2.0.0.0@sha256:80d7e84f79a2c8a8ee17d83ee157ed3c9b25c1716bad31dabd704bb793d32af0,3531
|
||||
- lsp-2.2.0.0@sha256:82fbf4b69d94d8d22543be71f89986b3e90050032d671fb3de3f8253ea1e5b6f,3550
|
||||
- lsp-types-2.0.2.0@sha256:a9a51c3cea0726d91fe63fa0670935ee720f7b31bc3f3b33b2483fc538152677,29421
|
||||
- row-types-1.0.1.2@sha256:4d4c7cb95d06a32b28ba977852d52a26b4c1f695ef083a6fd874ab6d79933b64,3071
|
||||
|
||||
ghc-options:
|
||||
|
@ -62,19 +62,19 @@ packages:
|
||||
original:
|
||||
hackage: recover-rtti-0.4.2@sha256:c179a303921126d8d782264e14f386c96e54a270df74be002e4c4ec3c8c7aebd,4529
|
||||
- completed:
|
||||
hackage: lsp-types-2.0.1.1@sha256:fdc9e7569d5b55352ab856510b9727dd859ab6b836f276cb20b288834bca66d6,29317
|
||||
hackage: lsp-2.2.0.0@sha256:82fbf4b69d94d8d22543be71f89986b3e90050032d671fb3de3f8253ea1e5b6f,3550
|
||||
pantry-tree:
|
||||
sha256: 6595878012dbb7d4520ed611d45a59d476d0de7504bbb5977b70e4fe19f3fd75
|
||||
size: 45523
|
||||
original:
|
||||
hackage: lsp-types-2.0.1.1@sha256:fdc9e7569d5b55352ab856510b9727dd859ab6b836f276cb20b288834bca66d6,29317
|
||||
- completed:
|
||||
hackage: lsp-2.0.0.0@sha256:80d7e84f79a2c8a8ee17d83ee157ed3c9b25c1716bad31dabd704bb793d32af0,3531
|
||||
pantry-tree:
|
||||
sha256: 242117f7c11289acb56dcb1779efcc335ef88c0e773dd7087dca1c3a13870bba
|
||||
sha256: 88ea35fb71d377c035770d5f0d6a3aea51919223e3bc1e492deb6f7d9cda3a85
|
||||
size: 1043
|
||||
original:
|
||||
hackage: lsp-2.0.0.0@sha256:80d7e84f79a2c8a8ee17d83ee157ed3c9b25c1716bad31dabd704bb793d32af0,3531
|
||||
hackage: lsp-2.2.0.0@sha256:82fbf4b69d94d8d22543be71f89986b3e90050032d671fb3de3f8253ea1e5b6f,3550
|
||||
- completed:
|
||||
hackage: lsp-types-2.0.2.0@sha256:a9a51c3cea0726d91fe63fa0670935ee720f7b31bc3f3b33b2483fc538152677,29421
|
||||
pantry-tree:
|
||||
sha256: 7a3f0b679066d5e4732dfa358d76e0969589d636f4012c9e87cbe3451aa3ee5e
|
||||
size: 45527
|
||||
original:
|
||||
hackage: lsp-types-2.0.2.0@sha256:a9a51c3cea0726d91fe63fa0670935ee720f7b31bc3f3b33b2483fc538152677,29421
|
||||
- completed:
|
||||
hackage: row-types-1.0.1.2@sha256:4d4c7cb95d06a32b28ba977852d52a26b4c1f695ef083a6fd874ab6d79933b64,3071
|
||||
pantry-tree:
|
||||
|
@ -42,8 +42,8 @@ dependencies:
|
||||
- ki
|
||||
- lens
|
||||
- lock-file
|
||||
- lsp >= 2.0.0.0
|
||||
- lsp-types >= 2.0.0.0
|
||||
- lsp >= 2.2.0.0
|
||||
- lsp-types >= 2.0.2.0
|
||||
- megaparsec
|
||||
- memory
|
||||
- mtl
|
||||
|
@ -112,7 +112,9 @@ serverDefinition ::
|
||||
serverDefinition vfsVar codebase runtime scope latestBranch latestPath =
|
||||
ServerDefinition
|
||||
{ defaultConfig = defaultLSPConfig,
|
||||
onConfigurationChange = Config.updateConfig,
|
||||
configSection = "unison",
|
||||
parseConfig = Config.parseConfig,
|
||||
onConfigChange = Config.updateConfig,
|
||||
doInitialize = lspDoInitialize vfsVar codebase runtime scope latestBranch latestPath,
|
||||
staticHandlers = lspStaticHandlers,
|
||||
interpretHandler = lspInterpretHandler,
|
||||
@ -148,8 +150,8 @@ lspDoInitialize vfsVar codebase runtime scope latestBranch latestPath lspContext
|
||||
pure $ Right $ env
|
||||
|
||||
-- | LSP request handlers that don't register/unregister dynamically
|
||||
lspStaticHandlers :: Handlers Lsp
|
||||
lspStaticHandlers =
|
||||
lspStaticHandlers :: ClientCapabilities -> Handlers Lsp
|
||||
lspStaticHandlers _capabilities =
|
||||
Handlers
|
||||
{ reqHandlers = lspRequestHandlers,
|
||||
notHandlers = lspNotificationHandlers
|
||||
@ -193,6 +195,7 @@ lspNotificationHandlers =
|
||||
& SMM.insert Msg.SMethod_Initialized (ClientMessageHandler Notifications.initializedHandler)
|
||||
& SMM.insert Msg.SMethod_CancelRequest (ClientMessageHandler $ Notifications.withDebugging cancelRequestHandler)
|
||||
& SMM.insert Msg.SMethod_WorkspaceDidChangeConfiguration (ClientMessageHandler Config.workspaceConfigurationChanged)
|
||||
& SMM.insert Msg.SMethod_SetTrace (ClientMessageHandler Notifications.setTraceHandler)
|
||||
|
||||
-- | A natural transformation into IO, required by the LSP lib.
|
||||
lspInterpretHandler :: Env -> Lsp <~> IO
|
||||
|
@ -5,13 +5,15 @@ module Unison.LSP.Configuration where
|
||||
import Data.Aeson
|
||||
import Data.Text qualified as Text
|
||||
import Language.LSP.Protocol.Message qualified as Msg
|
||||
import Unison.Debug qualified as Debug
|
||||
import Unison.LSP.Types
|
||||
import Unison.Prelude
|
||||
|
||||
-- | Handle configuration changes
|
||||
updateConfig :: Config -> Value -> Either Text Config
|
||||
updateConfig _oldConfig newConfig = Debug.debug Debug.LSP "Configuration Change" $ case fromJSON newConfig of
|
||||
-- | Handle configuration changes.
|
||||
updateConfig :: Applicative m => Config -> m ()
|
||||
updateConfig _newConfig = pure ()
|
||||
|
||||
parseConfig :: Config -> Value -> Either Text Config
|
||||
parseConfig _oldConfig newConfig = case fromJSON newConfig of
|
||||
Error err -> Left $ Text.pack err
|
||||
Success a -> Right a
|
||||
|
||||
|
@ -2,14 +2,19 @@
|
||||
|
||||
module Unison.LSP.NotificationHandlers where
|
||||
|
||||
import Language.LSP.Protocol.Message
|
||||
import Language.LSP.Protocol.Message qualified as Msg
|
||||
import Unison.Debug qualified as Debug
|
||||
import Unison.LSP.Types
|
||||
|
||||
initializedHandler :: TNotificationMessage 'Method_Initialized -> Lsp ()
|
||||
initializedHandler :: Msg.TNotificationMessage 'Msg.Method_Initialized -> Lsp ()
|
||||
initializedHandler _ = pure ()
|
||||
|
||||
withDebugging :: (Show m) => (m -> Lsp ()) -> (m -> Lsp ())
|
||||
withDebugging handler message = do
|
||||
Debug.debugM Debug.LSP "Notification" message
|
||||
handler message
|
||||
|
||||
setTraceHandler :: Msg.TNotificationMessage 'Msg.Method_SetTrace -> Lsp ()
|
||||
setTraceHandler _ =
|
||||
-- We don't handle trace messages yet, but we get warnings if we don't handle them.
|
||||
pure ()
|
||||
|
@ -14,14 +14,9 @@ import Control.Lens hiding (List, (:<))
|
||||
import Control.Monad.Except
|
||||
import Control.Monad.Reader
|
||||
import Data.Aeson qualified as Aeson
|
||||
import Data.Aeson.Key qualified as Aeson.Key
|
||||
import Data.Aeson.KeyMap qualified as Aeson.KeyMap
|
||||
import Data.ByteString.Lazy.Char8 qualified as BSC
|
||||
import Data.IntervalMap.Lazy (IntervalMap)
|
||||
import Data.IntervalMap.Lazy qualified as IM
|
||||
import Data.Map qualified as Map
|
||||
import Data.Set qualified as Set
|
||||
import Data.Text qualified as Text
|
||||
import Ki qualified
|
||||
import Language.LSP.Logging qualified as LSP
|
||||
import Language.LSP.Protocol.Lens
|
||||
@ -34,6 +29,7 @@ import Unison.Codebase
|
||||
import Unison.Codebase.Path qualified as Path
|
||||
import Unison.Codebase.Runtime (Runtime)
|
||||
import Unison.DataDeclaration qualified as DD
|
||||
import Unison.Debug qualified as Debug
|
||||
import Unison.LSP.Orphans ()
|
||||
import Unison.LabeledDependency (LabeledDependency)
|
||||
import Unison.Name (Name)
|
||||
@ -185,18 +181,8 @@ data Config = Config
|
||||
instance Aeson.FromJSON Config where
|
||||
parseJSON = Aeson.withObject "Config" \obj -> do
|
||||
maxCompletions <- obj Aeson..:! "maxCompletions" Aeson..!= maxCompletions defaultLSPConfig
|
||||
let invalidKeys = Set.fromList (map Aeson.Key.toText (Aeson.KeyMap.keys obj)) `Set.difference` validKeys
|
||||
when (not . null $ invalidKeys) do
|
||||
fail . Text.unpack $
|
||||
"Unrecognized configuration key(s): "
|
||||
<> Text.intercalate ", " (Set.toList invalidKeys)
|
||||
<> ".\nThe default configuration is:\n"
|
||||
<> Text.pack defaultConfigExample
|
||||
Debug.debugM Debug.LSP "Config" $ "maxCompletions: " <> show maxCompletions
|
||||
pure Config {..}
|
||||
where
|
||||
validKeys = Set.fromList ["maxCompletions"]
|
||||
defaultConfigExample =
|
||||
BSC.unpack $ Aeson.encode defaultLSPConfig
|
||||
|
||||
instance Aeson.ToJSON Config where
|
||||
toJSON (Config maxCompletions) =
|
||||
|
@ -196,8 +196,8 @@ library
|
||||
, ki
|
||||
, lens
|
||||
, lock-file
|
||||
, lsp >=2.0.0.0
|
||||
, lsp-types >=2.0.0.0
|
||||
, lsp >=2.2.0.0
|
||||
, lsp-types >=2.0.2.0
|
||||
, megaparsec
|
||||
, memory
|
||||
, mtl
|
||||
@ -334,8 +334,8 @@ executable cli-integration-tests
|
||||
, ki
|
||||
, lens
|
||||
, lock-file
|
||||
, lsp >=2.0.0.0
|
||||
, lsp-types >=2.0.0.0
|
||||
, lsp >=2.2.0.0
|
||||
, lsp-types >=2.0.2.0
|
||||
, megaparsec
|
||||
, memory
|
||||
, mtl
|
||||
@ -466,8 +466,8 @@ executable transcripts
|
||||
, ki
|
||||
, lens
|
||||
, lock-file
|
||||
, lsp >=2.0.0.0
|
||||
, lsp-types >=2.0.0.0
|
||||
, lsp >=2.2.0.0
|
||||
, lsp-types >=2.0.2.0
|
||||
, megaparsec
|
||||
, memory
|
||||
, mtl
|
||||
@ -604,8 +604,8 @@ executable unison
|
||||
, ki
|
||||
, lens
|
||||
, lock-file
|
||||
, lsp >=2.0.0.0
|
||||
, lsp-types >=2.0.0.0
|
||||
, lsp >=2.2.0.0
|
||||
, lsp-types >=2.0.2.0
|
||||
, megaparsec
|
||||
, memory
|
||||
, mtl
|
||||
@ -749,8 +749,8 @@ test-suite cli-tests
|
||||
, ki
|
||||
, lens
|
||||
, lock-file
|
||||
, lsp >=2.0.0.0
|
||||
, lsp-types >=2.0.0.0
|
||||
, lsp >=2.2.0.0
|
||||
, lsp-types >=2.0.2.0
|
||||
, megaparsec
|
||||
, memory
|
||||
, mtl
|
||||
|
Loading…
Reference in New Issue
Block a user