Skip to content

Commit 9c2f44d

Browse files
committed
Limit parallel jobs / cherrypick of #177
1 parent 4752595 commit 9c2f44d

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

Diff for: ls/ls.go

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ type Config struct {
8080
EnableLogging bool
8181
SkipLibrariesDiscoveryOnRebuild bool
8282
DisableRealTimeDiagnostics bool
83+
Jobs int
8384
}
8485

8586
var yellow = color.New(color.FgHiYellow)

Diff for: ls/lsp_client_clangd.go

+9
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,17 @@ func newClangdLSPClient(logger jsonrpc.FunctionLogger, dataFolder *paths.Path, l
5151
args := []string{
5252
ls.config.ClangdPath.String(),
5353
"-log=verbose",
54+
"--pch-storage=memory",
5455
fmt.Sprintf(`--compile-commands-dir=%s`, ls.buildPath),
5556
}
57+
if jobs := ls.config.Jobs; jobs == -1 {
58+
// default: limit parallel build jobs to 1
59+
args = append(args, "-j", "1")
60+
} else if jobs == 0 {
61+
// no args: clangd will max out the available cores
62+
} else {
63+
args = append(args, "-j", fmt.Sprintf("%d", jobs))
64+
}
5665
if dataFolder != nil {
5766
args = append(args, fmt.Sprintf("-query-driver=%s", dataFolder.Join("packages", "**").Canonical()))
5867
}

Diff for: main.go

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func main() {
7070
noRealTimeDiagnostics := flag.Bool(
7171
"no-real-time-diagnostics", false,
7272
"Disable real time diagnostics")
73+
jobs := flag.Int("jobs", -1, "Max number of parallel jobs. Default is 1. Use 0 to match the number of available CPU cores.")
7374
flag.Parse()
7475

7576
if *loggingBasePath != "" {
@@ -141,6 +142,7 @@ func main() {
141142
CliInstanceNumber: *cliDaemonInstanceNumber,
142143
SkipLibrariesDiscoveryOnRebuild: *skipLibrariesDiscoveryOnRebuild,
143144
DisableRealTimeDiagnostics: *noRealTimeDiagnostics,
145+
Jobs: *jobs,
144146
}
145147

146148
stdio := streams.NewReadWriteCloser(os.Stdin, os.Stdout)

0 commit comments

Comments
 (0)