1515 * limitations under the License.
1616 */
1717
18- import * as vscode from 'vscode' ;
1918import * as extensionFunctions from './extensionFunctions' ;
2019import * as path from 'path' ;
21- import { ViewColumn } from 'vscode' ;
20+ import { ViewColumn , WebviewPanel , Disposable , Uri , workspace , window , ExtensionContext , extensions } from 'vscode' ;
2221import { DIDACT_DEFAULT_URL } from './utils' ;
2322import { DEFAULT_TITLE_VALUE , didactManager , VIEW_TYPE } from './didactManager' ;
2423import * as commandHandler from './commandHandler' ;
2524
2625export class DidactPanel {
2726
2827 // public for testing purposes
29- public _panel : vscode . WebviewPanel | undefined ;
28+ public _panel : WebviewPanel | undefined ;
3029
31- private _disposables : vscode . Disposable [ ] = [ ] ;
30+ private _disposables : Disposable [ ] = [ ] ;
3231 private currentHtml : string | undefined = undefined ;
33- private didactUriPath : vscode . Uri | undefined = undefined ;
32+ private didactUriPath : Uri | undefined = undefined ;
3433 private defaultTitle = DEFAULT_TITLE_VALUE ;
3534 private isAsciiDoc = false ;
3635 private _disposed = false ;
3736 public visible = false ;
3837
39- public constructor ( uri ?: vscode . Uri ) {
38+ public constructor ( uri ?: Uri ) {
4039 this . didactUriPath = uri ;
4140 didactManager . add ( this ) ;
4241 }
4342
44- public initWebviewPanel ( viewColumn : ViewColumn , inpath ?: vscode . Uri | undefined ) : DidactPanel | undefined {
43+ public initWebviewPanel ( viewColumn : ViewColumn , inpath ?: Uri | undefined ) : DidactPanel | undefined {
4544 const extPath = didactManager . getExtensionPath ( ) ;
4645 if ( ! extPath ) {
4746 console . error ( `Error: Extension context not set on Didact manager` ) ;
4847 return undefined ;
4948 }
5049
5150 // Otherwise, create a new panel.
52- const localResourceRoots = [ vscode . Uri . file ( path . resolve ( extPath , 'media' ) ) ] ;
51+ const localResourceRoots = [ Uri . file ( path . resolve ( extPath , 'media' ) ) ] ;
5352 if ( inpath ) {
5453 const dirName = path . dirname ( inpath . fsPath ) ;
55- localResourceRoots . push ( vscode . Uri . file ( dirName ) ) ;
54+ localResourceRoots . push ( Uri . file ( dirName ) ) ;
5655 }
5756
58- const localIconPath = vscode . Uri . file ( path . resolve ( extPath , 'icon/logo.svg' ) ) ;
57+ const localIconPath = Uri . file ( path . resolve ( extPath , 'icon/logo.svg' ) ) ;
5958 const iconDirPath = path . dirname ( localIconPath . fsPath ) ;
60- localResourceRoots . push ( vscode . Uri . file ( iconDirPath ) ) ;
59+ localResourceRoots . push ( Uri . file ( iconDirPath ) ) ;
6160
62- const panel = vscode . window . createWebviewPanel (
61+ const panel = window . createWebviewPanel (
6362 VIEW_TYPE , this . defaultTitle , viewColumn ,
6463 {
6564 // Enable javascript in the webview
@@ -77,7 +76,7 @@ export class DidactPanel {
7776 return this . attachWebviewPanel ( panel ) ;
7877 }
7978
80- public attachWebviewPanel ( webviewPanel : vscode . WebviewPanel ) : DidactPanel {
79+ public attachWebviewPanel ( webviewPanel : WebviewPanel ) : DidactPanel {
8180 this . _panel = webviewPanel ;
8281 this . setVisible ( webviewPanel . active ) ;
8382 this . _panel . onDidDispose ( ( ) => {
@@ -91,12 +90,12 @@ export class DidactPanel {
9190 this . visible = flag ;
9291 }
9392
94- public static revive ( context : vscode . ExtensionContext , webviewPanel : vscode . WebviewPanel , oldBody ? : string , oldUri ? : string ) : DidactPanel {
93+ public static revive ( context : ExtensionContext , webviewPanel : WebviewPanel , oldBody ? : string , oldUri ? : string ) : DidactPanel {
9594 didactManager . setContext ( context ) ;
9695
9796 let panel : DidactPanel ;
9897 if ( oldUri ) {
99- const toUri = vscode . Uri . parse ( oldUri ) ;
98+ const toUri = Uri . parse ( oldUri ) ;
10099 panel = new DidactPanel ( toUri ) ;
101100 } else {
102101 panel = new DidactPanel ( ) ;
@@ -125,7 +124,7 @@ export class DidactPanel {
125124 try {
126125 await commandHandler . processInputs ( message . text , didactManager . getExtensionPath ( ) ) ;
127126 } catch ( error ) {
128- vscode . window . showErrorMessage ( `Didact was unable to call commands: ${ message . text } : ${ error } ` ) ;
127+ window . showErrorMessage ( `Didact was unable to call commands: ${ message . text } : ${ error } ` ) ;
129128 }
130129 }
131130 return ;
@@ -182,7 +181,7 @@ export class DidactPanel {
182181 return this . _panel ?. title ;
183182 }
184183
185- public getDidactUriPath ( ) : vscode . Uri | undefined {
184+ public getDidactUriPath ( ) : Uri | undefined {
186185 return this . didactUriPath ;
187186 }
188187
@@ -195,7 +194,7 @@ export class DidactPanel {
195194 return this . defaultTitle ;
196195 }
197196
198- public setDidactUriPath ( inpath : vscode . Uri | undefined ) : void {
197+ public setDidactUriPath ( inpath : Uri | undefined ) : void {
199198 this . didactUriPath = inpath ;
200199 if ( inpath ) {
201200 const tempFilename = path . basename ( inpath . fsPath ) ;
@@ -231,13 +230,13 @@ export class DidactPanel {
231230 const nonce = this . getNonce ( ) ;
232231
233232 // Base uri to support images
234- const didactUri : vscode . Uri = this . didactUriPath as vscode . Uri ;
233+ const didactUri : Uri = this . didactUriPath as Uri ;
235234
236235 let uriBaseHref = undefined ;
237236 if ( didactUri && this . _panel ) {
238237 try {
239238 const didactUriPath = path . dirname ( didactUri . fsPath ) ;
240- const uriBase = this . _panel . webview . asWebviewUri ( vscode . Uri . file ( didactUriPath ) ) . toString ( ) ;
239+ const uriBase = this . _panel . webview . asWebviewUri ( Uri . file ( didactUriPath ) ) . toString ( ) ;
241240 uriBaseHref = `<base href="${ uriBase } ${ uriBase . endsWith ( '/' ) ? '' : '/' } "/>` ;
242241 } catch ( error ) {
243242 console . error ( error ) ;
@@ -251,15 +250,15 @@ export class DidactPanel {
251250 }
252251
253252 // Local path to main script run in the webview
254- const scriptPathOnDisk = vscode . Uri . file (
253+ const scriptPathOnDisk = Uri . file (
255254 path . resolve ( extPath , 'media' , 'main.js' )
256255 ) ;
257256
258257 // And the uri we use to load this script in the webview
259258 const scriptUri = scriptPathOnDisk . with ( { scheme : 'vscode-resource' } ) ;
260259
261260 // the cssUri is our path to the stylesheet included in the security policy
262- const cssPathOnDisk = vscode . Uri . file (
261+ const cssPathOnDisk = Uri . file (
263262 path . resolve ( extPath , 'media' , 'webviewslim.css' )
264263 ) ;
265264 const cssUri = cssPathOnDisk . with ( { scheme : 'vscode-resource' } ) ;
@@ -270,7 +269,7 @@ export class DidactPanel {
270269 // process the stylesheet details for asciidoc or markdown-based didact files
271270 const stylesheetHtml = this . produceStylesheetHTML ( cssUriHtml ) ;
272271
273- const extensionHandle = vscode . extensions . getExtension ( extensionFunctions . EXTENSION_ID ) ;
272+ const extensionHandle = extensions . getExtension ( extensionFunctions . EXTENSION_ID ) ;
274273 let didactVersionLabel = 'Didact' ;
275274 if ( extensionHandle ) {
276275 const didactVersion = extensionHandle . packageJSON . version ;
@@ -294,7 +293,7 @@ export class DidactPanel {
294293 metaHeader += `\n${ uriBaseHref } \n` ;
295294 }
296295
297- const completedHtml = `<!DOCTYPE html>
296+ return `<!DOCTYPE html>
298297 <html lang="en">
299298 <head>
300299 ${ metaHeader }
@@ -310,8 +309,6 @@ export class DidactPanel {
310309 <script nonce="${ nonce } " src="${ scriptUri } "/>
311310 </body>
312311 </html>` ;
313-
314- return completedHtml ;
315312 }
316313
317314 produceStylesheetHTML ( cssUriHtml : string ) : string {
@@ -372,7 +369,7 @@ export class DidactPanel {
372369 return undefined ;
373370 }
374371
375- getColumn ( ) : vscode . ViewColumn | undefined {
372+ getColumn ( ) : ViewColumn | undefined {
376373 if ( this . _panel ) {
377374 return this . _panel . viewColumn ;
378375 }
@@ -417,9 +414,9 @@ export class DidactPanel {
417414 }
418415
419416 public hardReset ( ) : void {
420- const configuredUri : string | undefined = vscode . workspace . getConfiguration ( ) . get ( DIDACT_DEFAULT_URL ) ;
417+ const configuredUri : string | undefined = workspace . getConfiguration ( ) . get ( DIDACT_DEFAULT_URL ) ;
421418 if ( configuredUri ) {
422- const defaultUri = vscode . Uri . parse ( configuredUri ) ;
419+ const defaultUri = Uri . parse ( configuredUri ) ;
423420 didactManager . active ( ) ?. setDidactUriPath ( defaultUri ) ;
424421 }
425422 didactManager . active ( ) ?. _update ( true ) ;
0 commit comments