Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to display Request Name as Tab Title #400

Merged
merged 5 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ exchange | Preview the whole HTTP exchange(request and response)
* `rest-client.defaultHeaders`: If particular headers are omitted in request header, these will be added as headers for each request. (Default is `{ "User-Agent": "vscode-restclient", "Accept-Encoding": "gzip" }`)
* `rest-client.timeoutinmilliseconds`: Timeout in milliseconds. 0 for infinity. (Default is __0__)
* `rest-client.showResponseInDifferentTab`: Show response in different tab. (Default is __false__)
* `rest-client.requestNameAsTabTitle`: Show request name as the tab title. (Default is __false__)
* `rest-client.rememberCookiesForSubsequentRequests`: Save cookies from `Set-Cookie` header in response and use for subsequent requests. (Default is __true__)
* `rest-client.enableTelemetry`: Send out anonymous usage data. (Default is __true__)
* `rest-client.excludeHostsForProxy`: Excluded hosts when using proxy settings. (Default is __[]__)
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@
"scope": "resource",
"description": "Show response in different tab"
},
"rest-client.requestNameAsTabTitle": {
"type": "boolean",
"default": false,
"scope": "resource",
"description": "Show request name as the tab title."
},
"rest-client.rememberCookiesForSubsequentRequests": {
"type": "boolean",
"default": true,
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/requestController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class RequestController {
if (this._restClientSettings.previewResponseInUntitledDocument) {
this._textDocumentView.render(response, previewColumn);
} else {
this._webview.render(response, previewColumn);
this._webview.render(response, httpRequest, previewColumn);
}
} catch (reason) {
this.logger.error('Unable to preview response:', reason);
Expand Down Expand Up @@ -219,4 +219,4 @@ export class RequestController {
`Body: ${filesize(response.bodySizeInBytes)}`
].join(EOL);
}
}
}
3 changes: 3 additions & 0 deletions src/models/configurationSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface IRestClientSettings {
defaultHeaders: Headers;
timeoutInMilliseconds: number;
showResponseInDifferentTab: boolean;
requestNameAsTabTitle: boolean;
proxy: string;
proxyStrictSSL: boolean;
rememberCookiesForSubsequentRequests: boolean;
Expand Down Expand Up @@ -44,6 +45,7 @@ export class RestClientSettings implements IRestClientSettings {
public defaultHeaders: Headers;
public timeoutInMilliseconds: number;
public showResponseInDifferentTab: boolean;
public requestNameAsTabTitle: boolean;
public proxy: string;
public proxyStrictSSL: boolean;
public rememberCookiesForSubsequentRequests: boolean;
Expand Down Expand Up @@ -114,6 +116,7 @@ export class RestClientSettings implements IRestClientSettings {
"Accept-Encoding": "gzip"
});
this.showResponseInDifferentTab = restClientSettings.get<boolean>("showResponseInDifferentTab", false);
this.requestNameAsTabTitle = restClientSettings.get<boolean>("requestNameAsTabTitle", false);
this.rememberCookiesForSubsequentRequests = restClientSettings.get<boolean>("rememberCookiesForSubsequentRequests", true);
this.timeoutInMilliseconds = restClientSettings.get<number>("timeoutinmilliseconds", 0);
if (this.timeoutInMilliseconds < 0) {
Expand Down
6 changes: 3 additions & 3 deletions src/views/httpResponseWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ export class HttpResponseWebview extends BaseWebview {
this.context.subscriptions.push(commands.registerCommand('rest-client.unfold-response', () => this.unfoldResponseBody()));
}

public async render(response: HttpResponse, column: ViewColumn) {
public async render(response: HttpResponse, request: HttpRequest, column: ViewColumn) {
let panel: WebviewPanel;
if (this.settings.showResponseInDifferentTab || this.panels.length === 0) {
const tabTitle = this.settings.requestNameAsTabTitle && request.requestVariableCacheKey && request.requestVariableCacheKey.key ? request.requestVariableCacheKey.key : 'Response';
panel = window.createWebviewPanel(
this.viewType,
`Response(${response.elapsedMillionSeconds}ms)`,
`${tabTitle}(${response.elapsedMillionSeconds}ms)`,
{ viewColumn: column, preserveFocus: !this.settings.previewResponsePanelTakeFocus },
{
enableFindWidget: true,
Expand Down Expand Up @@ -349,4 +350,3 @@ class FoldingRange {
public constructor(public start: number, public end: number) {
}
}