3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import * as nls from 'vs/nls' ;
7
6
import { Disposable , IDisposable } from 'vs/base/common/lifecycle' ;
8
- import { IWorkbenchContribution } from 'vs/workbench/common/contributions' ;
7
+ import { URI } from 'vs/base/common/uri' ;
8
+ import * as nls from 'vs/nls' ;
9
+ import { IConfigurationChangeEvent , IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
10
+ import { IContextKey , IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
11
+ import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors' ;
9
12
import { Registry } from 'vs/platform/registry/common/platform' ;
13
+ import { IWorkbenchContribution } from 'vs/workbench/common/contributions' ;
10
14
import { Extensions , IViewContainersRegistry , IViewsRegistry } from 'vs/workbench/common/views' ;
11
15
import { VIEWLET_ID as debugContainerId } from 'vs/workbench/contrib/debug/common/debug' ;
12
- import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors ' ;
16
+ import { NOTEBOOK_VARIABLE_VIEW_ENABLED } from 'vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariableContextKeys ' ;
13
17
import { NotebookVariablesView } from 'vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView' ;
18
+ import { getNotebookEditorFromEditorPane } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
14
19
import { variablesViewIcon } from 'vs/workbench/contrib/notebook/browser/notebookIcons' ;
15
- import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
16
- import { IConfigurationChangeEvent , IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
17
- import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService' ;
18
20
import { NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
19
- import { getNotebookEditorFromEditorPane } from 'vs/workbench/contrib/notebook/browser/notebookBrowser ' ;
21
+ import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService ' ;
20
22
import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService' ;
21
- import { IContextKey , IContextKeyService } from 'vs/platform/contextkey/ common/contextkey ' ;
22
- import { NOTEBOOK_VARIABLE_VIEW_ENABLED } from 'vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariableContextKeys ' ;
23
+ import { INotebookService } from 'vs/workbench/contrib/notebook/ common/notebookService ' ;
24
+ import { IEditorService } from 'vs/workbench/services/editor/common/editorService ' ;
23
25
24
26
export class NotebookVariables extends Disposable implements IWorkbenchContribution {
25
27
private listeners : IDisposable [ ] = [ ] ;
@@ -33,14 +35,15 @@ export class NotebookVariables extends Disposable implements IWorkbenchContribut
33
35
@IConfigurationService private readonly configurationService : IConfigurationService ,
34
36
@IEditorService private readonly editorService : IEditorService ,
35
37
@INotebookExecutionStateService private readonly notebookExecutionStateService : INotebookExecutionStateService ,
36
- @INotebookKernelService private readonly notebookKernelService : INotebookKernelService
38
+ @INotebookKernelService private readonly notebookKernelService : INotebookKernelService ,
39
+ @INotebookService private readonly notebookDocumentService : INotebookService
37
40
) {
38
41
super ( ) ;
39
42
40
43
this . viewEnabled = NOTEBOOK_VARIABLE_VIEW_ENABLED . bindTo ( contextKeyService ) ;
41
44
42
45
this . listeners . push ( this . editorService . onDidActiveEditorChange ( ( ) => this . handleInitEvent ( ) ) ) ;
43
- this . listeners . push ( this . notebookExecutionStateService . onDidChangeExecution ( ( e ) => this . handleInitEvent ( ) ) ) ;
46
+ this . listeners . push ( this . notebookExecutionStateService . onDidChangeExecution ( ( e ) => this . handleInitEvent ( e . notebook ) ) ) ;
44
47
45
48
this . configListener = configurationService . onDidChangeConfiguration ( ( e ) => this . handleConfigChange ( e ) ) ;
46
49
}
@@ -57,21 +60,23 @@ export class NotebookVariables extends Disposable implements IWorkbenchContribut
57
60
}
58
61
}
59
62
60
- private handleInitEvent ( ) {
63
+ private handleInitEvent ( notebook ?: URI ) {
61
64
if ( this . configurationService . getValue ( NotebookSetting . notebookVariablesView )
62
- && this . editorService . activeEditorPane ?. getId ( ) === 'workbench.editor.notebook' ) {
65
+ && ( ! ! notebook || this . editorService . activeEditorPane ?. getId ( ) === 'workbench.editor.notebook' ) ) {
63
66
64
- if ( this . hasVariableProvider ( ) && ! this . initialized && this . initializeView ( ) ) {
67
+ if ( this . hasVariableProvider ( notebook ) && ! this . initialized && this . initializeView ( ) ) {
65
68
this . viewEnabled . set ( true ) ;
66
69
this . initialized = true ;
67
70
this . listeners . forEach ( listener => listener . dispose ( ) ) ;
68
71
}
69
72
}
70
73
}
71
74
72
- private hasVariableProvider ( ) {
73
- const notebookDocument = getNotebookEditorFromEditorPane ( this . editorService . activeEditorPane ) ?. getViewModel ( ) ?. notebookDocument ;
74
- return notebookDocument && this . notebookKernelService . getMatchingKernel ( notebookDocument ) . selected ?. hasVariableProvider ;
75
+ private hasVariableProvider ( notebookUri ?: URI ) {
76
+ const notebook = notebookUri ?
77
+ this . notebookDocumentService . getNotebookTextModel ( notebookUri ) :
78
+ getNotebookEditorFromEditorPane ( this . editorService . activeEditorPane ) ?. getViewModel ( ) ?. notebookDocument ;
79
+ return notebook && this . notebookKernelService . getMatchingKernel ( notebook ) . selected ?. hasVariableProvider ;
75
80
}
76
81
77
82
private initializeView ( ) {
0 commit comments