11"use strict" ;
22
3- import { window , workspace , commands , Uri , StatusBarItem , StatusBarAlignment , ViewColumn , Disposable , TextDocument , Range } from 'vscode' ;
3+ import { window , Uri , StatusBarItem , StatusBarAlignment , Range } from 'vscode' ;
44import { ArrayUtility } from "../common/arrayUtility" ;
55import { RequestParserFactory } from '../models/requestParserFactory' ;
66import { HttpClient } from '../httpClient' ;
@@ -9,7 +9,6 @@ import { HttpResponse } from '../models/httpResponse';
99import { SerializedHttpRequest } from '../models/httpRequest' ;
1010import { RestClientSettings } from '../models/configurationSettings' ;
1111import { PersistUtility } from '../persistUtility' ;
12- import { HttpResponseTextDocumentContentProvider } from '../views/httpResponseTextDocumentContentProvider' ;
1312import { UntitledFileContentProvider } from '../views/responseUntitledFileContentProvider' ;
1413import { trace } from "../decorator" ;
1514import { VariableProcessor } from '../variableProcessor' ;
@@ -20,6 +19,7 @@ import * as Constants from '../constants';
2019import { RequestVariableCacheKey } from "../models/requestVariableCacheKey" ;
2120import { RequestVariableCache } from "../requestVariableCache" ;
2221import { RequestVariableCacheValue } from "../models/requestVariableCacheValue" ;
22+ import { HttpResponseWebview } from '../views/httpResponseWebview' ;
2323
2424import { EOL } from 'os' ;
2525
@@ -35,20 +35,19 @@ export class RequestController {
3535 private _sizeStatusBarItem : StatusBarItem ;
3636 private _restClientSettings : RestClientSettings ;
3737 private _httpClient : HttpClient ;
38- private _responseTextProvider : HttpResponseTextDocumentContentProvider ;
39- private _registration : Disposable ;
4038 private _interval : NodeJS . Timer ;
39+ private _webview : HttpResponseWebview ;
4140
4241 public constructor ( ) {
4342 this . _durationStatusBarItem = window . createStatusBarItem ( StatusBarAlignment . Left ) ;
4443 this . _sizeStatusBarItem = window . createStatusBarItem ( StatusBarAlignment . Left ) ;
4544 this . _restClientSettings = new RestClientSettings ( ) ;
4645 this . _httpClient = new HttpClient ( this . _restClientSettings ) ;
47-
48- this . _responseTextProvider = new HttpResponseTextDocumentContentProvider ( this . _restClientSettings ) ;
49- this . _registration = workspace . registerTextDocumentContentProvider ( 'rest-response' , this . _responseTextProvider ) ;
50-
51- workspace . onDidCloseTextDocument ( ( params ) => this . onDidCloseTextDocument ( params ) ) ;
46+ this . _webview = new HttpResponseWebview ( this . _restClientSettings ) ;
47+ this . _webview . onDidCloseAllWebviewPanels ( ( ) => {
48+ this . _durationStatusBarItem . hide ( ) ;
49+ this . _sizeStatusBarItem . hide ( ) ;
50+ } ) ;
5251 }
5352
5453 @trace ( 'Request' )
@@ -150,8 +149,6 @@ export class RequestController {
150149 RequestVariableCache . add ( httpRequest . requestVariableCacheKey , new RequestVariableCacheValue ( httpRequest , response ) ) ;
151150 }
152151
153- this . _responseTextProvider . update ( previewUri ) ;
154-
155152 try {
156153 if ( this . _restClientSettings . previewResponseInUntitledDocument ) {
157154 UntitledFileContentProvider . createHttpResponseUntitledFile (
@@ -163,8 +160,7 @@ export class RequestController {
163160 this . _restClientSettings . previewResponseInActiveColumn
164161 ) ;
165162 } else {
166- const column = this . _restClientSettings . previewResponseInActiveColumn ? ViewColumn . Active : ViewColumn . Two ;
167- await commands . executeCommand ( 'vscode.previewHtml' , previewUri , column , `Response(${ response . elapsedMillionSeconds } ms)` ) ;
163+ this . _webview . render ( response ) ;
168164 }
169165 } catch ( reason ) {
170166 window . showErrorMessage ( reason ) ;
@@ -198,7 +194,7 @@ export class RequestController {
198194 public dispose ( ) {
199195 this . _durationStatusBarItem . dispose ( ) ;
200196 this . _sizeStatusBarItem . dispose ( ) ;
201- this . _registration . dispose ( ) ;
197+ this . _webview . dispose ( ) ;
202198 }
203199
204200 private generatePreviewUri ( ) : Uri {
@@ -224,18 +220,6 @@ export class RequestController {
224220 this . _sizeStatusBarItem . hide ( ) ;
225221 }
226222
227- private onDidCloseTextDocument ( doc : TextDocument ) : void {
228- // Remove the status bar associated with the response preview uri
229- if ( this . _restClientSettings . showResponseInDifferentTab ) {
230- return ;
231- }
232-
233- if ( ResponseStore . get ( doc . uri . toString ( ) ) ) {
234- this . _durationStatusBarItem . hide ( ) ;
235- this . _sizeStatusBarItem . hide ( ) ;
236- }
237- }
238-
239223 private formatDurationStatusBar ( response : HttpResponse ) {
240224 this . _durationStatusBarItem . command = null ;
241225 this . _durationStatusBarItem . text = ` $(clock) ${ response . elapsedMillionSeconds } ms` ;
0 commit comments