Skip to content

Commit

Permalink
Use single method to kill processes
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Apr 5, 2020
1 parent fbb4cf8 commit 16cbd97
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/goDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
getWorkspaceFolderPath,
goKeywords,
isPositionInString,
killProcess,
killTree,
runGodoc
} from './util';

Expand Down Expand Up @@ -135,7 +135,7 @@ function definitionLocation_godef(
const env = getToolsEnvVars();
let p: cp.ChildProcess;
if (token) {
token.onCancellationRequested(() => killProcess(p));
token.onCancellationRequested(() => killTree(p.pid));
}

return new Promise<GoDefinitionInformation>((resolve, reject) => {
Expand Down Expand Up @@ -226,7 +226,7 @@ function definitionLocation_gogetdoc(
const env = getToolsEnvVars();
let p: cp.ChildProcess;
if (token) {
token.onCancellationRequested(() => killProcess(p));
token.onCancellationRequested(() => killTree(p.pid));
}

return new Promise<GoDefinitionInformation>((resolve, reject) => {
Expand Down Expand Up @@ -300,7 +300,7 @@ function definitionLocation_guru(
const env = getToolsEnvVars();
let p: cp.ChildProcess;
if (token) {
token.onCancellationRequested(() => killProcess(p));
token.onCancellationRequested(() => killTree(p.pid));
}
return new Promise<GoDefinitionInformation>((resolve, reject) => {
p = cp.execFile(
Expand Down
4 changes: 2 additions & 2 deletions src/goOutline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
getFileArchive,
getGoConfig,
getToolsEnvVars,
killProcess,
killTree,
makeMemoizedByteOffsetConverter
} from './util';

Expand Down Expand Up @@ -88,7 +88,7 @@ export function runGoOutline(

let p: cp.ChildProcess;
if (token) {
token.onCancellationRequested(() => killProcess(p));
token.onCancellationRequested(() => killTree(p.pid));
}

// Spawn `go-outline` process
Expand Down
4 changes: 2 additions & 2 deletions src/goRename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import vscode = require('vscode');
import { Edit, FilePatch, getEditsFromUnifiedDiffStr, isDiffToolAvailable } from './diffUtils';
import { promptForMissingTool } from './goInstallTools';
import { outputChannel } from './goStatus';
import { byteOffsetAt, canonicalizeGOPATHPrefix, getBinPath, getGoConfig, getToolsEnvVars, killProcess } from './util';
import { byteOffsetAt, canonicalizeGOPATHPrefix, getBinPath, getGoConfig, getToolsEnvVars, killTree } from './util';

export class GoRenameProvider implements vscode.RenameProvider {
public provideRenameEdits(
Expand Down Expand Up @@ -49,7 +49,7 @@ export class GoRenameProvider implements vscode.RenameProvider {

let p: cp.ChildProcess;
if (token) {
token.onCancellationRequested(() => killProcess(p));
token.onCancellationRequested(() => killTree(p.pid));
}

p = cp.execFile(gorename, gorenameArgs, { env }, (err, stdout, stderr) => {
Expand Down
4 changes: 2 additions & 2 deletions src/goSymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import cp = require('child_process');
import vscode = require('vscode');
import { promptForMissingTool, promptForUpdatingTool } from './goInstallTools';
import { getBinPath, getGoConfig, getToolsEnvVars, getWorkspaceFolderPath, killProcess } from './util';
import { getBinPath, getGoConfig, getToolsEnvVars, getWorkspaceFolderPath, killTree } from './util';

// Keep in sync with github.com/acroca/go-symbols'
interface GoSymbolDeclaration {
Expand Down Expand Up @@ -116,7 +116,7 @@ function callGoSymbols(args: string[], token: vscode.CancellationToken): Promise
let p: cp.ChildProcess;

if (token) {
token.onCancellationRequested(() => killProcess(p));
token.onCancellationRequested(() => killTree(p.pid));
}

return new Promise((resolve, reject) => {
Expand Down
16 changes: 0 additions & 16 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,22 +852,6 @@ export function getWorkspaceFolderPath(fileUri?: vscode.Uri): string {
}
}

export function killProcess(p: cp.ChildProcess) {
if (p) {
try {
p.kill();
} catch (e) {
console.log('Error killing process: ' + e);
if (e && e.message && e.stack) {
const matches = e.stack.match(/(src.go[a-z,A-Z]+\.js)/g);
if (matches) {
sendTelemetryEventForKillingProcess(e.message, matches);
}
}
}
}
}

export const killTree = (processId: number): void => {
kill(processId, (err) => {
if (err) {
Expand Down

0 comments on commit 16cbd97

Please sign in to comment.