Merge branch 'main' into joh/webpack5

This commit is contained in:
Martin Aeschlimann
2021-07-09 09:50:10 +02:00
198 changed files with 2298 additions and 1662 deletions

View File

@@ -5,18 +5,19 @@
import * as vscode from 'vscode';
import { Api, getExtensionApi } from './api';
import { CommandManager } from './commands/commandManager';
import { registerBaseCommands } from './commands/index';
import { LanguageConfigurationManager } from './languageFeatures/languageConfiguration';
import { createLazyClientHost, lazilyActivateClient } from './lazyClientHost';
import { noopRequestCancellerFactory } from './tsServer/cancellation';
import { noopLogDirectoryProvider } from './tsServer/logDirectoryProvider';
import { ITypeScriptVersionProvider, TypeScriptVersion, TypeScriptVersionSource } from './tsServer/versionProvider';
import { WorkerServerProcess } from './tsServer/serverProcess.browser';
import API from './utils/api';
import { CommandManager } from './commands/commandManager';
import { TypeScriptServiceConfiguration } from './utils/configuration';
import { PluginManager } from './utils/plugins';
import { ITypeScriptVersionProvider, TypeScriptVersion, TypeScriptVersionSource } from './tsServer/versionProvider';
import { ActiveJsTsEditorTracker } from './utils/activeJsTsEditorTracker';
import API from './utils/api';
import { TypeScriptServiceConfiguration } from './utils/configuration';
import { BrowserServiceConfigurationProvider } from './utils/configuration.browser';
import { PluginManager } from './utils/plugins';
class StaticVersionProvider implements ITypeScriptVersionProvider {
@@ -66,7 +67,8 @@ export function activate(
cancellerFactory: noopRequestCancellerFactory,
versionProvider,
processFactory: WorkerServerProcess,
activeJsTsEditorTracker
activeJsTsEditorTracker,
serviceConfigurationProvider: new BrowserServiceConfigurationProvider(),
}, item => {
onCompletionAccepted.fire(item);
});

View File

@@ -15,6 +15,7 @@ import { NodeLogDirectoryProvider } from './tsServer/logDirectoryProvider.electr
import { ChildServerProcess } from './tsServer/serverProcess.electron';
import { DiskTypeScriptVersionProvider } from './tsServer/versionProvider.electron';
import { ActiveJsTsEditorTracker } from './utils/activeJsTsEditorTracker';
import { ElectronServiceConfigurationProvider } from './utils/configuration.electron';
import { onCaseInsenitiveFileSystem } from './utils/fileSystem.electron';
import { PluginManager } from './utils/plugins';
import * as temp from './utils/temp.electron';
@@ -47,6 +48,7 @@ export function activate(
versionProvider,
processFactory: ChildServerProcess,
activeJsTsEditorTracker,
serviceConfigurationProvider: new ElectronServiceConfigurationProvider(),
}, item => {
onCompletionAccepted.fire(item);
});

View File

