api - add vscode.env.language
This commit is contained in:
parent
2e68641c84
commit
ee249f86bd
5 changed files with 49 additions and 10 deletions
25
extensions/vscode-api-tests/src/env.test.ts
Normal file
25
extensions/vscode-api-tests/src/env.test.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import {env} from 'vscode';
|
||||
|
||||
suite('env-namespace', () => {
|
||||
|
||||
test('env is set', function() {
|
||||
assert.equal(typeof env.language, 'string');
|
||||
assert.equal(typeof env.machineId, 'string');
|
||||
assert.equal(typeof env.sessionId, 'string');
|
||||
});
|
||||
|
||||
test('env is readonly', function() {
|
||||
assert.throws(() => env.language = '234');
|
||||
assert.throws(() => env.machineId = '234');
|
||||
assert.throws(() => env.sessionId = '234');
|
||||
});
|
||||
|
||||
});
|
|
@ -91,6 +91,8 @@ export interface IConfiguration {
|
|||
}
|
||||
|
||||
export interface IEnvironment {
|
||||
language: string;
|
||||
|
||||
appName: string;
|
||||
appRoot: string;
|
||||
isBuilt: boolean;
|
||||
|
|
11
src/vs/vscode.d.ts
vendored
11
src/vs/vscode.d.ts
vendored
|
@ -2687,14 +2687,25 @@ declare namespace vscode {
|
|||
*/
|
||||
export namespace env {
|
||||
|
||||
/**
|
||||
* Represents the preferred user-language, like `de-CH`, `fr`, or `en-US`.
|
||||
*
|
||||
* @readonly
|
||||
*/
|
||||
export let language: string;
|
||||
|
||||
/**
|
||||
* A unique identifier for the computer.
|
||||
*
|
||||
* @readonly
|
||||
*/
|
||||
export let machineId: string;
|
||||
|
||||
/**
|
||||
* A unique identifier for the current session.
|
||||
* Changes each time the editor is started.
|
||||
*
|
||||
* @readonly
|
||||
*/
|
||||
export let sessionId: string;
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ import {CancellationTokenSource} from 'vs/base/common/cancellation';
|
|||
import vscode = require('vscode');
|
||||
import {TextEditorRevealType} from 'vs/workbench/api/node/mainThreadEditors';
|
||||
import * as paths from 'vs/base/common/paths';
|
||||
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
|
||||
import {ITelemetryService, ITelemetryInfo} from 'vs/platform/telemetry/common/telemetry';
|
||||
|
||||
/**
|
||||
* This class implements the API described in vscode.d.ts,
|
||||
|
@ -144,15 +144,13 @@ export class ExtHostAPIImplementation {
|
|||
const extHostOutputService = new ExtHostOutputService(this._threadService);
|
||||
|
||||
// env namespace
|
||||
this.env = {
|
||||
machineId: undefined,
|
||||
sessionId: undefined,
|
||||
// locale: undefined
|
||||
}
|
||||
telemetryService.getTelemetryInfo().then(info => {
|
||||
this.env.machineId = info.machineId;
|
||||
this.env.sessionId = info.sessionId;
|
||||
}, errors.onUnexpectedError);
|
||||
let telemetryInfo: ITelemetryInfo;
|
||||
this.env = Object.freeze({
|
||||
get machineId() { return telemetryInfo.machineId },
|
||||
get sessionId() { return telemetryInfo.sessionId },
|
||||
get language() { return contextService.getConfiguration().env.language }
|
||||
});
|
||||
telemetryService.getTelemetryInfo().then(info => telemetryInfo = info, errors.onUnexpectedError);
|
||||
|
||||
// commands namespace
|
||||
this.commands = {
|
||||
|
|
|
@ -49,6 +49,9 @@ export function startup(environment: IMainEnvironment, globalSettings: IGlobalSe
|
|||
env: environment
|
||||
};
|
||||
|
||||
// Inherit navigator language
|
||||
environment.language = navigator.language;
|
||||
|
||||
// Shell Options
|
||||
let filesToOpen = environment.filesToOpen && environment.filesToOpen.length ? toInputs(environment.filesToOpen) : null;
|
||||
let filesToCreate = environment.filesToCreate && environment.filesToCreate.length ? toInputs(environment.filesToCreate) : null;
|
||||
|
|
Loading…
Reference in a new issue