提交 02a59c30 编写于 作者: M Matt Bierner

Make CachedResponse generic

上级 fabc6276
...@@ -9,7 +9,6 @@ import { ITypeScriptServiceClient, ServerResponse } from '../typescriptService'; ...@@ -9,7 +9,6 @@ import { ITypeScriptServiceClient, ServerResponse } from '../typescriptService';
import { escapeRegExp } from '../utils/regexp'; import { escapeRegExp } from '../utils/regexp';
import * as typeConverters from '../utils/typeConverters'; import * as typeConverters from '../utils/typeConverters';
export class ReferencesCodeLens extends vscode.CodeLens { export class ReferencesCodeLens extends vscode.CodeLens {
constructor( constructor(
public document: vscode.Uri, public document: vscode.Uri,
...@@ -20,14 +19,14 @@ export class ReferencesCodeLens extends vscode.CodeLens { ...@@ -20,14 +19,14 @@ export class ReferencesCodeLens extends vscode.CodeLens {
} }
} }
export class CachedNavTreeResponse { export class CachedResponse<T extends Proto.Response> {
private response?: Promise<ServerResponse<Proto.NavTreeResponse>>; private response?: Promise<ServerResponse<T>>;
private version: number = -1; private version: number = -1;
private document: string = ''; private document: string = '';
public execute( public execute(
document: vscode.TextDocument, document: vscode.TextDocument,
f: () => Promise<ServerResponse<Proto.NavTreeResponse>> f: () => Promise<ServerResponse<T>>
) { ) {
if (this.matches(document)) { if (this.matches(document)) {
return this.response; return this.response;
...@@ -42,8 +41,8 @@ export class CachedNavTreeResponse { ...@@ -42,8 +41,8 @@ export class CachedNavTreeResponse {
private update( private update(
document: vscode.TextDocument, document: vscode.TextDocument,
response: Promise<ServerResponse<Proto.NavTreeResponse>> response: Promise<ServerResponse<T>>
): Promise<ServerResponse<Proto.NavTreeResponse>> { ): Promise<ServerResponse<T>> {
this.response = response; this.response = response;
this.version = document.version; this.version = document.version;
this.document = document.uri.toString(); this.document = document.uri.toString();
...@@ -56,7 +55,7 @@ export abstract class TypeScriptBaseCodeLensProvider implements vscode.CodeLensP ...@@ -56,7 +55,7 @@ export abstract class TypeScriptBaseCodeLensProvider implements vscode.CodeLensP
public constructor( public constructor(
protected client: ITypeScriptServiceClient, protected client: ITypeScriptServiceClient,
private cachedResponse: CachedNavTreeResponse private cachedResponse: CachedResponse<Proto.NavTreeResponse>
) { } ) { }
public get onDidChangeCodeLenses(): vscode.Event<void> { public get onDidChangeCodeLenses(): vscode.Event<void> {
......
...@@ -78,7 +78,7 @@ export function register( ...@@ -78,7 +78,7 @@ export function register(
selector: vscode.DocumentSelector, selector: vscode.DocumentSelector,
modeId: string, modeId: string,
client: ITypeScriptServiceClient, client: ITypeScriptServiceClient,
cachedResponse: CachedNavTreeResponse, cachedResponse: CachedResponse<Proto.NavTreeResponse>,
) { ) {
return new VersionDependentRegistration(client, API.v220, () => return new VersionDependentRegistration(client, API.v220, () =>
new ConfigurationDependentRegistration(modeId, 'implementationsCodeLens.enabled', () => { new ConfigurationDependentRegistration(modeId, 'implementationsCodeLens.enabled', () => {
......
...@@ -90,7 +90,7 @@ export function register( ...@@ -90,7 +90,7 @@ export function register(
selector: vscode.DocumentSelector, selector: vscode.DocumentSelector,
modeId: string, modeId: string,
client: ITypeScriptServiceClient, client: ITypeScriptServiceClient,
cachedResponse: CachedNavTreeResponse, cachedResponse: CachedResponse<Proto.NavTreeResponse>,
) { ) {
return new VersionDependentRegistration(client, API.v206, () => return new VersionDependentRegistration(client, API.v206, () =>
new ConfigurationDependentRegistration(modeId, 'referencesCodeLens.enabled', () => { new ConfigurationDependentRegistration(modeId, 'referencesCodeLens.enabled', () => {
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import { basename } from 'path'; import { basename } from 'path';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { CachedNavTreeResponse } from './features/baseCodeLensProvider'; import { CachedResponse } from './features/baseCodeLensProvider';
import { DiagnosticKind } from './features/diagnostics'; import { DiagnosticKind } from './features/diagnostics';
import FileConfigurationManager from './features/fileConfigurationManager'; import FileConfigurationManager from './features/fileConfigurationManager';
import TypeScriptServiceClient from './typescriptServiceClient'; import TypeScriptServiceClient from './typescriptServiceClient';
...@@ -53,7 +53,7 @@ export default class LanguageProvider extends Disposable { ...@@ -53,7 +53,7 @@ export default class LanguageProvider extends Disposable {
private async registerProviders(): Promise<void> { private async registerProviders(): Promise<void> {
const selector = this.documentSelector; const selector = this.documentSelector;
const cachedResponse = new CachedNavTreeResponse(); const cachedResponse = new CachedResponse();
this._register((await import('./features/completions')).register(selector, this.description.id, this.client, this.typingsStatus, this.fileConfigurationManager, this.commandManager, this.onCompletionAccepted)); this._register((await import('./features/completions')).register(selector, this.description.id, this.client, this.typingsStatus, this.fileConfigurationManager, this.commandManager, this.onCompletionAccepted));
this._register((await import('./features/definitions')).register(selector, this.client)); this._register((await import('./features/definitions')).register(selector, this.client));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册