@@ -8,7 +8,8 @@ module Development.IDE.Main
8
8
,defaultMain
9
9
) where
10
10
import Control.Concurrent.Extra (newLock , readVar ,
11
- withLock )
11
+ withLock ,
12
+ withNumCapabilities )
12
13
import Control.Exception.Safe (Exception (displayException ),
13
14
catchAny )
14
15
import Control.Monad.Extra (concatMapM , unless ,
@@ -68,6 +69,7 @@ import Development.IDE.Types.Options (IdeGhcSession,
68
69
defaultIdeOptions ,
69
70
optModifyDynFlags )
70
71
import Development.IDE.Types.Shake (Key (Key ))
72
+ import GHC.Conc (getNumProcessors )
71
73
import GHC.IO.Encoding (setLocaleEncoding )
72
74
import GHC.IO.Handle (hDuplicate )
73
75
import HIE.Bios.Cradle (findCradle )
@@ -86,6 +88,7 @@ import Ide.Types (IdeCommand (IdeCommand),
86
88
PluginId (PluginId ),
87
89
ipMap )
88
90
import qualified Language.LSP.Server as LSP
91
+ import Numeric.Natural (Natural )
89
92
import Options.Applicative hiding (action )
90
93
import qualified System.Directory.Extra as IO
91
94
import System.Exit (ExitCode (ExitFailure ),
@@ -163,6 +166,7 @@ data Arguments = Arguments
163
166
, argsDebouncer :: IO (Debouncer NormalizedUri ) -- ^ Debouncer used for diagnostics
164
167
, argsHandleIn :: IO Handle
165
168
, argsHandleOut :: IO Handle
169
+ , argsThreads :: Maybe Natural
166
170
}
167
171
168
172
instance Default Arguments where
@@ -179,6 +183,7 @@ instance Default Arguments where
179
183
, argsDefaultHlsConfig = def
180
184
, argsGetHieDbLoc = getHieDbLoc
181
185
, argsDebouncer = newAsyncDebouncer
186
+ , argsThreads = Nothing
182
187
, argsHandleIn = pure stdin
183
188
, argsHandleOut = do
184
189
-- Move stdout to another file descriptor and duplicate stderr
@@ -221,12 +226,14 @@ defaultMain Arguments{..} = do
221
226
inH <- argsHandleIn
222
227
outH <- argsHandleOut
223
228
229
+ numProcessors <- getNumProcessors
230
+
224
231
case argCommand of
225
232
PrintExtensionSchema ->
226
233
LT. putStrLn $ decodeUtf8 $ A. encodePretty $ pluginsToVSCodeExtensionSchema argsHlsPlugins
227
234
PrintDefaultConfig ->
228
235
LT. putStrLn $ decodeUtf8 $ A. encodePretty $ pluginsToDefaultConfig argsHlsPlugins
229
- LSP -> do
236
+ LSP -> withNumCapabilities ( maybe (numProcessors `div` 2 ) fromIntegral argsThreads) $ do
230
237
t <- offsetTime
231
238
hPutStrLn stderr " Starting LSP server..."
232
239
hPutStrLn stderr " If you are seeing this in a terminal, you probably should have run WITHOUT the --lsp option!"
0 commit comments