Skip to content

Commit 93de3ac

Browse files
committed
Add --did-save-period-ms option
1 parent a2e7ee5 commit 93de3ac

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

app/Main.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ data Options = Options {
5252
optWrappedLanguageServer :: Maybe FilePath
5353
, optWrappedArgs :: Maybe Text
5454
, optShadowDirTemplate :: Maybe FilePath
55+
, optDidSaveDebouncePeriodMs :: Int
5556
, optLogLevel :: Maybe Text
5657
}
5758

@@ -60,6 +61,7 @@ options = Options
6061
<$> optional (strOption (long "wrapped-server" <> help "Wrapped rust-analyzer binary"))
6162
<*> optional (strOption (long "wrapped-args" <> help "Extra arguments to rust-analyzer"))
6263
<*> optional (strOption (long "shadow-dir-template" <> help "Template for making a shadow project directory"))
64+
<*> option auto (long "did-save-period-ms" <> showDefault <> help "Debounce period for sending textDocument/didSave notifications after changes" <> value 1000 <> metavar "INT")
6365
<*> optional (strOption (long "log-level" <> help "Log level (debug, info, warn, error)"))
6466

6567
fullOpts :: ParserInfo Options
@@ -134,7 +136,7 @@ main = do
134136
}
135137

136138
withMaybeShadowDir optShadowDirTemplate $ \maybeShadowDir -> do
137-
transformerState <- newTransformerState maybeShadowDir
139+
transformerState <- newTransformerState maybeShadowDir optDidSaveDebouncePeriodMs
138140

139141
flip runLoggingT logFn $ filterLogger logFilterFn $ flip runReaderT transformerState $
140142
withAsync (readWrappedOut clientReqMap serverReqMap wrappedOut sendToStdout) $ \_wrappedOutAsync ->

default.nix

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ mkDerivation {
1919
unliftio-core uuid
2020
];
2121
executableHaskellDepends = [
22-
aeson auto-update base bytestring lens lsp-types monad-logger mtl
22+
aeson base bytestring lens lsp-types monad-logger mtl
2323
optparse-applicative process retry safe string-interpolate text
24-
unix unliftio unliftio-core uuid
24+
unix unliftio unliftio-core
2525
];
2626
testHaskellDepends = [
27-
auto-update base exceptions lsp-types monad-logger myers-diff
28-
QuickCheck quickcheck-instances row-types sandwich
29-
sandwich-quickcheck string-interpolate text text-rope unliftio uuid
27+
base exceptions lsp-types monad-logger myers-diff QuickCheck
28+
quickcheck-instances row-types sandwich sandwich-quickcheck
29+
string-interpolate text text-rope unliftio
3030
];
3131
doCheck = false;
3232
license = "unknown";

package.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ extra-source-files:
66
- CHANGELOG.md
77

88
dependencies:
9-
- auto-update
109
- base >= 4.7 && < 5
1110
# - language-rust
1211
- lsp-types >= 2.0.0.1
1312
- monad-logger
1413
- string-interpolate
1514
- text
1615
- unliftio
17-
- uuid
1816

1917
default-extensions:
2018
- OverloadedStrings
@@ -40,6 +38,7 @@ library:
4038
source-dirs: src
4139
dependencies:
4240
- aeson
41+
- auto-update
4342
- containers
4443
- filepath
4544
- lens
@@ -54,6 +53,7 @@ library:
5453
- text-rope
5554
- time
5655
- unliftio-core
56+
- uuid
5757

5858
executables:
5959
rust-notebook-language-server:

rust-notebook-language-server.cabal

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ executable rust-notebook-language-server
100100
ghc-options: -Wunused-packages -Wall -fno-warn-name-shadowing -threaded -rtsopts -with-rtsopts=-N -O2 -W
101101
build-depends:
102102
aeson
103-
, auto-update
104103
, base >=4.7 && <5
105104
, bytestring
106105
, lens
@@ -117,7 +116,6 @@ executable rust-notebook-language-server
117116
, unix
118117
, unliftio
119118
, unliftio-core
120-
, uuid
121119
default-language: Haskell2010
122120

123121
test-suite rust-notebook-language-server-test
@@ -151,7 +149,6 @@ test-suite rust-notebook-language-server-test
151149
ghc-options: -Wunused-packages -Wall -fno-warn-name-shadowing -threaded -rtsopts -with-rtsopts=-N -O2 -W
152150
build-depends:
153151
QuickCheck
154-
, auto-update
155152
, base >=4.7 && <5
156153
, exceptions
157154
, lsp-types >=2.0.0.1
@@ -166,5 +163,4 @@ test-suite rust-notebook-language-server-test
166163
, text
167164
, text-rope
168165
, unliftio
169-
, uuid
170166
default-language: Haskell2010

src/Transform/ClientNot.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ transformClientNot' sendExtraNotification SMethod_TextDocumentDidOpen params = w
8686
| documentUuid == uuid -> runInIO $ doDidSave ds sendExtraNotification
8787
| otherwise -> return ()
8888
_ -> return ()
89-
, debounceFreq = 5_000_000
89+
, debounceFreq = transformerDidSaveDebouncePeriodMs * 1000
9090
, debounceEdge = trailingEdge
9191
})
9292

src/Transform/Util.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,18 @@ data TransformerState = TransformerState {
110110
, transformerInitializeParams :: MVar (Maybe InitializeParams)
111111
, transformerInitializeResult :: MVar (Maybe InitializeResult)
112112
, transformerShadowDir :: FilePath
113+
, transformerDidSaveDebouncePeriodMs :: Int
113114
}
114115

115116
-- * Transformers
116117

117-
newTransformerState :: (MonadIO m) => FilePath -> m TransformerState
118-
newTransformerState shadowDir = TransformerState
118+
newTransformerState :: (MonadIO m) => FilePath -> Int -> m TransformerState
119+
newTransformerState shadowDir didSaveDebouncePeriodMs = TransformerState
119120
<$> newMVar mempty
120121
<*> newMVar Nothing
121122
<*> newMVar Nothing
122123
<*> pure shadowDir
124+
<*> pure didSaveDebouncePeriodMs
123125

124126
lookupTransformer :: TransformerMonad m => Uri -> m (Maybe DocumentState)
125127
lookupTransformer uri = do

0 commit comments

Comments
 (0)