Make CachedResponse generic

This commit is contained in:
Matt Bierner
2018-11-19 18:47:28 -08:00
parent fabc627634
commit 02a59c3015
4 changed files with 10 additions and 11 deletions

View File

@@ -9,7 +9,6 @@ import { ITypeScriptServiceClient, ServerResponse } from '../typescriptService';
import { escapeRegExp } from '../utils/regexp';
import * as typeConverters from '../utils/typeConverters';
export class ReferencesCodeLens extends vscode.CodeLens {
constructor(
public document: vscode.Uri,
@@ -20,14 +19,14 @@ export class ReferencesCodeLens extends vscode.CodeLens {
}
}
export class CachedNavTreeResponse {
private response?: Promise<ServerResponse<Proto.NavTreeResponse>>;
export class CachedResponse<T extends Proto.Response> {
private response?: Promise<ServerResponse<T>>;
private version: number = -1;
private document: string = '';
public execute(
document: vscode.TextDocument,
f: () => Promise<ServerResponse<Proto.NavTreeResponse>>
f: () => Promise<ServerResponse<T>>
) {
if (this.matches(document)) {
return this.response;
@@ -42,8 +41,8 @@ export class CachedNavTreeResponse {
private update(
document: vscode.TextDocument,
response: Promise<ServerResponse<Proto.NavTreeResponse>>
): Promise<ServerResponse<Proto.NavTreeResponse>> {
response: Promise<ServerResponse<T>>
): Promise<ServerResponse<T>> {
this.response = response;
this.version = document.version;
this.document = document.uri.toString();
@@ -56,7 +55,7 @@ export abstract class TypeScriptBaseCodeLensProvider implements vscode.CodeLensP
public constructor(
protected client: ITypeScriptServiceClient,
private cachedResponse: CachedNavTreeResponse
private cachedResponse: CachedResponse<Proto.NavTreeResponse>
) { }
public get onDidChangeCodeLenses(): vscode.Event<void> {

View File

@@ -78,7 +78,7 @@ export function register(
selector: vscode.DocumentSelector,
modeId: string,
client: ITypeScriptServiceClient,
cachedResponse: CachedNavTreeResponse,
cachedResponse: CachedResponse<Proto.NavTreeResponse>,
) {
return new VersionDependentRegistration(client, API.v220, () =>
new ConfigurationDependentRegistration(modeId, 'implementationsCodeLens.enabled', () => {

View File

@@ -90,7 +90,7 @@ export function register(
selector: vscode.DocumentSelector,
modeId: string,
client: ITypeScriptServiceClient,
cachedResponse: CachedNavTreeResponse,
cachedResponse: CachedResponse<Proto.NavTreeResponse>,
) {
return new VersionDependentRegistration(client, API.v206, () =>
new ConfigurationDependentRegistration(modeId, 'referencesCodeLens.enabled', () => {

View File

@@ -5,7 +5,7 @@
import { basename } from 'path';
import * as vscode from 'vscode';
import { CachedNavTreeResponse } from './features/baseCodeLensProvider';
import { CachedResponse } from './features/baseCodeLensProvider';
import { DiagnosticKind } from './features/diagnostics';
import FileConfigurationManager from './features/fileConfigurationManager';
import TypeScriptServiceClient from './typescriptServiceClient';
@@ -53,7 +53,7 @@ export default class LanguageProvider extends Disposable {
private async registerProviders(): Promise<void> {
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/definitions')).register(selector, this.client));