diff --git a/app/Main.hs b/app/Main.hs index 05a0a24..c73d82a 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -177,7 +177,7 @@ handleStdin wrappedIn clientReqMap serverReqMap = do modifyMVar_ clientReqMap $ \m -> case updateClientRequestMap m msgId (SMethodAndParams meth (msg ^. Lens.params)) of Just m' -> return m' Nothing -> return m - transformClientReq meth msg >>= liftIO . writeToHandle wrappedIn . A.encode + transformClientReq rustNotebookConfig meth msg >>= liftIO . writeToHandle wrappedIn . A.encode Right (ClientToServerNot meth msg) -> transformClientNot rustNotebookConfig sendExtraNotification meth msg >>= (liftIO . writeToHandle wrappedIn . A.encode) where diff --git a/package.yaml b/package.yaml index 7d03177..b3aaeda 100644 --- a/package.yaml +++ b/package.yaml @@ -40,6 +40,7 @@ library: dependencies: - containers - filepath + - lens - mtl - notebook-language-server-core - pcre-light diff --git a/rust-notebook-language-server.cabal b/rust-notebook-language-server.cabal index b3d1985..c0230da 100644 --- a/rust-notebook-language-server.cabal +++ b/rust-notebook-language-server.cabal @@ -41,6 +41,7 @@ library base >=4.7 && <5 , containers , filepath + , lens , lsp-types >=2.0.0.1 , monad-logger , mtl diff --git a/src/Transform/Config.hs b/src/Transform/Config.hs index c81a6d7..7990371 100644 --- a/src/Transform/Config.hs +++ b/src/Transform/Config.hs @@ -2,6 +2,7 @@ module Transform.Config (rustNotebookConfig) where +import Control.Lens hiding ((<.>)) import Control.Monad.IO.Class import Control.Monad.Logger import Control.Monad.Reader @@ -14,6 +15,7 @@ import Language.LSP.Notebook import Language.LSP.NotebookLanguageServer.Config import Language.LSP.NotebookLanguageServer.Transform.ServerRsp.Hover (mkDocRegex) import Language.LSP.NotebookLanguageServer.Transform.Util +import Language.LSP.Protocol.Lens import Language.LSP.Protocol.Types import Language.LSP.Transformer (Doc) import Text.Regex.PCRE.Light (Regex) @@ -29,9 +31,26 @@ rustNotebookConfig = NotebookConfig { , notebookConfigMakeShadowDocument = makeShadowDocument , notebookConfigUnopenedUri = addExtensionToUri ".rs" , notebookConfigOnDocumentsChanged = updateLibRs + , notebookConfigTransformInitialize = transformInitialize + , notebookConfigCustomUriMethods = ["rust-analyzer/analyzerStatus"] , notebookConfigLanguageName = "rust" } +-- | rust-analyzer gets pointed at the shadow crate rather than the notebook's directory, and +-- we need didSave notifications to keep the crate on disk up to date. +transformInitialize :: TransformerMonad RustNotebookTransformer n => InitializeParams -> n InitializeParams +transformInitialize params = do + dir <- asks transformerShadowDir + pure $ params + & set rootPath (Just (InL (T.pack dir))) + & set rootUri (InL (filePathToUri dir)) + & set (capabilities . textDocument . _Just . synchronization) (Just $ TextDocumentSyncClientCapabilities { + _dynamicRegistration = Just False + , _willSave = Just True + , _willSaveWaitUntil = Just False + , _didSave = Just True + }) + makeShadowDocument :: TransformerMonad RustNotebookTransformer n => Uri -> Doc -> n (Uri, FilePath, Regex) makeShadowDocument _origUri projected = do TransformerState {transformerShadowDir} <- ask diff --git a/stack.yaml b/stack.yaml index 6957565..9609a3c 100644 --- a/stack.yaml +++ b/stack.yaml @@ -13,7 +13,7 @@ system-ghc: true extra-deps: - git: https://github.com/codedownio/notebook-language-server-core.git - commit: db16c415168a1f150d43d1bf1f388d6e6272ec72 + commit: b474d01835bb175c5564b931bcec32424551fccd # - language-rust-0.2.0.27 diff --git a/stack.yaml.lock b/stack.yaml.lock index c6c8636..c6ad766 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -5,15 +5,15 @@ packages: - completed: - commit: db16c415168a1f150d43d1bf1f388d6e6272ec72 + commit: b474d01835bb175c5564b931bcec32424551fccd git: https://github.com/codedownio/notebook-language-server-core.git name: notebook-language-server-core pantry-tree: - sha256: 8008b9ad9e853f1d819cb66c4bd01a5d0fc3bab7acd0f4549bfed09f1445f910 + sha256: 554c2a636ed5e2dac188feae84770503a5fb70824cac9d45c8ffe6a41e0d268b size: 1919 version: 0.1.0.0 original: - commit: db16c415168a1f150d43d1bf1f388d6e6272ec72 + commit: b474d01835bb175c5564b931bcec32424551fccd git: https://github.com/codedownio/notebook-language-server-core.git snapshots: - completed: