Skip to content

Commit

Permalink
Only use one paths rename handler
Browse files Browse the repository at this point in the history
Fixes #51485
  • Loading branch information
mjbvz committed Jun 12, 2018
1 parent db9865b commit 583f1e4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 35 deletions.
2 changes: 1 addition & 1 deletion extensions/typescript-language-features/src/commands.ts
Expand Up @@ -121,7 +121,7 @@ async function goToProjectConfig(

const file = client.toPath(resource);
// TSServer errors when 'projectInfo' is invoked on a non js/ts file
if (!file || !clientHost.handles(resource)) {
if (!file || !await clientHost.handles(resource)) {
vscode.window.showWarningMessage(
localize(
'typescript.projectConfigUnsupportedFile',
Expand Down
Expand Up @@ -32,6 +32,7 @@ export class UpdateImportsOnFileRenameHandler {
private readonly handles: (uri: vscode.Uri) => Promise<boolean>,
) {
this._onDidRenameSub = vscode.workspace.onDidRenameResource(e => {
console.log(e.newResource);
this.doRename(e.oldResource, e.newResource);
});
}
Expand All @@ -48,10 +49,13 @@ export class UpdateImportsOnFileRenameHandler {
return;
}

if (!await this.handles(newResource)) {
const handles = await this.handles(newResource);
console.log(handles);
if (!handles) {
return;
}


const newFile = this.client.toPath(newResource);
if (!newFile) {
return;
Expand Down Expand Up @@ -79,6 +83,7 @@ export class UpdateImportsOnFileRenameHandler {
return;
}

console.log('x');
if (await this.confirmActionWithUser(document)) {
await vscode.workspace.applyEdit(edits);
}
Expand Down
17 changes: 0 additions & 17 deletions extensions/typescript-language-features/src/languageProvider.ts
Expand Up @@ -17,7 +17,6 @@ import { CachedNavTreeResponse } from './features/baseCodeLensProvider';
import { memoize } from './utils/memoize';
import { disposeAll } from './utils/dispose';
import TelemetryReporter from './utils/telemetry';
import { UpdateImportsOnFileRenameHandler } from './features/updatePathsOnRename';

const validateSetting = 'validate.enable';
const suggestionSetting = 'suggestionActions.enabled';
Expand All @@ -30,8 +29,6 @@ export default class LanguageProvider {

private readonly disposables: vscode.Disposable[] = [];

private readonly renameHandler: UpdateImportsOnFileRenameHandler;

constructor(
private readonly client: TypeScriptServiceClient,
private readonly description: LanguageDescription,
Expand All @@ -52,22 +49,12 @@ export default class LanguageProvider {
client.onReady(async () => {
await this.registerProviders();
});

this.renameHandler = new UpdateImportsOnFileRenameHandler(this.client, this.fileConfigurationManager, async uri => {
try {
const doc = await vscode.workspace.openTextDocument(uri);
return this.handles(uri, doc);
} catch {
return false;
}
});
}

public dispose(): void {
disposeAll(this.disposables);

this.diagnosticsManager.dispose();
this.renameHandler.dispose();
}

@memoize
Expand Down Expand Up @@ -119,10 +106,6 @@ export default class LanguageProvider {
return true;
}

if (this.client.bufferSyncSupport.handles(resource)) {
return true;
}

const base = basename(resource.fsPath);
return !!base && base === this.description.configFile;
}
Expand Down
Expand Up @@ -8,25 +8,23 @@
* https://github.com/Microsoft/TypeScript-Sublime-Plugin/blob/master/TypeScript%20Indent.tmPreferences
* ------------------------------------------------------------------------------------------ */

import { workspace, Memento, Diagnostic, Range, Disposable, Uri, DiagnosticSeverity, DiagnosticTag, DiagnosticRelatedInformation } from 'vscode';

import { Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag, Disposable, Memento, Range, Uri, workspace } from 'vscode';
import { DiagnosticKind } from './features/diagnostics';
import FileConfigurationManager from './features/fileConfigurationManager';
import LanguageProvider from './languageProvider';
import * as Proto from './protocol';
import * as PConst from './protocol.const';

import TypeScriptServiceClient from './typescriptServiceClient';
import LanguageProvider from './languageProvider';

import TypingsStatus, { AtaProgressReporter } from './utils/typingsStatus';
import VersionStatus from './utils/versionStatus';
import { TypeScriptServerPlugin } from './utils/plugins';
import * as typeConverters from './utils/typeConverters';
import API from './utils/api';
import { CommandManager } from './utils/commandManager';
import { disposeAll } from './utils/dispose';
import { LanguageDescription } from './utils/languageDescription';
import LogDirectoryProvider from './utils/logDirectoryProvider';
import { disposeAll } from './utils/dispose';
import { DiagnosticKind } from './features/diagnostics';
import API from './utils/api';
import FileConfigurationManager from './features/fileConfigurationManager';
import { TypeScriptServerPlugin } from './utils/plugins';
import * as typeConverters from './utils/typeConverters';
import TypingsStatus, { AtaProgressReporter } from './utils/typingsStatus';
import VersionStatus from './utils/versionStatus';
import { UpdateImportsOnFileRenameHandler } from './features/updatePathsOnRename';

// Style check diagnostics that can be reported as warnings
const styleCheckDiagnostics = [
Expand All @@ -47,6 +45,7 @@ export default class TypeScriptServiceClientHost {
private readonly disposables: Disposable[] = [];
private readonly versionStatus: VersionStatus;
private readonly fileConfigurationManager: FileConfigurationManager;
private readonly updateImportsOnFileRenameHandler: UpdateImportsOnFileRenameHandler;

private reportStyleCheckAsWarnings: boolean = true;

Expand Down Expand Up @@ -95,14 +94,15 @@ export default class TypeScriptServiceClientHost {
this.ataProgressReporter = new AtaProgressReporter(this.client);
this.fileConfigurationManager = new FileConfigurationManager(this.client);


for (const description of descriptions) {
const manager = new LanguageProvider(this.client, description, this.commandManager, this.client.telemetryReporter, this.typingsStatus, this.fileConfigurationManager);
this.languages.push(manager);
this.disposables.push(manager);
this.languagePerId.set(description.id, manager);
}

this.updateImportsOnFileRenameHandler = new UpdateImportsOnFileRenameHandler(this.client, this.fileConfigurationManager, uri => this.handles(uri));

this.client.ensureServiceStarted();
this.client.onReady(() => {
if (!this.client.apiVersion.gte(API.v230)) {
Expand Down Expand Up @@ -151,6 +151,7 @@ export default class TypeScriptServiceClientHost {
this.typingsStatus.dispose();
this.ataProgressReporter.dispose();
this.fileConfigurationManager.dispose();
this.updateImportsOnFileRenameHandler.dispose();
}

public get serviceClient(): TypeScriptServiceClient {
Expand All @@ -162,8 +163,12 @@ export default class TypeScriptServiceClientHost {
this.triggerAllDiagnostics();
}

public handles(resource: Uri): boolean {
return !!this.findLanguage(resource);
public async handles(resource: Uri): Promise<boolean> {
const provider = await this.findLanguage(resource);
if (provider) {
return true;
}
return this.client.bufferSyncSupport.handles(resource);
}

private configurationChanged(): void {
Expand Down

0 comments on commit 583f1e4

Please sign in to comment.