Skip to content

Commit

Permalink
Limit parallel jobs / cherrypick of #177
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Feb 6, 2024
1 parent 4752595 commit 9c2f44d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions ls/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type Config struct {
EnableLogging bool
SkipLibrariesDiscoveryOnRebuild bool
DisableRealTimeDiagnostics bool
Jobs int
}

var yellow = color.New(color.FgHiYellow)
Expand Down
9 changes: 9 additions & 0 deletions ls/lsp_client_clangd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -141,6 +142,7 @@ func main() {
CliInstanceNumber: *cliDaemonInstanceNumber,
SkipLibrariesDiscoveryOnRebuild: *skipLibrariesDiscoveryOnRebuild,
DisableRealTimeDiagnostics: *noRealTimeDiagnostics,
Jobs: *jobs,
}

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

0 comments on commit 9c2f44d

Please sign in to comment.