Skip to content

Commit 0dc7369

Browse files
author
Kartik Raj
committed
Use readonly editor instead of an untitled buffer when showing environment changes
1 parent 14a24d5 commit 0dc7369

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

src/vs/workbench/contrib/terminalContrib/environmentChanges/browser/terminal.environmentChanges.contribution.ts

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { Schemas } from 'vs/base/common/network';
76
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';
811
import { localize } from 'vs/nls';
12+
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
913
import { EnvironmentVariableMutatorType, EnvironmentVariableScope, IEnvironmentVariableMutator, IMergedEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable';
1014
import { registerActiveInstanceAction } from 'vs/workbench/contrib/terminal/browser/terminalActions';
1115
import { TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal';
@@ -16,17 +20,27 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
1620
registerActiveInstanceAction({
1721
id: TerminalCommandId.ShowEnvironmentContributions,
1822
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) => {
2024
const collection = activeInstance.extEnvironmentVariableCollection;
2125
if (collection) {
26+
const scope = arg as EnvironmentVariableScope | undefined;
27+
const instantiationService = accessor.get(IInstantiationService);
28+
const outputProvider = instantiationService.createInstance(EnvironmentCollectionProvider);
2229
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+
}
3044
}
3145
}
3246
});
@@ -68,3 +82,23 @@ function mutatorTypeLabel(type: EnvironmentVariableMutatorType, value: string, v
6882
default: return `${variable}=${value}`;
6983
}
7084
}
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

Comments
 (0)