mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-23 19:59:37 +00:00
Extract cached response to own file
This commit is contained in:
@@ -6,9 +6,10 @@
|
||||
import * as vscode from 'vscode';
|
||||
import * as nls from 'vscode-nls';
|
||||
import * as Proto from '../protocol';
|
||||
import { ITypeScriptServiceClient, ServerResponse } from '../typescriptService';
|
||||
import { ITypeScriptServiceClient } from '../typescriptService';
|
||||
import { escapeRegExp } from '../utils/regexp';
|
||||
import * as typeConverters from '../utils/typeConverters';
|
||||
import { CachedResponse } from '../tsServer/cachedResponse';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
@@ -22,37 +23,6 @@ export class ReferencesCodeLens extends vscode.CodeLens {
|
||||
}
|
||||
}
|
||||
|
||||
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<T>>
|
||||
) {
|
||||
if (this.matches(document)) {
|
||||
return this.response;
|
||||
}
|
||||
|
||||
return this.update(document, f());
|
||||
}
|
||||
|
||||
private matches(document: vscode.TextDocument): boolean {
|
||||
return this.version === document.version && this.document === document.uri.toString();
|
||||
}
|
||||
|
||||
private update(
|
||||
document: vscode.TextDocument,
|
||||
response: Promise<ServerResponse<T>>
|
||||
): Promise<ServerResponse<T>> {
|
||||
this.response = response;
|
||||
this.version = document.version;
|
||||
this.document = document.uri.toString();
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class TypeScriptBaseCodeLensProvider implements vscode.CodeLensProvider {
|
||||
|
||||
public static readonly cancelledCommand: vscode.Command = {
|
||||
|
||||
@@ -8,7 +8,7 @@ import * as Proto from '../protocol';
|
||||
import * as PConst from '../protocol.const';
|
||||
import { ITypeScriptServiceClient } from '../typescriptService';
|
||||
import * as typeConverters from '../utils/typeConverters';
|
||||
import { CachedResponse } from './baseCodeLensProvider';
|
||||
import { CachedResponse } from '../tsServer/cachedResponse';
|
||||
|
||||
const getSymbolKind = (kind: string): vscode.SymbolKind => {
|
||||
switch (kind) {
|
||||
|
||||
@@ -10,7 +10,8 @@ import * as PConst from '../protocol.const';
|
||||
import { ITypeScriptServiceClient } from '../typescriptService';
|
||||
import API from '../utils/api';
|
||||
import { ConfigurationDependentRegistration, VersionDependentRegistration } from '../utils/dependentRegistration';
|
||||
import { TypeScriptBaseCodeLensProvider, ReferencesCodeLens, getSymbolRange, CachedResponse } from './baseCodeLensProvider';
|
||||
import { TypeScriptBaseCodeLensProvider, ReferencesCodeLens, getSymbolRange } from './baseCodeLensProvider';
|
||||
import { CachedResponse } from '../tsServer/cachedResponse';
|
||||
import * as typeConverters from '../utils/typeConverters';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
@@ -11,7 +11,8 @@ import { ITypeScriptServiceClient } from '../typescriptService';
|
||||
import API from '../utils/api';
|
||||
import { ConfigurationDependentRegistration, VersionDependentRegistration } from '../utils/dependentRegistration';
|
||||
import * as typeConverters from '../utils/typeConverters';
|
||||
import { ReferencesCodeLens, TypeScriptBaseCodeLensProvider, getSymbolRange, CachedResponse } from './baseCodeLensProvider';
|
||||
import { ReferencesCodeLens, TypeScriptBaseCodeLensProvider, getSymbolRange } from './baseCodeLensProvider';
|
||||
import { CachedResponse } from '../tsServer/cachedResponse';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { basename } from 'path';
|
||||
import * as vscode from 'vscode';
|
||||
import { CachedResponse } from './features/baseCodeLensProvider';
|
||||
import { CachedResponse } from './tsServer/cachedResponse';
|
||||
import { DiagnosticKind } from './features/diagnostics';
|
||||
import FileConfigurationManager from './features/fileConfigurationManager';
|
||||
import TypeScriptServiceClient from './typescriptServiceClient';
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as Proto from '../protocol';
|
||||
import { ServerResponse } from '../typescriptService';
|
||||
|
||||
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<T>>) {
|
||||
if (this.matches(document)) {
|
||||
return this.response;
|
||||
}
|
||||
return this.update(document, f());
|
||||
}
|
||||
|
||||
private matches(document: vscode.TextDocument): boolean {
|
||||
return this.version === document.version && this.document === document.uri.toString();
|
||||
}
|
||||
|
||||
private update(document: vscode.TextDocument, response: Promise<ServerResponse<T>>): Promise<ServerResponse<T>> {
|
||||
this.response = response;
|
||||
this.version = document.version;
|
||||
this.document = document.uri.toString();
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user