@@ -12,6 +12,7 @@ import { ITypeScriptVersionProvider } from './tsServer/versionProvider';
import TypeScriptServiceClientHost from './typeScriptServiceClientHost';
import { ActiveJsTsEditorTracker } from './utils/activeJsTsEditorTracker';
import { flatten } from './utils/arrays';
import { ServiceConfigurationProvider } from './utils/configuration';
import * as fileSchemes from './utils/fileSchemes';
import { standardLanguageDescriptions } from './utils/languageDescription';
import { lazy, Lazy } from './utils/lazy';
@@ -29,6 +30,7 @@ export function createLazyClientHost(
versionProvider: ITypeScriptVersionProvider,
processFactory: TsServerProcessFactory,
activeJsTsEditorTracker: ActiveJsTsEditorTracker,
serviceConfigurationProvider: ServiceConfigurationProvider,
},
onCompletionAccepted: (item: vscode.CompletionItem) => void,
): Lazy<TypeScriptServiceClientHost> {

View File

@@ -31,6 +31,7 @@ import TypingsStatus, { AtaProgressReporter } from './utils/typingsStatus';
import * as ProjectStatus from './utils/largeProjectStatus';
import { ActiveJsTsEditorTracker } from './utils/activeJsTsEditorTracker';
import { LogLevelMonitor } from './utils/logLevelMonitor';
import { ServiceConfigurationProvider } from './utils/configuration';
// Style check diagnostics that can be reported as warnings
const styleCheckDiagnostics = new Set([
@@ -69,6 +70,7 @@ export default class TypeScriptServiceClientHost extends Disposable {
versionProvider: ITypeScriptVersionProvider,
processFactory: TsServerProcessFactory,
activeJsTsEditorTracker: ActiveJsTsEditorTracker,
serviceConfigurationProvider: ServiceConfigurationProvider,
},
onCompletionAccepted: (item: vscode.CompletionItem) => void,
) {

View File

@@ -19,7 +19,7 @@ import { TypeScriptVersionManager } from './tsServer/versionManager';
import { ITypeScriptVersionProvider, TypeScriptVersion } from './tsServer/versionProvider';
import { ClientCapabilities, ClientCapability, ExecConfig, ITypeScriptServiceClient, ServerResponse, TypeScriptRequests } from './typescriptService';
import API from './utils/api';
import { SeparateSyntaxServerConfiguration, TsServerLogLevel, TypeScriptServiceConfiguration } from './utils/configuration';
import { areServiceConfigurationsEqual, ServiceConfigurationProvider, SeparateSyntaxServerConfiguration, TsServerLogLevel, TypeScriptServiceConfiguration } from './utils/configuration';
import { Disposable } from './utils/dispose';
import * as fileSchemes from './utils/fileSchemes';
import { Logger } from './utils/logger';
@@ -135,6 +135,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
cancellerFactory: OngoingRequestCancellerFactory,
versionProvider: ITypeScriptVersionProvider,
processFactory: TsServerProcessFactory,
serviceConfigurationProvider: ServiceConfigurationProvider,
},
allModeIds: readonly string[]
) {
@@ -161,7 +162,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
this.numberRestarts = 0;
this._configuration = TypeScriptServiceConfiguration.loadFromWorkspace();
this._configuration = services.serviceConfigurationProvider.loadFromWorkspace();
this.versionProvider.updateConfiguration(this._configuration);
this.pluginPathsProvider = new TypeScriptPluginPathsProvider(this._configuration);
@@ -185,7 +186,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
vscode.workspace.onDidChangeConfiguration(() => {
const oldConfiguration = this._configuration;
this._configuration = TypeScriptServiceConfiguration.loadFromWorkspace();
this._configuration = services.serviceConfigurationProvider.loadFromWorkspace();
this.versionProvider.updateConfiguration(this._configuration);
this._versionManager.updateConfiguration(this._configuration);
@@ -193,11 +194,11 @@ export default class TypeScriptServiceClient extends Disposable implements IType
this.tracer.updateConfiguration();
if (this.serverState.type === ServerState.Type.Running) {
if (!this._configuration.implictProjectConfiguration.isEqualTo(oldConfiguration.implictProjectConfiguration)) {
if (!this._configuration.implicitProjectConfiguration.isEqualTo(oldConfiguration.implicitProjectConfiguration)) {
this.setCompilerOptionsForInferredProjects(this._configuration);
}
if (!this._configuration.isEqualTo(oldConfiguration)) {
if (!areServiceConfigurationsEqual(this._configuration, oldConfiguration)) {
this.restartTsServer();
}
}

View File

@@ -0,0 +1,19 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { BaseServiceConfigurationProvider } from './configuration';
export class BrowserServiceConfigurationProvider extends BaseServiceConfigurationProvider {
// On browsers, we only support using the built-in TS version
protected extractGlobalTsdk(_configuration: vscode.WorkspaceConfiguration): string | null {
return null;
}
protected extractLocalTsdk(_configuration: vscode.WorkspaceConfiguration): string | null {
return null;
}
}

View File

@@ -0,0 +1,38 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as os from 'os';
import * as path from 'path';
import * as vscode from 'vscode';
import { BaseServiceConfigurationProvider } from './configuration';
export class ElectronServiceConfigurationProvider extends BaseServiceConfigurationProvider {
private fixPathPrefixes(inspectValue: string): string {
const pathPrefixes = ['~' + path.sep];
for (const pathPrefix of pathPrefixes) {
if (inspectValue.startsWith(pathPrefix)) {
return path.join(os.homedir(), inspectValue.slice(pathPrefix.length));
}
}
return inspectValue;
}
protected extractGlobalTsdk(configuration: vscode.WorkspaceConfiguration): string | null {
const inspect = configuration.inspect('typescript.tsdk');
if (inspect && typeof inspect.globalValue === 'string') {
return this.fixPathPrefixes(inspect.globalValue);
}
return null;
}
protected extractLocalTsdk(configuration: vscode.WorkspaceConfiguration): string | null {
const inspect = configuration.inspect('typescript.tsdk');
if (inspect && typeof inspect.workspaceValue === 'string') {
return this.fixPathPrefixes(inspect.workspaceValue);
}
return null;
}
}

View File

@@ -3,8 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as os from 'os';
import * as path from 'path';
import * as vscode from 'vscode';
import * as objects from '../utils/objects';
@@ -89,100 +87,80 @@ export class ImplicitProjectConfiguration {
}
}
export class TypeScriptServiceConfiguration {
public readonly locale: string | null;
public readonly globalTsdk: string | null;
public readonly localTsdk: string | null;
public readonly npmLocation: string | null;
public readonly tsServerLogLevel: TsServerLogLevel = TsServerLogLevel.Off;
public readonly tsServerPluginPaths: readonly string[];
public readonly implictProjectConfiguration: ImplicitProjectConfiguration;
public readonly disableAutomaticTypeAcquisition: boolean;
public readonly separateSyntaxServer: SeparateSyntaxServerConfiguration;
public readonly enableProjectDiagnostics: boolean;
public readonly maxTsServerMemory: number;
public readonly enablePromptUseWorkspaceTsdk: boolean;
public readonly watchOptions: protocol.WatchOptions | undefined;
public readonly includePackageJsonAutoImports: 'auto' | 'on' | 'off' | undefined;
public readonly enableTsServerTracing: boolean;
export interface TypeScriptServiceConfiguration {
readonly locale: string | null;
readonly globalTsdk: string | null;
readonly localTsdk: string | null;
readonly npmLocation: string | null;
readonly tsServerLogLevel: TsServerLogLevel;
readonly tsServerPluginPaths: readonly string[];
readonly implicitProjectConfiguration: ImplicitProjectConfiguration;
readonly disableAutomaticTypeAcquisition: boolean;
readonly separateSyntaxServer: SeparateSyntaxServerConfiguration;
readonly enableProjectDiagnostics: boolean;
readonly maxTsServerMemory: number;
readonly enablePromptUseWorkspaceTsdk: boolean;
readonly watchOptions: protocol.WatchOptions | undefined;
readonly includePackageJsonAutoImports: 'auto' | 'on' | 'off' | undefined;
readonly enableTsServerTracing: boolean;
}
public static loadFromWorkspace(): TypeScriptServiceConfiguration {
return new TypeScriptServiceConfiguration();
}
export function areServiceConfigurationsEqual(a: TypeScriptServiceConfiguration, b: TypeScriptServiceConfiguration): boolean {
return objects.equals(a, b);
}
private constructor() {
export interface ServiceConfigurationProvider {
loadFromWorkspace(): TypeScriptServiceConfiguration;
}
export abstract class BaseServiceConfigurationProvider implements ServiceConfigurationProvider {
public loadFromWorkspace(): TypeScriptServiceConfiguration {
const configuration = vscode.workspace.getConfiguration();
this.locale = TypeScriptServiceConfiguration.extractLocale(configuration);
this.globalTsdk = TypeScriptServiceConfiguration.extractGlobalTsdk(configuration);
this.localTsdk = TypeScriptServiceConfiguration.extractLocalTsdk(configuration);
this.npmLocation = TypeScriptServiceConfiguration.readNpmLocation(configuration);
this.tsServerLogLevel = TypeScriptServiceConfiguration.readTsServerLogLevel(configuration);
this.tsServerPluginPaths = TypeScriptServiceConfiguration.readTsServerPluginPaths(configuration);
this.implictProjectConfiguration = new ImplicitProjectConfiguration(configuration);
this.disableAutomaticTypeAcquisition = TypeScriptServiceConfiguration.readDisableAutomaticTypeAcquisition(configuration);
this.separateSyntaxServer = TypeScriptServiceConfiguration.readUseSeparateSyntaxServer(configuration);
this.enableProjectDiagnostics = TypeScriptServiceConfiguration.readEnableProjectDiagnostics(configuration);
this.maxTsServerMemory = TypeScriptServiceConfiguration.readMaxTsServerMemory(configuration);
this.enablePromptUseWorkspaceTsdk = TypeScriptServiceConfiguration.readEnablePromptUseWorkspaceTsdk(configuration);
this.watchOptions = TypeScriptServiceConfiguration.readWatchOptions(configuration);
this.includePackageJsonAutoImports = TypeScriptServiceConfiguration.readIncludePackageJsonAutoImports(configuration);
this.enableTsServerTracing = TypeScriptServiceConfiguration.readEnableTsServerTracing(configuration);
return {
locale: this.extractLocale(configuration),
globalTsdk: this.extractGlobalTsdk(configuration),
localTsdk: this.extractLocalTsdk(configuration),
npmLocation: this.readNpmLocation(configuration),
tsServerLogLevel: this.readTsServerLogLevel(configuration),
tsServerPluginPaths: this.readTsServerPluginPaths(configuration),
implicitProjectConfiguration: new ImplicitProjectConfiguration(configuration),
disableAutomaticTypeAcquisition: this.readDisableAutomaticTypeAcquisition(configuration),
separateSyntaxServer: this.readUseSeparateSyntaxServer(configuration),
enableProjectDiagnostics: this.readEnableProjectDiagnostics(configuration),
maxTsServerMemory: this.readMaxTsServerMemory(configuration),
enablePromptUseWorkspaceTsdk: this.readEnablePromptUseWorkspaceTsdk(configuration),
watchOptions: this.readWatchOptions(configuration),
includePackageJsonAutoImports: this.readIncludePackageJsonAutoImports(configuration),
enableTsServerTracing: this.readEnableTsServerTracing(configuration),
};
}
public isEqualTo(other: TypeScriptServiceConfiguration): boolean {
return objects.equals(this, other);
}
protected abstract extractGlobalTsdk(configuration: vscode.WorkspaceConfiguration): string | null;
protected abstract extractLocalTsdk(configuration: vscode.WorkspaceConfiguration): string | null;
private static fixPathPrefixes(inspectValue: string): string {
const pathPrefixes = ['~' + path.sep];
for (const pathPrefix of pathPrefixes) {
if (inspectValue.startsWith(pathPrefix)) {
const homedir = typeof os.homedir === 'function' ? os.homedir() : ''; // no os.homedir in the browser #128222
return path.join(homedir, inspectValue.slice(pathPrefix.length));
}
}
return inspectValue;
}
private static extractGlobalTsdk(configuration: vscode.WorkspaceConfiguration): string | null {
const inspect = configuration.inspect('typescript.tsdk');
if (inspect && typeof inspect.globalValue === 'string') {
return this.fixPathPrefixes(inspect.globalValue);
}
return null;
}
private static extractLocalTsdk(configuration: vscode.WorkspaceConfiguration): string | null {
const inspect = configuration.inspect('typescript.tsdk');
if (inspect && typeof inspect.workspaceValue === 'string') {
return this.fixPathPrefixes(inspect.workspaceValue);
}
return null;
}
private static readTsServerLogLevel(configuration: vscode.WorkspaceConfiguration): TsServerLogLevel {
protected readTsServerLogLevel(configuration: vscode.WorkspaceConfiguration): TsServerLogLevel {
const setting = configuration.get<string>('typescript.tsserver.log', 'off');
return TsServerLogLevel.fromString(setting);
}
private static readTsServerPluginPaths(configuration: vscode.WorkspaceConfiguration): string[] {
protected readTsServerPluginPaths(configuration: vscode.WorkspaceConfiguration): string[] {
return configuration.get<string[]>('typescript.tsserver.pluginPaths', []);
}
private static readNpmLocation(configuration: vscode.WorkspaceConfiguration): string | null {
protected readNpmLocation(configuration: vscode.WorkspaceConfiguration): string | null {
return configuration.get<string | null>('typescript.npm', null);
}
private static readDisableAutomaticTypeAcquisition(configuration: vscode.WorkspaceConfiguration): boolean {
protected readDisableAutomaticTypeAcquisition(configuration: vscode.WorkspaceConfiguration): boolean {
return configuration.get<boolean>('typescript.disableAutomaticTypeAcquisition', false);
}
private static extractLocale(configuration: vscode.WorkspaceConfiguration): string | null {
protected extractLocale(configuration: vscode.WorkspaceConfiguration): string | null {
return configuration.get<string | null>('typescript.locale', null);
}
private static readUseSeparateSyntaxServer(configuration: vscode.WorkspaceConfiguration): SeparateSyntaxServerConfiguration {
protected readUseSeparateSyntaxServer(configuration: vscode.WorkspaceConfiguration): SeparateSyntaxServerConfiguration {
const value = configuration.get<boolean | string>('typescript.tsserver.useSeparateSyntaxServer', true);
if (value === 'forAllRequests') {
return SeparateSyntaxServerConfiguration.ForAllRequests;
@@ -193,19 +171,19 @@ export class TypeScriptServiceConfiguration {
return SeparateSyntaxServerConfiguration.Disabled;
}
private static readEnableProjectDiagnostics(configuration: vscode.WorkspaceConfiguration): boolean {
protected readEnableProjectDiagnostics(configuration: vscode.WorkspaceConfiguration): boolean {
return configuration.get<boolean>('typescript.tsserver.experimental.enableProjectDiagnostics', false);
}
private static readWatchOptions(configuration: vscode.WorkspaceConfiguration): protocol.WatchOptions | undefined {
protected readWatchOptions(configuration: vscode.WorkspaceConfiguration): protocol.WatchOptions | undefined {
return configuration.get<protocol.WatchOptions>('typescript.tsserver.watchOptions');
}
private static readIncludePackageJsonAutoImports(configuration: vscode.WorkspaceConfiguration): 'auto' | 'on' | 'off' | undefined {
protected readIncludePackageJsonAutoImports(configuration: vscode.WorkspaceConfiguration): 'auto' | 'on' | 'off' | undefined {
return configuration.get<'auto' | 'on' | 'off'>('typescript.preferences.includePackageJsonAutoImports');
}
private static readMaxTsServerMemory(configuration: vscode.WorkspaceConfiguration): number {
protected readMaxTsServerMemory(configuration: vscode.WorkspaceConfiguration): number {
const defaultMaxMemory = 3072;
const minimumMaxMemory = 128;
const memoryInMB = configuration.get<number>('typescript.tsserver.maxTsServerMemory', defaultMaxMemory);
@@ -215,11 +193,12 @@ export class TypeScriptServiceConfiguration {
return Math.max(memoryInMB, minimumMaxMemory);
}
private static readEnablePromptUseWorkspaceTsdk(configuration: vscode.WorkspaceConfiguration): boolean {
protected readEnablePromptUseWorkspaceTsdk(configuration: vscode.WorkspaceConfiguration): boolean {
return configuration.get<boolean>('typescript.enablePromptUseWorkspaceTsdk', false);
}
private static readEnableTsServerTracing(configuration: vscode.WorkspaceConfiguration): boolean {
protected readEnableTsServerTracing(configuration: vscode.WorkspaceConfiguration): boolean {
return configuration.get<boolean>('typescript.tsserver.enableTracing', false);
}
}

View File

@@ -32,22 +32,22 @@ export function inferredProjectCompilerOptions(
jsx: 'preserve' as Proto.JsxEmit,
};
if (serviceConfig.implictProjectConfiguration.checkJs) {
if (serviceConfig.implicitProjectConfiguration.checkJs) {
projectConfig.checkJs = true;
if (projectType === ProjectType.TypeScript) {
projectConfig.allowJs = true;
}
}
if (serviceConfig.implictProjectConfiguration.experimentalDecorators) {
if (serviceConfig.implicitProjectConfiguration.experimentalDecorators) {
projectConfig.experimentalDecorators = true;
}
if (serviceConfig.implictProjectConfiguration.strictNullChecks) {
if (serviceConfig.implicitProjectConfiguration.strictNullChecks) {
projectConfig.strictNullChecks = true;
}
if (serviceConfig.implictProjectConfiguration.strictFunctionTypes) {
if (serviceConfig.implicitProjectConfiguration.strictFunctionTypes) {
projectConfig.strictFunctionTypes = true;
}