mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 12:19:20 +00:00
Make CachedResponse generic
This commit is contained in:
@@ -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> {
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user