Merge pull request #162072 from microsoft/tyriar/161775

Fix free port quick fix on Windows
This commit is contained in:
Daniel Imms 2022-09-27 16:24:47 -07:00 committed by GitHub
commit 63abb75d2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 7 deletions

View file

@ -124,7 +124,7 @@ export class PtyService extends Disposable implements IPtyService {
await new Promise<string>((resolve, reject) => {
exec(`kill ${processId}`, {}, (err, stdout) => {
if (err) {
return reject(`Problem occurred when killing the process w ID: ${processId}`);
return reject(`Problem occurred when killing the process with PID: ${processId}`);
}
resolve(stdout);
});
@ -143,13 +143,13 @@ export class PtyService extends Disposable implements IPtyService {
});
const processesForPort = stdout.split('\n');
if (processesForPort.length >= 1) {
const capturePid = /LISTENING\s+(\d{3})/;
const capturePid = /LISTENING\s+(\d+)/;
const processId = processesForPort[0].match(capturePid)?.[1];
if (processId) {
await new Promise<string>((resolve, reject) => {
exec(`Taskkill /F /PID ${processId}`, {}, (err, stdout) => {
if (err) {
return reject(`Problem occurred when killing the process w ID: ${processId}`);
return reject(`Problem occurred when killing the process with PID: ${processId}`);
}
resolve(stdout);
});

View file

@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import { IAction } from 'vs/base/common/actions';
import { isWindows } from 'vs/base/common/platform';
import { localize } from 'vs/nls';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { QuickFixMatchResult, ITerminalQuickFixAction, ITerminalQuickFixOptions, ITerminalInstance } from 'vs/workbench/contrib/terminal/browser/terminal';
@ -14,7 +13,7 @@ export const GitCommandLineRegex = /git/;
export const GitPushCommandLineRegex = /git\s+push/;
export const AnyCommandLineRegex = /.+/;
export const GitSimilarOutputRegex = /most similar command is\s*([^\s]{3,})/;
export const FreePortOutputRegex = /address already in use \d\.\d\.\d\.\d:(\d\d\d\d)|Unable to bind [^ ]*:(\d+)|can't listen on port (\d+)|listen EADDRINUSE [^ ]*:(\d+)/;
export const FreePortOutputRegex = /address already in use \d+\.\d+\.\d+\.\d+:(\d{4,5})|Unable to bind [^ ]*:(\d{4,5})|can't listen on port (\d{4,5})|listen EADDRINUSE [^ ]*:(\d{4,5})/;
export const GitPushOutputRegex = /git push --set-upstream origin ([^\s]+)/;
export const GitCreatePrOutputRegex = /Create a pull request for \'([^\s]+)\' on GitHub by visiting:\s*remote:\s*(https:.+pull.+)/;
@ -50,8 +49,7 @@ export function freePort(terminalInstance?: Partial<ITerminalInstance>): ITermin
return {
quickFixLabel: (matchResult: QuickFixMatchResult) => matchResult.outputMatch ? `Free port ${matchResult.outputMatch[1]}` : '',
commandLineMatcher: AnyCommandLineRegex,
// TODO: Support free port on Windows https://github.com/microsoft/vscode/issues/161775
outputMatcher: isWindows ? undefined : {
outputMatcher: {
lineMatcher: FreePortOutputRegex,
anchor: 'bottom',
offset: 0,