Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/env/common/envService.ts
13401 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import type { Event, WindowState } from 'vscode';
7
import { createServiceIdentifier } from '../../../util/common/services';
8
import { env } from '../../../util/vs/base/common/process';
9
import { URI } from '../../../util/vs/base/common/uri';
10
import { isPreRelease, isProduction, packageJson } from './packagejson';
11
12
export enum OperatingSystem {
13
Windows = 'Windows',
14
Macintosh = 'Mac',
15
Linux = 'Linux'
16
}
17
18
19
export class NameAndVersion {
20
constructor(
21
readonly name: string,
22
readonly version: string
23
) { }
24
25
format(): string {
26
return `${this.name}/${this.version}`;
27
}
28
}
29
30
31
export const IEnvService = createServiceIdentifier<IEnvService>('IEnvService');
32
33
export interface IEnvService {
34
readonly _serviceBrand: undefined;
35
readonly language: string | undefined;
36
readonly sessionId: string;
37
readonly machineId: string;
38
readonly devDeviceId: string;
39
readonly vscodeVersion: string;
40
/**
41
* Whether the current session is considered active
42
* @see vscode.window.state.active
43
*/
44
readonly isActive: boolean;
45
/**
46
* @see vscode.env.remoteName
47
*/
48
readonly remoteName: string | undefined;
49
readonly uiKind: 'desktop' | 'web';
50
readonly OS: OperatingSystem;
51
readonly uriScheme: string;
52
readonly extensionId: string;
53
readonly appRoot: string;
54
readonly shell: string;
55
/**
56
* @see vscode.window.onDidChangeWindowState
57
*/
58
readonly onDidChangeWindowState: Event<WindowState>;
59
isProduction(): boolean;
60
isPreRelease(): boolean;
61
isSimulation(): boolean;
62
getBuildType(): 'prod' | 'dev';
63
getVersion(): string;
64
getBuild(): string;
65
getName(): string;
66
getEditorInfo(): NameAndVersion;
67
getEditorPluginInfo(): NameAndVersion;
68
openExternal(target: URI): Promise<boolean>;
69
}
70
71
export const INativeEnvService = createServiceIdentifier<INativeEnvService>('INativeEnvService');
72
export interface INativeEnvService extends IEnvService {
73
readonly _serviceBrand: undefined;
74
userHome: URI;
75
}
76
77
export abstract class AbstractEnvService implements IEnvService {
78
language: string | undefined;
79
declare _serviceBrand: undefined;
80
81
abstract get sessionId(): string;
82
abstract get vscodeVersion(): string;
83
abstract get extensionId(): string;
84
abstract get machineId(): string;
85
abstract get devDeviceId(): string;
86
abstract get remoteName(): string | undefined;
87
abstract get uiKind(): 'desktop' | 'web';
88
abstract get OS(): OperatingSystem;
89
abstract get uriScheme(): string;
90
abstract get appRoot(): string;
91
abstract get shell(): string;
92
abstract get isActive(): boolean;
93
abstract get onDidChangeWindowState(): Event<WindowState>;
94
95
/**
96
* @returns true if this is a build for end users.
97
*/
98
isProduction(): boolean {
99
return isProduction;
100
}
101
102
isPreRelease(): boolean {
103
return isPreRelease;
104
}
105
106
isSimulation(): boolean {
107
return env['SIMULATION'] === '1';
108
}
109
110
getBuildType(): 'prod' | 'dev' {
111
return packageJson.buildType;
112
}
113
114
getVersion(): string {
115
return packageJson.version;
116
}
117
118
getBuild(): string {
119
return packageJson.build;
120
}
121
122
getName(): string {
123
return packageJson.name;
124
}
125
126
/**
127
* The name and version of the editor itself.
128
* `{ name : 'vscode', version: '1.63.2' }`.
129
*/
130
abstract getEditorInfo(): NameAndVersion;
131
132
/**
133
* The name and version of the Copilot chat plugin.
134
* or `{ name: 'copilot-chat', version: '1.7.21' }`.
135
*/
136
abstract getEditorPluginInfo(): NameAndVersion;
137
138
getEditorVersionHeaders(): { [key: string]: string } {
139
return {
140
'Editor-Version': this.getEditorInfo().format(),
141
'Editor-Plugin-Version': this.getEditorPluginInfo().format(),
142
};
143
}
144
145
abstract openExternal(target: URI): Promise<boolean>;
146
}
147
148
// FIXME: This needs to be used in locations where the EnvService is not yet available, so it's
149
// not part of the env service itself.
150
export const isScenarioAutomation = env['IS_SCENARIO_AUTOMATION'] === '1';
151