import { workspace , ExtensionContext , WorkspaceFolder , window } from 'vscode' ; import { getWorkspaceFolder , isProperSubpathOf } from './utils/workspace-util' ; import { WorkspaceContext } from './workspace' ; export function activate ( context ) { let workspaceRoot = getWorkspaceFolder ( workspace . workspaceFolders as WorkspaceFolder [ ] , window . activeTextEditor ) ; const workspaceContext = new WorkspaceContext ( context , workspaceRoot ) ; workspaceContext . registerCommands ( ) ; /**
     * detect when active editor changes and the workspace too
     */ const activeTextEditorWorkspaceChangesRegistration = window . onDidChangeActiveTextEditor ( ( editor ) => { if ( editor ?. document . uri ) { const newWorkspaceRoot = getWorkspaceFolder ( [ workspace . getWorkspaceFolder ( editor . document . uri ) ] as WorkspaceFolder [ ] , window . activeTextEditor ) ; if ( workspaceContext . workspaceRoot === newWorkspaceRoot ) { return ; } if ( isProperSubpathOf ( newWorkspaceRoot , workspaceContext . workspaceRoot ) ) { return ; } workspaceContext . workspaceRoot = newWorkspaceRoot ; workspaceContext . refreshCommands ( ) ; } } ) ; context . subscriptions . push ( activeTextEditorWorkspaceChangesRegistration ) ; } export function deactivate ( ) { }