mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-28 04:23:32 +01:00
Move buffer sync support into client
This will allow the client to access the known buffers during path normalization
This commit is contained in:
@@ -4,19 +4,17 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
import * as nls from 'vscode-nls';
|
||||
import * as Proto from '../protocol';
|
||||
import { ITypeScriptServiceClient } from '../typescriptService';
|
||||
import * as typeConverters from '../utils/typeConverters';
|
||||
import FileConfigurationManager from './fileConfigurationManager';
|
||||
import { getEditForCodeAction, applyCodeActionCommands } from '../utils/codeAction';
|
||||
import { Command, CommandManager } from '../utils/commandManager';
|
||||
import { DiagnosticsManager } from './diagnostics';
|
||||
import BufferSyncSupport from './bufferSyncSupport';
|
||||
|
||||
import * as nls from 'vscode-nls';
|
||||
import TelemetryReporter from '../utils/telemetry';
|
||||
import API from '../utils/api';
|
||||
import { applyCodeActionCommands, getEditForCodeAction } from '../utils/codeAction';
|
||||
import { Command, CommandManager } from '../utils/commandManager';
|
||||
import TelemetryReporter from '../utils/telemetry';
|
||||
import * as typeConverters from '../utils/typeConverters';
|
||||
import { DiagnosticsManager } from './diagnostics';
|
||||
import FileConfigurationManager from './fileConfigurationManager';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
class ApplyCodeActionCommand implements Command {
|
||||
@@ -165,7 +163,6 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider {
|
||||
private readonly formattingConfigurationManager: FileConfigurationManager,
|
||||
commandManager: CommandManager,
|
||||
private readonly diagnosticsManager: DiagnosticsManager,
|
||||
private readonly bufferSyncSupport: BufferSyncSupport,
|
||||
telemetryReporter: TelemetryReporter
|
||||
) {
|
||||
commandManager.register(new ApplyCodeActionCommand(client, telemetryReporter));
|
||||
@@ -194,7 +191,7 @@ class TypeScriptQuickFixProvider implements vscode.CodeActionProvider {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (this.bufferSyncSupport.hasPendingDiagnostics(document.uri)) {
|
||||
if (this.client.bufferSyncSupport.hasPendingDiagnostics(document.uri)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -291,9 +288,8 @@ export function register(
|
||||
fileConfigurationManager: FileConfigurationManager,
|
||||
commandManager: CommandManager,
|
||||
diagnosticsManager: DiagnosticsManager,
|
||||
bufferSyncSupport: BufferSyncSupport,
|
||||
telemetryReporter: TelemetryReporter
|
||||
) {
|
||||
return vscode.languages.registerCodeActionsProvider(selector,
|
||||
new TypeScriptQuickFixProvider(client, fileConfigurationManager, commandManager, diagnosticsManager, bufferSyncSupport, telemetryReporter));
|
||||
new TypeScriptQuickFixProvider(client, fileConfigurationManager, commandManager, diagnosticsManager, telemetryReporter));
|
||||
}
|
||||
|
||||
@@ -8,11 +8,10 @@ import * as vscode from 'vscode';
|
||||
import * as nls from 'vscode-nls';
|
||||
import * as Proto from '../protocol';
|
||||
import { ITypeScriptServiceClient } from '../typescriptService';
|
||||
import API from '../utils/api';
|
||||
import * as languageIds from '../utils/languageModeIds';
|
||||
import * as typeConverters from '../utils/typeConverters';
|
||||
import BufferSyncSupport from './bufferSyncSupport';
|
||||
import FileConfigurationManager from './fileConfigurationManager';
|
||||
import API from '../utils/api';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
@@ -29,7 +28,6 @@ export class UpdateImportsOnFileRenameHandler {
|
||||
|
||||
public constructor(
|
||||
private readonly client: ITypeScriptServiceClient,
|
||||
private readonly bufferSyncSupport: BufferSyncSupport,
|
||||
private readonly fileConfigurationManager: FileConfigurationManager,
|
||||
private readonly handles: (uri: vscode.Uri) => Promise<boolean>,
|
||||
) {
|
||||
@@ -73,8 +71,8 @@ export class UpdateImportsOnFileRenameHandler {
|
||||
}
|
||||
|
||||
// Make sure TS knows about file
|
||||
this.bufferSyncSupport.closeResource(oldResource);
|
||||
this.bufferSyncSupport.openTextDocument(document);
|
||||
this.client.bufferSyncSupport.closeResource(oldResource);
|
||||
this.client.bufferSyncSupport.openTextDocument(document);
|
||||
|
||||
const edits = await this.getEditsForFileRename(document, oldFile, newFile);
|
||||
if (!edits || !edits.size) {
|
||||
|
||||
@@ -7,9 +7,6 @@ import * as vscode from 'vscode';
|
||||
import { basename } from 'path';
|
||||
|
||||
import TypeScriptServiceClient from './typescriptServiceClient';
|
||||
|
||||
import BufferSyncSupport from './features/bufferSyncSupport';
|
||||
|
||||
import TypingsStatus from './utils/typingsStatus';
|
||||
import FileConfigurationManager from './features/fileConfigurationManager';
|
||||
import { CommandManager } from './utils/commandManager';
|
||||
@@ -41,10 +38,9 @@ export default class LanguageProvider {
|
||||
private readonly commandManager: CommandManager,
|
||||
private readonly telemetryReporter: TelemetryReporter,
|
||||
private readonly typingsStatus: TypingsStatus,
|
||||
private readonly fileConfigurationManager: FileConfigurationManager,
|
||||
private readonly bufferSyncSupport: BufferSyncSupport,
|
||||
private readonly fileConfigurationManager: FileConfigurationManager
|
||||
) {
|
||||
this.bufferSyncSupport.onDelete(resource => {
|
||||
this.client.bufferSyncSupport.onDelete(resource => {
|
||||
this.diagnosticsManager.delete(resource);
|
||||
}, null, this.disposables);
|
||||
|
||||
@@ -57,7 +53,7 @@ export default class LanguageProvider {
|
||||
await this.registerProviders();
|
||||
});
|
||||
|
||||
this.renameHandler = new UpdateImportsOnFileRenameHandler(this.client, this.bufferSyncSupport, this.fileConfigurationManager, async uri => {
|
||||
this.renameHandler = new UpdateImportsOnFileRenameHandler(this.client, this.fileConfigurationManager, async uri => {
|
||||
try {
|
||||
const doc = await vscode.workspace.openTextDocument(uri);
|
||||
return this.handles(uri, doc);
|
||||
@@ -102,7 +98,7 @@ export default class LanguageProvider {
|
||||
this.disposables.push((await import('./features/implementationsCodeLens')).register(selector, this.description.id, this.client, cachedResponse));
|
||||
this.disposables.push((await import('./features/jsDocCompletions')).register(selector, this.client, this.commandManager));
|
||||
this.disposables.push((await import('./features/organizeImports')).register(selector, this.client, this.commandManager, this.fileConfigurationManager));
|
||||
this.disposables.push((await import('./features/quickFix')).register(selector, this.client, this.fileConfigurationManager, this.commandManager, this.diagnosticsManager, this.bufferSyncSupport, this.telemetryReporter));
|
||||
this.disposables.push((await import('./features/quickFix')).register(selector, this.client, this.fileConfigurationManager, this.commandManager, this.diagnosticsManager, this.telemetryReporter));
|
||||
this.disposables.push((await import('./features/refactor')).register(selector, this.client, this.fileConfigurationManager, this.commandManager));
|
||||
this.disposables.push((await import('./features/references')).register(selector, this.client));
|
||||
this.disposables.push((await import('./features/referencesCodeLens')).register(selector, this.description.id, this.client, cachedResponse));
|
||||
@@ -123,7 +119,7 @@ export default class LanguageProvider {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.bufferSyncSupport.handles(resource)) {
|
||||
if (this.client.bufferSyncSupport.handles(resource)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -167,7 +163,7 @@ export default class LanguageProvider {
|
||||
}
|
||||
|
||||
public triggerAllDiagnostics(): void {
|
||||
this.bufferSyncSupport.requestAllDiagnostics();
|
||||
this.client.bufferSyncSupport.requestAllDiagnostics();
|
||||
}
|
||||
|
||||
public diagnosticsReceived(diagnosticsKind: DiagnosticKind, file: vscode.Uri, diagnostics: (vscode.Diagnostic & { reportUnnecessary: any })[]): void {
|
||||
|
||||
@@ -27,7 +27,6 @@ import { disposeAll } from './utils/dispose';
|
||||
import { DiagnosticKind } from './features/diagnostics';
|
||||
import API from './utils/api';
|
||||
import FileConfigurationManager from './features/fileConfigurationManager';
|
||||
import BufferSyncSupport from './features/bufferSyncSupport';
|
||||
|
||||
// Style check diagnostics that can be reported as warnings
|
||||
const styleCheckDiagnostics = [
|
||||
@@ -48,7 +47,6 @@ export default class TypeScriptServiceClientHost {
|
||||
private readonly disposables: Disposable[] = [];
|
||||
private readonly versionStatus: VersionStatus;
|
||||
private readonly fileConfigurationManager: FileConfigurationManager;
|
||||
private readonly bufferSyncSupport: BufferSyncSupport;
|
||||
|
||||
private reportStyleCheckAsWarnings: boolean = true;
|
||||
|
||||
@@ -74,7 +72,13 @@ export default class TypeScriptServiceClientHost {
|
||||
configFileWatcher.onDidDelete(handleProjectCreateOrDelete, this, this.disposables);
|
||||
configFileWatcher.onDidChange(handleProjectChange, this, this.disposables);
|
||||
|
||||
this.client = new TypeScriptServiceClient(workspaceState, version => this.versionStatus.onDidChangeTypeScriptVersion(version), plugins, logDirectoryProvider);
|
||||
const allModeIds = this.getAllModeIds(descriptions);
|
||||
this.client = new TypeScriptServiceClient(
|
||||
workspaceState,
|
||||
version => this.versionStatus.onDidChangeTypeScriptVersion(version),
|
||||
plugins,
|
||||
logDirectoryProvider,
|
||||
allModeIds);
|
||||
this.disposables.push(this.client);
|
||||
|
||||
this.client.onDiagnosticsReceived(({ kind, resource, diagnostics }) => {
|
||||
@@ -84,11 +88,6 @@ export default class TypeScriptServiceClientHost {
|
||||
this.client.onConfigDiagnosticsReceived(diag => this.configFileDiagnosticsReceived(diag), null, this.disposables);
|
||||
this.client.onResendModelsRequested(() => this.populateService(), null, this.disposables);
|
||||
|
||||
this.client.onProjectUpdatedInBackground(files => {
|
||||
const resources = files.openFiles.map(Uri.file);
|
||||
this.bufferSyncSupport.getErr(resources);
|
||||
}, null, this.disposables);
|
||||
|
||||
this.versionStatus = new VersionStatus(resource => this.client.toPath(resource));
|
||||
this.disposables.push(this.versionStatus);
|
||||
|
||||
@@ -96,15 +95,9 @@ export default class TypeScriptServiceClientHost {
|
||||
this.ataProgressReporter = new AtaProgressReporter(this.client);
|
||||
this.fileConfigurationManager = new FileConfigurationManager(this.client);
|
||||
|
||||
const allModeIds: string[] = [];
|
||||
for (const description of descriptions) {
|
||||
allModeIds.push(...description.modeIds);
|
||||
}
|
||||
this.bufferSyncSupport = new BufferSyncSupport(this.client, allModeIds);
|
||||
this.client.onReady(() => { this.bufferSyncSupport.listen(); });
|
||||
|
||||
for (const description of descriptions) {
|
||||
const manager = new LanguageProvider(this.client, description, this.commandManager, this.client.telemetryReporter, this.typingsStatus, this.fileConfigurationManager, this.bufferSyncSupport);
|
||||
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);
|
||||
@@ -130,7 +123,7 @@ export default class TypeScriptServiceClientHost {
|
||||
diagnosticOwner: 'typescript',
|
||||
isExternal: true
|
||||
};
|
||||
const manager = new LanguageProvider(this.client, description, this.commandManager, this.client.telemetryReporter, this.typingsStatus, this.fileConfigurationManager, this.bufferSyncSupport);
|
||||
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);
|
||||
@@ -145,12 +138,19 @@ export default class TypeScriptServiceClientHost {
|
||||
this.configurationChanged();
|
||||
}
|
||||
|
||||
private getAllModeIds(descriptions: LanguageDescription[]) {
|
||||
const allModeIds: string[] = [];
|
||||
for (const description of descriptions) {
|
||||
allModeIds.push(...description.modeIds);
|
||||
}
|
||||
return allModeIds;
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
disposeAll(this.disposables);
|
||||
this.typingsStatus.dispose();
|
||||
this.ataProgressReporter.dispose();
|
||||
this.fileConfigurationManager.dispose();
|
||||
this.bufferSyncSupport.dispose();
|
||||
}
|
||||
|
||||
public get serviceClient(): TypeScriptServiceClient {
|
||||
@@ -189,8 +189,8 @@ export default class TypeScriptServiceClientHost {
|
||||
|
||||
private populateService(): void {
|
||||
this.fileConfigurationManager.reset();
|
||||
this.bufferSyncSupport.reOpenDocuments();
|
||||
this.bufferSyncSupport.requestAllDiagnostics();
|
||||
this.client.bufferSyncSupport.reOpenDocuments();
|
||||
this.client.bufferSyncSupport.requestAllDiagnostics();
|
||||
|
||||
// See https://github.com/Microsoft/TypeScript/issues/5530
|
||||
workspace.saveAll(false).then(() => {
|
||||
@@ -314,4 +314,4 @@ export default class TypeScriptServiceClientHost {
|
||||
private isStyleCheckDiagnostic(code: number | undefined): boolean {
|
||||
return code ? styleCheckDiagnostics.indexOf(code) !== -1 : false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import API from './utils/api';
|
||||
import { TypeScriptServerPlugin } from './utils/plugins';
|
||||
import { TypeScriptServiceConfiguration } from './utils/configuration';
|
||||
import Logger from './utils/logger';
|
||||
import BufferSyncSupport from './features/bufferSyncSupport';
|
||||
|
||||
export interface ITypeScriptServiceClient {
|
||||
/**
|
||||
@@ -32,16 +33,17 @@ export interface ITypeScriptServiceClient {
|
||||
|
||||
getWorkspaceRootForResource(resource: Uri): string | undefined;
|
||||
|
||||
onTsServerStarted: Event<API>;
|
||||
onProjectLanguageServiceStateChanged: Event<Proto.ProjectLanguageServiceStateEventBody>;
|
||||
onDidBeginInstallTypings: Event<Proto.BeginInstallTypesEventBody>;
|
||||
onDidEndInstallTypings: Event<Proto.EndInstallTypesEventBody>;
|
||||
onTypesInstallerInitializationFailed: Event<Proto.TypesInstallerInitializationFailedEventBody>;
|
||||
readonly onTsServerStarted: Event<API>;
|
||||
readonly onProjectLanguageServiceStateChanged: Event<Proto.ProjectLanguageServiceStateEventBody>;
|
||||
readonly onDidBeginInstallTypings: Event<Proto.BeginInstallTypesEventBody>;
|
||||
readonly onDidEndInstallTypings: Event<Proto.EndInstallTypesEventBody>;
|
||||
readonly onTypesInstallerInitializationFailed: Event<Proto.TypesInstallerInitializationFailedEventBody>;
|
||||
|
||||
apiVersion: API;
|
||||
plugins: TypeScriptServerPlugin[];
|
||||
configuration: TypeScriptServiceConfiguration;
|
||||
logger: Logger;
|
||||
readonly apiVersion: API;
|
||||
readonly plugins: TypeScriptServerPlugin[];
|
||||
readonly configuration: TypeScriptServiceConfiguration;
|
||||
readonly logger: Logger;
|
||||
readonly bufferSyncSupport: BufferSyncSupport;
|
||||
|
||||
execute(command: 'configure', args: Proto.ConfigureRequestArguments, token?: CancellationToken): Promise<Proto.ConfigureResponse>;
|
||||
execute(command: 'open', args: Proto.OpenRequestArgs, expectedResult: boolean, token?: CancellationToken): Promise<any>;
|
||||
|
||||
@@ -31,6 +31,7 @@ import LogDirectoryProvider from './utils/logDirectoryProvider';
|
||||
import { disposeAll } from './utils/dispose';
|
||||
import { DiagnosticKind } from './features/diagnostics';
|
||||
import { TypeScriptPluginPathsProvider } from './utils/pluginPathsProvider';
|
||||
import BufferSyncSupport from './features/bufferSyncSupport';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
@@ -198,11 +199,14 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
|
||||
|
||||
private readonly disposables: Disposable[] = [];
|
||||
|
||||
public readonly bufferSyncSupport: BufferSyncSupport;
|
||||
|
||||
constructor(
|
||||
private readonly workspaceState: Memento,
|
||||
private readonly onDidChangeTypeScriptVersion: (version: TypeScriptVersion) => void,
|
||||
public readonly plugins: TypeScriptServerPlugin[],
|
||||
private readonly logDirectoryProvider: LogDirectoryProvider
|
||||
private readonly logDirectoryProvider: LogDirectoryProvider,
|
||||
allModeIds: string[]
|
||||
) {
|
||||
this.pathSeparator = path.sep;
|
||||
this.lastStart = Date.now();
|
||||
@@ -227,6 +231,9 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
|
||||
this._tsserverVersion = undefined;
|
||||
this.tracer = new Tracer(this.logger);
|
||||
|
||||
this.bufferSyncSupport = new BufferSyncSupport(this, allModeIds);
|
||||
this.onReady(() => { this.bufferSyncSupport.listen(); });
|
||||
|
||||
workspace.onDidChangeConfiguration(() => {
|
||||
const oldConfiguration = this._configuration;
|
||||
this._configuration = TypeScriptServiceConfiguration.loadFromWorkspace();
|
||||
@@ -265,6 +272,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
this.bufferSyncSupport.dispose();
|
||||
this._onTsServerStarted.dispose();
|
||||
this._onDidBeginInstallTypings.dispose();
|
||||
this._onDidEndInstallTypings.dispose();
|
||||
@@ -304,9 +312,6 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
|
||||
return this._onTsServerStarted.event;
|
||||
}
|
||||
|
||||
private readonly _onProjectUpdatedInBackground = new EventEmitter<Proto.ProjectsUpdatedInBackgroundEventBody>();
|
||||
public readonly onProjectUpdatedInBackground = this._onProjectUpdatedInBackground.event;
|
||||
|
||||
private readonly _onProjectLanguageServiceStateChanged = new EventEmitter<Proto.ProjectLanguageServiceStateEventBody>();
|
||||
public readonly onProjectLanguageServiceStateChanged = this._onProjectLanguageServiceStateChanged.event;
|
||||
|
||||
@@ -663,7 +668,9 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
|
||||
return resource;
|
||||
}
|
||||
}
|
||||
return Uri.file(filepath);
|
||||
const resource = Uri.file(filepath);
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
public getWorkspaceRootForResource(resource: Uri): string | undefined {
|
||||
@@ -878,7 +885,9 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
|
||||
|
||||
case 'projectsUpdatedInBackground':
|
||||
if (event.body) {
|
||||
this._onProjectUpdatedInBackground.fire((event as Proto.ProjectsUpdatedInBackgroundEvent).body);
|
||||
const body = (event as Proto.ProjectsUpdatedInBackgroundEvent).body;
|
||||
const resources = body.openFiles.map(Uri.file);
|
||||
this.bufferSyncSupport.getErr(resources);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user