mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
server ready feature: fix #70537
This commit is contained in:
parent
79957814c2
commit
1bebb2409c
|
@ -5,6 +5,9 @@
|
||||||
|
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as util from 'util';
|
import * as util from 'util';
|
||||||
|
import * as nls from 'vscode-nls';
|
||||||
|
|
||||||
|
const localize = nls.loadMessageBundle();
|
||||||
|
|
||||||
const PATTERN = 'listening on.* (https?://\\S+|[0-9]+)'; // matches "listening on port 3000" or "Now listening on: https://localhost:5001"
|
const PATTERN = 'listening on.* (https?://\\S+|[0-9]+)'; // matches "listening on port 3000" or "Now listening on: https://localhost:5001"
|
||||||
const URI_FORMAT = 'http://localhost:%s';
|
const URI_FORMAT = 'http://localhost:%s';
|
||||||
|
@ -85,24 +88,44 @@ class ServerReadyDetector extends vscode.Disposable {
|
||||||
detectPattern(s: string): void {
|
detectPattern(s: string): void {
|
||||||
|
|
||||||
if (!this.hasFired) {
|
if (!this.hasFired) {
|
||||||
const result = this.regexp.exec(s);
|
const matches = this.regexp.exec(s);
|
||||||
if (result && result.length === 2) {
|
if (matches && matches.length >= 1) {
|
||||||
this.openExternalWithString(this.session, result[1]);
|
this.openExternalWithString(this.session, matches.length > 1 ? matches[1] : '');
|
||||||
this.hasFired = true;
|
this.hasFired = true;
|
||||||
this.internalDispose();
|
this.internalDispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private openExternalWithString(session: vscode.DebugSession, portOrUriString: string) {
|
private openExternalWithString(session: vscode.DebugSession, captureString: string) {
|
||||||
|
|
||||||
if (portOrUriString) {
|
|
||||||
if (/^[0-9]+$/.test(portOrUriString)) {
|
|
||||||
const args: ServerReadyAction = session.configuration.serverReadyAction;
|
const args: ServerReadyAction = session.configuration.serverReadyAction;
|
||||||
portOrUriString = util.format(args.uriFormat || URI_FORMAT, portOrUriString);
|
const format = args.uriFormat || URI_FORMAT;
|
||||||
|
|
||||||
|
if (captureString === '') {
|
||||||
|
// nothing captured by reg exp -> use the uriFormat as the target url without substitution
|
||||||
|
// verify that format does not contain '%s'
|
||||||
|
if (format.indexOf('%s') >= 0) {
|
||||||
|
const errMsg = localize('server.ready.nocapture.error', "Format uri ('{0}') uses a substitution placeholder but pattern did not capture anything.", format);
|
||||||
|
vscode.window.showErrorMessage(errMsg, { modal: true }).then(_ => undefined);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
this.openExternalWithUri(session, portOrUriString);
|
captureString = format;
|
||||||
|
} else if (/^[0-9]+$/.test(captureString)) {
|
||||||
|
// looks like a port number -> use the uriFormat and substitute a single "%s" with the port
|
||||||
|
// verify that format only contains a single '%s'
|
||||||
|
const s = format.split('%s');
|
||||||
|
if (s.length !== 2) {
|
||||||
|
const errMsg = localize('server.ready.placeholder.error', "Format uri ('{0}') must contain exactly one substitution placeholder.", format);
|
||||||
|
vscode.window.showErrorMessage(errMsg, { modal: true }).then(_ => undefined);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
captureString = util.format(format, captureString);
|
||||||
|
} else {
|
||||||
|
// use the string as is
|
||||||
|
}
|
||||||
|
|
||||||
|
this.openExternalWithUri(session, captureString);
|
||||||
}
|
}
|
||||||
|
|
||||||
private openExternalWithUri(session: vscode.DebugSession, uri: string) {
|
private openExternalWithUri(session: vscode.DebugSession, uri: string) {
|
||||||
|
|
Loading…
Reference in a new issue