import * as vscode from 'vscode' ; description export interface LiveServerConfigItem { portNumber : number ; showStatusBarItem : boolean ; showServerStatusNotifications : boolean ; autoRefreshPreview : AutoRefreshPreview ; browserPreviewLaunchServerLogging : boolean ; openPreviewTarget : OpenPreviewTarget ; serverKeepAliveAfterEmbeddedPreviewClose : number ; notifyOnOpenLooseFile : boolean ; runTaskWithExternalPreview : boolean ; defaultPreviewPath : string ; debugOnExternalPreview : boolean ; hostIP : string ; } description export enum AutoRefreshPreview { onAnyChange = 'On All Changes in Editor' , onSave = 'On Changes to Saved Files' , never = 'Never' } description export enum OpenPreviewTarget { embeddedPreview = 'Embedded Preview' , externalBrowser = 'External Browser' } description export const SETTINGS_SECTION_ID = 'livePreview' ; description export const Settings = { portNumber : 'portNumber' , showStatusBarItem : 'showStatusBarItem' , showServerStatusNotifications : 'showServerStatusNotifications' , autoRefreshPreview : 'autoRefreshPreview' , browserPreviewLaunchServerLogging : 'tasks.browserPreviewLaunchServerLogging' , openPreviewTarget : 'openPreviewTarget' , serverKeepAliveAfterEmbeddedPreviewClose : 'serverKeepAliveAfterEmbeddedPreviewClose' , notifyOnOpenLooseFile : 'notifyOnOpenLooseFile' , runTaskWithExternalPreview : 'tasks.runTaskWithExternalPreview' , defaultPreviewPath : 'defaultPreviewPath' , debugOnExternalPreview : 'debugOnExternalPreview' , hostIP : 'hostIP' , } ; description export const PreviewType = { internalPreview : 'internalPreview' , externalPreview : 'externalPreview' , externalDebugPreview : 'externalDebugPreview' , } ; export class SettingUtil { description param { vscode . Uri } extensionUri returns { LiveServerConfigItem } public static GetConfig ( extensionUri ) { const config = vscode . workspace . getConfiguration ( SETTINGS_SECTION_ID , extensionUri ) ; return { portNumber : config . get < number > ( Settings . portNumber , 3000 ) , showStatusBarItem : config . get < boolean > ( Settings . showStatusBarItem , true ) , showServerStatusNotifications : config . get < boolean > ( Settings . showServerStatusNotifications , false ) , autoRefreshPreview : config . get < AutoRefreshPreview > ( Settings . autoRefreshPreview , AutoRefreshPreview . onAnyChange ) , browserPreviewLaunchServerLogging : config . get < boolean > ( Settings . browserPreviewLaunchServerLogging , true ) , openPreviewTarget : config . get < OpenPreviewTarget > ( Settings . openPreviewTarget , OpenPreviewTarget . embeddedPreview ) , serverKeepAliveAfterEmbeddedPreviewClose : config . get < number > ( Settings . serverKeepAliveAfterEmbeddedPreviewClose , 20 ) , notifyOnOpenLooseFile : config . get < boolean > ( Settings . notifyOnOpenLooseFile , true ) , runTaskWithExternalPreview : config . get < boolean > ( Settings . runTaskWithExternalPreview , true ) , defaultPreviewPath : config . get < string > ( Settings . defaultPreviewPath , '' ) , debugOnExternalPreview : config . get < boolean > ( Settings . debugOnExternalPreview , false ) , hostIP : config . get < string > ( Settings . hostIP , '127.0.0.1' ) , } ; } description param { vscode . Uri } extensionUri returns { string } public static GetPreviewType ( extensionUri ) { if ( SettingUtil . GetConfig ( extensionUri ) . openPreviewTarget == OpenPreviewTarget . embeddedPreview ) { return PreviewType . internalPreview ; } else { return SettingUtil . GetExternalPreviewType ( extensionUri ) ; } } public static GetExternalPreviewType ( extensionUri ) { if ( SettingUtil . GetConfig ( extensionUri ) . debugOnExternalPreview ) { return PreviewType . externalDebugPreview ; } else { return PreviewType . externalPreview ; } } description param { string } settingSuffix param { T } value param { boolean } isGlobal public static UpdateSettings < T > ( settingSuffix , value , isGlobal = true ) { vscode . workspace . getConfiguration ( SETTINGS_SECTION_ID ) . update ( settingSuffix , value , isGlobal ) ; } }