Skip to content

Commit

Permalink
When sqlfluff process takes too long many process overload running in…
Browse files Browse the repository at this point in the history
… parallel start overloading the cpu. Killing running process before running a new one.

(cherry picked from commit dab6319)
  • Loading branch information
Robbie Ostermann committed Jul 11, 2022
1 parent 711c98e commit 0e67f6b
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/features/utils/lintingProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class LintingProvider {
private diagnosticCollection!: vscode.DiagnosticCollection;
private delayers!: { [key: string]: ThrottledDelayer<void>; };
private linter: Linter;
private childProcess: cp.ChildProcess;

constructor(linter: Linter) {
this.linter = linter;
Expand Down Expand Up @@ -89,7 +90,7 @@ export class LintingProvider {
let delayer = this.delayers[key];

if (!delayer) {
delayer = new ThrottledDelayer<void>(Configuration.runTrigger() === RunTrigger.onType ? 250 : 0);
delayer = new ThrottledDelayer<void>(500);
this.delayers[key] = delayer;
}

Expand Down Expand Up @@ -121,8 +122,12 @@ export class LintingProvider {
}
args = args.concat(Configuration.extraArguments());

const childProcess = cp.spawn(executable, args, options);
childProcess.on("error", (error: Error) => {
if (this.childProcess) {
this.childProcess.kill();
}
this.childProcess = cp.spawn(executable, args, options);

this.childProcess.on("error", (error: Error) => {
let message = "";
if (this.executableNotFound) {
resolve();
Expand Down Expand Up @@ -157,14 +162,14 @@ export class LintingProvider {
resolve();
};

if (childProcess.pid) {
if (this.childProcess.pid) {
if (Configuration.runTrigger() === RunTrigger.onType) {
childProcess.stdin.write(textDocument.getText());
childProcess.stdin.end();
this.childProcess.stdin.write(textDocument.getText());
this.childProcess.stdin.end();
}

childProcess.stdout.on("data", onDataEvent);
childProcess.stdout.on("end", onEndEvent);
this.childProcess.stdout.on("data", onDataEvent);
this.childProcess.stdout.on("end", onEndEvent);
resolve();
} else {
resolve();
Expand Down

0 comments on commit 0e67f6b

Please sign in to comment.