diff --git a/ls/ls.go b/ls/ls.go index f5d734a..d055cb8 100644 --- a/ls/ls.go +++ b/ls/ls.go @@ -80,6 +80,7 @@ type Config struct { EnableLogging bool SkipLibrariesDiscoveryOnRebuild bool DisableRealTimeDiagnostics bool + Jobs int } var yellow = color.New(color.FgHiYellow) diff --git a/ls/lsp_client_clangd.go b/ls/lsp_client_clangd.go index d4b9322..eb8a103 100644 --- a/ls/lsp_client_clangd.go +++ b/ls/lsp_client_clangd.go @@ -51,8 +51,17 @@ func newClangdLSPClient(logger jsonrpc.FunctionLogger, dataFolder *paths.Path, l args := []string{ ls.config.ClangdPath.String(), "-log=verbose", + "--pch-storage=memory", fmt.Sprintf(`--compile-commands-dir=%s`, ls.buildPath), } + if jobs := ls.config.Jobs; jobs == -1 { + // default: limit parallel build jobs to 1 + args = append(args, "-j", "1") + } else if jobs == 0 { + // no args: clangd will max out the available cores + } else { + args = append(args, "-j", fmt.Sprintf("%d", jobs)) + } if dataFolder != nil { args = append(args, fmt.Sprintf("-query-driver=%s", dataFolder.Join("packages", "**").Canonical())) } diff --git a/main.go b/main.go index ed38ad5..b1b5883 100644 --- a/main.go +++ b/main.go @@ -70,6 +70,7 @@ func main() { noRealTimeDiagnostics := flag.Bool( "no-real-time-diagnostics", false, "Disable real time diagnostics") + jobs := flag.Int("jobs", -1, "Max number of parallel jobs. Default is 1. Use 0 to match the number of available CPU cores.") flag.Parse() if *loggingBasePath != "" { @@ -141,6 +142,7 @@ func main() { CliInstanceNumber: *cliDaemonInstanceNumber, SkipLibrariesDiscoveryOnRebuild: *skipLibrariesDiscoveryOnRebuild, DisableRealTimeDiagnostics: *noRealTimeDiagnostics, + Jobs: *jobs, } stdio := streams.NewReadWriteCloser(os.Stdin, os.Stdout)