3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { Schemas } from 'vs/base/common/network' ;
7
6
import { URI } from 'vs/base/common/uri' ;
7
+ import { Event } from 'vs/base/common/event' ;
8
+ import { ITextModel } from 'vs/editor/common/model' ;
9
+ import { IModelService } from 'vs/editor/common/services/model' ;
10
+ import { ITextModelContentProvider , ITextModelService } from 'vs/editor/common/services/resolverService' ;
8
11
import { localize } from 'vs/nls' ;
12
+ import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
9
13
import { EnvironmentVariableMutatorType , EnvironmentVariableScope , IEnvironmentVariableMutator , IMergedEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable' ;
10
14
import { registerActiveInstanceAction } from 'vs/workbench/contrib/terminal/browser/terminalActions' ;
11
15
import { TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal' ;
@@ -16,17 +20,27 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
16
20
registerActiveInstanceAction ( {
17
21
id : TerminalCommandId . ShowEnvironmentContributions ,
18
22
title : { value : localize ( 'workbench.action.terminal.showEnvironmentContributions' , "Show Environment Contributions" ) , original : 'Show Environment Contributions' } ,
19
- run : async ( activeInstance , c , accessor , scope ) => {
23
+ run : async ( activeInstance , c , accessor , arg ) => {
20
24
const collection = activeInstance . extEnvironmentVariableCollection ;
21
25
if ( collection ) {
26
+ const scope = arg as EnvironmentVariableScope | undefined ;
27
+ const instantiationService = accessor . get ( IInstantiationService ) ;
28
+ const outputProvider = instantiationService . createInstance ( EnvironmentCollectionProvider ) ;
22
29
const editorService = accessor . get ( IEditorService ) ;
23
- await editorService . openEditor ( {
24
- resource : URI . from ( {
25
- scheme : Schemas . untitled
26
- } ) ,
27
- contents : describeEnvironmentChanges ( collection , scope as EnvironmentVariableScope | undefined ) ,
28
- languageId : 'markdown'
29
- } ) ;
30
+ const timestamp = new Date ( ) . getTime ( ) ;
31
+ const scopeDesc = scope ?. workspaceFolder ? ` - ${ scope . workspaceFolder . name } ` : '' ;
32
+ const textContent = await outputProvider . provideTextContent ( URI . from (
33
+ {
34
+ scheme : EnvironmentCollectionProvider . scheme ,
35
+ path : `Environment changes${ scopeDesc } ` ,
36
+ fragment : describeEnvironmentChanges ( collection , scope ) ,
37
+ query : `environment-collection-${ timestamp } `
38
+ } ) ) ;
39
+ if ( textContent ) {
40
+ await editorService . openEditor ( {
41
+ resource : textContent . uri
42
+ } ) ;
43
+ }
30
44
}
31
45
}
32
46
} ) ;
@@ -68,3 +82,23 @@ function mutatorTypeLabel(type: EnvironmentVariableMutatorType, value: string, v
68
82
default : return `${ variable } =${ value } ` ;
69
83
}
70
84
}
85
+
86
+ class EnvironmentCollectionProvider implements ITextModelContentProvider {
87
+ static scheme = 'ENVIRONMENT_CHANGES_COLLECTION' ;
88
+
89
+ constructor (
90
+ @ITextModelService textModelResolverService : ITextModelService ,
91
+ @IModelService private readonly _modelService : IModelService
92
+ ) {
93
+ textModelResolverService . registerTextModelContentProvider ( EnvironmentCollectionProvider . scheme , this ) ;
94
+ }
95
+
96
+ async provideTextContent ( resource : URI ) : Promise < ITextModel | null > {
97
+ const existing = this . _modelService . getModel ( resource ) ;
98
+ if ( existing && ! existing . isDisposed ( ) ) {
99
+ return existing ;
100
+ }
101
+
102
+ return this . _modelService . createModel ( resource . fragment , { languageId : 'markdown' , onDidChange : Event . None } , resource , false ) ;
103
+ }
104
+ }
0 commit comments