Auto restart TS Server on watch options change

This commit is contained in:
Matt Bierner 2020-02-24 15:02:36 -08:00
parent d46c8a8c3c
commit 6ff3d9c899
3 changed files with 57 additions and 5 deletions

View file

@ -477,7 +477,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
this.bufferSyncSupport.reset();
const watchOptions = this.apiVersion.gte(API.v380)
? vscode.workspace.getConfiguration('typescript').get<Proto.WatchOptions | undefined>('tsserver.watchOptions')
? this.configuration.watchOptions
: undefined;
const configureOptions: Proto.ConfigureRequestArguments = {

View file

@ -2,10 +2,12 @@
* 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 * as arrays from './arrays';
import * as os from 'os';
import * as path from 'path';
import * as vscode from 'vscode';
import * as objects from '../utils/objects';
import * as arrays from './arrays';
export enum TsServerLogLevel {
Off,
@ -50,13 +52,14 @@ export class TypeScriptServiceConfiguration {
public readonly localTsdk: string | null;
public readonly npmLocation: string | null;
public readonly tsServerLogLevel: TsServerLogLevel = TsServerLogLevel.Off;
public readonly tsServerPluginPaths: string[];
public readonly tsServerPluginPaths: readonly string[];
public readonly checkJs: boolean;
public readonly experimentalDecorators: boolean;
public readonly disableAutomaticTypeAcquisition: boolean;
public readonly useSeparateSyntaxServer: boolean;
public readonly enableProjectDiagnostics: boolean;
public readonly maxTsServerMemory: number;
public readonly watchOptions: protocol.WatchOptions | undefined;
public static loadFromWorkspace(): TypeScriptServiceConfiguration {
return new TypeScriptServiceConfiguration();
@ -77,6 +80,7 @@ export class TypeScriptServiceConfiguration {
this.useSeparateSyntaxServer = TypeScriptServiceConfiguration.readUseSeparateSyntaxServer(configuration);
this.enableProjectDiagnostics = TypeScriptServiceConfiguration.readEnableProjectDiagnostics(configuration);
this.maxTsServerMemory = TypeScriptServiceConfiguration.readMaxTsServerMemory(configuration);
this.watchOptions = TypeScriptServiceConfiguration.readWatchOptions(configuration);
}
public isEqualTo(other: TypeScriptServiceConfiguration): boolean {
@ -91,7 +95,8 @@ export class TypeScriptServiceConfiguration {
&& arrays.equals(this.tsServerPluginPaths, other.tsServerPluginPaths)
&& this.useSeparateSyntaxServer === other.useSeparateSyntaxServer
&& this.enableProjectDiagnostics === other.enableProjectDiagnostics
&& this.maxTsServerMemory === other.maxTsServerMemory;
&& this.maxTsServerMemory === other.maxTsServerMemory
&& objects.equals(this.watchOptions, other.watchOptions);
}
private static fixPathPrefixes(inspectValue: string): string {
@ -157,6 +162,10 @@ export class TypeScriptServiceConfiguration {
return configuration.get<boolean>('typescript.tsserver.experimental.enableProjectDiagnostics', false);
}
private static readWatchOptions(configuration: vscode.WorkspaceConfiguration): protocol.WatchOptions | undefined {
return configuration.get<protocol.WatchOptions>('typescript.tsserver.watchOptions');
}
private static readMaxTsServerMemory(configuration: vscode.WorkspaceConfiguration): number {
const defaultMaxMemory = 3072;
const minimumMaxMemory = 128;

View file

@ -0,0 +1,43 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as array from './arrays';
export function equals(one: any, other: any): boolean {
if (one === other) {
return true;
}
if (one === null || one === undefined || other === null || other === undefined) {
return false;
}
if (typeof one !== typeof other) {
return false;
}
if (typeof one !== 'object') {
return false;
}
if (Array.isArray(one) !== Array.isArray(other)) {
return false;
}
if (Array.isArray(one)) {
return array.equals(one, other, equals);
} else {
const oneKeys: string[] = [];
for (const key in one) {
oneKeys.push(key);
}
oneKeys.sort();
const otherKeys: string[] = [];
for (const key in other) {
otherKeys.push(key);
}
otherKeys.sort();
if (!array.equals(oneKeys, otherKeys)) {
return false;
}
return oneKeys.every(key => equals(one[key], other[key]));
}
}