Use VersionDependentRegistration for update paths on rename

Avoids registering class on unsupported ts versions
This commit is contained in:
Matt Bierner 2018-07-25 17:56:08 -07:00
parent d5855b35b2
commit f97c743507
2 changed files with 12 additions and 9 deletions

View file

@ -15,6 +15,7 @@ import { isTypeScriptDocument } from '../utils/languageModeIds';
import { escapeRegExp } from '../utils/regexp'; import { escapeRegExp } from '../utils/regexp';
import * as typeConverters from '../utils/typeConverters'; import * as typeConverters from '../utils/typeConverters';
import FileConfigurationManager from './fileConfigurationManager'; import FileConfigurationManager from './fileConfigurationManager';
import { VersionDependentRegistration } from '../utils/dependentRegistration';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
@ -26,7 +27,7 @@ enum UpdateImportsOnFileMoveSetting {
Never = 'never', Never = 'never',
} }
export class UpdateImportsOnFileRenameHandler { class UpdateImportsOnFileRenameHandler {
private readonly _onDidRenameSub: vscode.Disposable; private readonly _onDidRenameSub: vscode.Disposable;
public constructor( public constructor(
@ -47,10 +48,6 @@ export class UpdateImportsOnFileRenameHandler {
oldResource: vscode.Uri, oldResource: vscode.Uri,
newResource: vscode.Uri, newResource: vscode.Uri,
): Promise<void> { ): Promise<void> {
if (!this.client.apiVersion.gte(API.v290)) {
return;
}
const targetResource = await this.getTargetResource(newResource); const targetResource = await this.getTargetResource(newResource);
if (!targetResource) { if (!targetResource) {
return; return;
@ -304,3 +301,11 @@ export class UpdateImportsOnFileRenameHandler {
} }
} }
export function register(
client: ITypeScriptServiceClient,
fileConfigurationManager: FileConfigurationManager,
handles: (uri: vscode.Uri) => Promise<boolean>,
) {
return new VersionDependentRegistration(client, API.v290, () =>
new UpdateImportsOnFileRenameHandler(client, fileConfigurationManager, handles));
}

View file

@ -11,7 +11,7 @@
import { Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag, Disposable, Memento, Range, Uri, workspace } from 'vscode'; import { Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag, Disposable, Memento, Range, Uri, workspace } from 'vscode';
import { DiagnosticKind } from './features/diagnostics'; import { DiagnosticKind } from './features/diagnostics';
import FileConfigurationManager from './features/fileConfigurationManager'; import FileConfigurationManager from './features/fileConfigurationManager';
import { UpdateImportsOnFileRenameHandler } from './features/updatePathsOnRename'; import { register as registerUpdatePathsOnRename } from './features/updatePathsOnRename';
import LanguageProvider from './languageProvider'; import LanguageProvider from './languageProvider';
import * as Proto from './protocol'; import * as Proto from './protocol';
import * as PConst from './protocol.const'; import * as PConst from './protocol.const';
@ -45,7 +45,6 @@ export default class TypeScriptServiceClientHost {
private readonly disposables: Disposable[] = []; private readonly disposables: Disposable[] = [];
private readonly versionStatus: VersionStatus; private readonly versionStatus: VersionStatus;
private readonly fileConfigurationManager: FileConfigurationManager; private readonly fileConfigurationManager: FileConfigurationManager;
private readonly updateImportsOnFileRenameHandler: UpdateImportsOnFileRenameHandler;
private reportStyleCheckAsWarnings: boolean = true; private reportStyleCheckAsWarnings: boolean = true;
@ -101,7 +100,7 @@ export default class TypeScriptServiceClientHost {
this.languagePerId.set(description.id, manager); this.languagePerId.set(description.id, manager);
} }
this.updateImportsOnFileRenameHandler = new UpdateImportsOnFileRenameHandler(this.client, this.fileConfigurationManager, uri => this.handles(uri)); this.disposables.push(registerUpdatePathsOnRename(this.client, this.fileConfigurationManager, uri => this.handles(uri)));
this.client.ensureServiceStarted(); this.client.ensureServiceStarted();
this.client.onReady(() => { this.client.onReady(() => {
@ -152,7 +151,6 @@ export default class TypeScriptServiceClientHost {
this.typingsStatus.dispose(); this.typingsStatus.dispose();
this.ataProgressReporter.dispose(); this.ataProgressReporter.dispose();
this.fileConfigurationManager.dispose(); this.fileConfigurationManager.dispose();
this.updateImportsOnFileRenameHandler.dispose();
} }
public get serviceClient(): TypeScriptServiceClient { public get serviceClient(): TypeScriptServiceClient {