@@ -47,6 +47,7 @@ import { getLoggingLevel } from './logging/settings';
4747import { DebugService } from './common/application/debugService' ;
4848import { DebugSessionEventDispatcher } from './debugger/extension/hooks/eventHandlerDispatcher' ;
4949import { IDebugSessionEventHandlers } from './debugger/extension/hooks/types' ;
50+ import { WorkspaceService } from './common/application/workspace' ;
5051
5152export async function activateComponents (
5253 // `ext` is passed to any extra activation funcs.
@@ -70,6 +71,10 @@ export async function activateComponents(
7071 // https://github.com/microsoft/vscode-python/issues/15380
7172 // These will go away eventually once everything is refactored into components.
7273 const legacyActivationResult = await activateLegacy ( ext ) ;
74+ const workspaceService = new WorkspaceService ( ) ;
75+ if ( ! workspaceService . isTrusted ) {
76+ return [ legacyActivationResult ] ;
77+ }
7378 const promises : Promise < ActivationResult > [ ] = [
7479 // More component activations will go here
7580 pythonEnvironments . activate ( components . pythonEnvs , ext ) ,
@@ -133,56 +138,64 @@ async function activateLegacy(ext: ExtensionState): Promise<ActivationResult> {
133138 const workspaceService = serviceContainer . get < IWorkspaceService > ( IWorkspaceService ) ;
134139 const cmdManager = serviceContainer . get < ICommandManager > ( ICommandManager ) ;
135140 languages . setLanguageConfiguration ( PYTHON_LANGUAGE , getLanguageConfiguration ( ) ) ;
136- const interpreterManager = serviceContainer . get < IInterpreterService > ( IInterpreterService ) ;
137- interpreterManager . initialize ( ) ;
138- if ( ! workspaceService . isVirtualWorkspace ) {
139- const handlers = serviceManager . getAll < IDebugSessionEventHandlers > ( IDebugSessionEventHandlers ) ;
140- const dispatcher = new DebugSessionEventDispatcher ( handlers , DebugService . instance , disposables ) ;
141- dispatcher . registerEventHandlers ( ) ;
141+ if ( workspaceService . isTrusted ) {
142+ const interpreterManager = serviceContainer . get < IInterpreterService > ( IInterpreterService ) ;
143+ interpreterManager . initialize ( ) ;
144+ if ( ! workspaceService . isVirtualWorkspace ) {
145+ const handlers = serviceManager . getAll < IDebugSessionEventHandlers > ( IDebugSessionEventHandlers ) ;
146+ const dispatcher = new DebugSessionEventDispatcher ( handlers , DebugService . instance , disposables ) ;
147+ dispatcher . registerEventHandlers ( ) ;
142148
143- const outputChannel = serviceManager . get < OutputChannel > ( IOutputChannel , STANDARD_OUTPUT_CHANNEL ) ;
144- disposables . push ( cmdManager . registerCommand ( Commands . ViewOutput , ( ) => outputChannel . show ( ) ) ) ;
145- cmdManager . executeCommand ( 'setContext' , 'python.vscode.channel' , applicationEnv . channel ) . then ( noop , noop ) ;
149+ const outputChannel = serviceManager . get < OutputChannel > ( IOutputChannel , STANDARD_OUTPUT_CHANNEL ) ;
150+ disposables . push ( cmdManager . registerCommand ( Commands . ViewOutput , ( ) => outputChannel . show ( ) ) ) ;
151+ cmdManager . executeCommand ( 'setContext' , 'python.vscode.channel' , applicationEnv . channel ) . then ( noop , noop ) ;
146152
147- serviceContainer . get < IApplicationDiagnostics > ( IApplicationDiagnostics ) . register ( ) ;
153+ serviceContainer . get < IApplicationDiagnostics > ( IApplicationDiagnostics ) . register ( ) ;
148154
149- serviceManager . get < ITerminalAutoActivation > ( ITerminalAutoActivation ) . register ( ) ;
150- const pythonSettings = configuration . getSettings ( ) ;
155+ serviceManager . get < ITerminalAutoActivation > ( ITerminalAutoActivation ) . register ( ) ;
156+ const pythonSettings = configuration . getSettings ( ) ;
151157
152- const sortImports = serviceContainer . get < ISortImportsEditingProvider > ( ISortImportsEditingProvider ) ;
153- sortImports . registerCommands ( ) ;
158+ const sortImports = serviceContainer . get < ISortImportsEditingProvider > ( ISortImportsEditingProvider ) ;
159+ sortImports . registerCommands ( ) ;
154160
155- serviceManager . get < ICodeExecutionManager > ( ICodeExecutionManager ) . registerCommands ( ) ;
161+ serviceManager . get < ICodeExecutionManager > ( ICodeExecutionManager ) . registerCommands ( ) ;
156162
157- context . subscriptions . push ( new LinterCommands ( serviceManager ) ) ;
163+ context . subscriptions . push ( new LinterCommands ( serviceManager ) ) ;
158164
159- if ( pythonSettings && pythonSettings . formatting && pythonSettings . formatting . provider !== 'internalConsole' ) {
160- const formatProvider = new PythonFormattingEditProvider ( context , serviceContainer ) ;
161- context . subscriptions . push ( languages . registerDocumentFormattingEditProvider ( PYTHON , formatProvider ) ) ;
162- context . subscriptions . push ( languages . registerDocumentRangeFormattingEditProvider ( PYTHON , formatProvider ) ) ;
163- }
165+ if (
166+ pythonSettings &&
167+ pythonSettings . formatting &&
168+ pythonSettings . formatting . provider !== 'internalConsole'
169+ ) {
170+ const formatProvider = new PythonFormattingEditProvider ( context , serviceContainer ) ;
171+ context . subscriptions . push ( languages . registerDocumentFormattingEditProvider ( PYTHON , formatProvider ) ) ;
172+ context . subscriptions . push (
173+ languages . registerDocumentRangeFormattingEditProvider ( PYTHON , formatProvider ) ,
174+ ) ;
175+ }
164176
165- context . subscriptions . push ( new ReplProvider ( serviceContainer ) ) ;
177+ context . subscriptions . push ( new ReplProvider ( serviceContainer ) ) ;
166178
167- const terminalProvider = new TerminalProvider ( serviceContainer ) ;
168- terminalProvider . initialize ( window . activeTerminal ) . ignoreErrors ( ) ;
169- context . subscriptions . push ( terminalProvider ) ;
179+ const terminalProvider = new TerminalProvider ( serviceContainer ) ;
180+ terminalProvider . initialize ( window . activeTerminal ) . ignoreErrors ( ) ;
181+ context . subscriptions . push ( terminalProvider ) ;
170182
171- context . subscriptions . push (
172- languages . registerCodeActionsProvider ( PYTHON , new PythonCodeActionProvider ( ) , {
173- providedCodeActionKinds : [ CodeActionKind . SourceOrganizeImports ] ,
174- } ) ,
175- ) ;
183+ context . subscriptions . push (
184+ languages . registerCodeActionsProvider ( PYTHON , new PythonCodeActionProvider ( ) , {
185+ providedCodeActionKinds : [ CodeActionKind . SourceOrganizeImports ] ,
186+ } ) ,
187+ ) ;
176188
177- serviceContainer
178- . getAll < DebugConfigurationProvider > ( IDebugConfigurationService )
179- . forEach ( ( debugConfigProvider ) => {
180- context . subscriptions . push (
181- debug . registerDebugConfigurationProvider ( DebuggerTypeName , debugConfigProvider ) ,
182- ) ;
183- } ) ;
189+ serviceContainer
190+ . getAll < DebugConfigurationProvider > ( IDebugConfigurationService )
191+ . forEach ( ( debugConfigProvider ) => {
192+ context . subscriptions . push (
193+ debug . registerDebugConfigurationProvider ( DebuggerTypeName , debugConfigProvider ) ,
194+ ) ;
195+ } ) ;
184196
185- serviceContainer . get < IDebuggerBanner > ( IDebuggerBanner ) . initialize ( ) ;
197+ serviceContainer . get < IDebuggerBanner > ( IDebuggerBanner ) . initialize ( ) ;
198+ }
186199 }
187200
188201 // "activate" everything else
0 commit comments