use Dto<T> util in more places, some clean-up/alignment of caching logic

This commit is contained in:
Johannes Rieken
2022-01-19 15:12:08 +01:00
parent dcc6643fd7
commit 15db136c3c
5 changed files with 60 additions and 118 deletions

View File

@@ -68,6 +68,7 @@ import { createProxyIdentifier, Dto, IRPCProtocol, SerializableObjectWithBuffers
import { ILanguageStatus } from 'vs/workbench/services/languageStatus/common/languageStatusService';
import { CandidatePort } from 'vs/workbench/services/remote/common/remoteExplorerService';
import * as search from 'vs/workbench/services/search/common/search';
import { IWorkspaceSymbol } from 'vs/workbench/contrib/search/common/search';
export interface IEnvironment {
isExtensionDevelopmentDebug: boolean;
@@ -1426,21 +1427,6 @@ export interface ExtHostLanguagesShape {
$acceptLanguageIds(ids: string[]): void;
}
export interface ObjectIdentifier {
$ident?: number;
}
export namespace ObjectIdentifier {
export const name = '$ident';
export function mixin<T>(obj: T, id: number): T & ObjectIdentifier {
Object.defineProperty(obj, name, { value: id, enumerable: true });
return <T & ObjectIdentifier>obj;
}
export function of(obj: any): number {
return obj[name];
}
}
export interface ExtHostHeapServiceShape {
$onGarbageCollection(ids: number[]): void;
}
@@ -1523,43 +1509,15 @@ export interface ISignatureHelpContextDto {
readonly activeSignatureHelp: ISignatureHelpDto | undefined;
}
export interface IInlayHintDto {
cacheId?: ChainedCacheId;
label: string | Dto<modes.InlayHintLabelPart[]>;
tooltip?: string | IMarkdownString;
position: IPosition;
kind: modes.InlayHintKind;
whitespaceBefore?: boolean;
whitespaceAfter?: boolean;
}
export type IInlayHintDto = CachedSessionItem<Dto<modes.InlayHint>>;
export interface IInlayHintsDto {
cacheId?: CacheId;
hints: IInlayHintDto[];
}
export type IInlayHintsDto = CachedSession<{ hints: IInlayHintDto[]; }>;
export interface ILocationDto {
uri: UriComponents;
range: IRange;
}
export type ILocationDto = Dto<modes.Location>;
export type ILocationLinkDto = Dto<modes.LocationLink>;
export interface IDefinitionLinkDto {
originSelectionRange?: IRange;
uri: UriComponents;
range: IRange;
targetSelectionRange?: IRange;
}
export interface IWorkspaceSymbolDto extends IdObject {
name: string;
containerName?: string;
kind: modes.SymbolKind;
location: ILocationDto;
}
export interface IWorkspaceSymbolsDto extends IdObject {
symbols: IWorkspaceSymbolDto[];
}
export type IWorkspaceSymbolDto = CachedSessionItem<Dto<IWorkspaceSymbol>>;
export type IWorkspaceSymbolsDto = CachedSession<{ symbols: IWorkspaceSymbolDto[]; }>;
export interface IWorkspaceEditEntryMetadataDto {
needsConfirmation: boolean;
@@ -1629,7 +1587,7 @@ export function reviveWorkspaceEditDto(data: IWorkspaceEditDto | undefined): mod
return <modes.WorkspaceEdit>data;
}
export type ICommandDto = ObjectIdentifier & modes.Command;
export type ICommandDto = { $ident?: number; } & modes.Command;
export interface ICodeActionDto {
cacheId?: ChainedCacheId;
@@ -1655,28 +1613,14 @@ export interface ICodeActionProviderMetadataDto {
export type CacheId = number;
export type ChainedCacheId = [CacheId, CacheId];
export interface ILinksListDto {
id?: CacheId;
links: ILinkDto[];
}
type CachedSessionItem<T> = T & { cacheId?: ChainedCacheId };
type CachedSession<T> = T & { cacheId?: CacheId };
export interface ILinkDto {
cacheId?: ChainedCacheId;
range: IRange;
url?: string | UriComponents;
tooltip?: string;
}
export type ILinksListDto = CachedSession<{ links: ILinkDto[]; }>;
export type ILinkDto = CachedSessionItem<Dto<modes.ILink>>;
export interface ICodeLensListDto {
cacheId?: number;
lenses: ICodeLensDto[];
}
export interface ICodeLensDto {
cacheId?: ChainedCacheId;
range: IRange;
command?: ICommandDto;
}
export type ICodeLensListDto = CachedSession<{ lenses: ICodeLensDto[]; }>;
export type ICodeLensDto = CachedSessionItem<Dto<modes.CodeLens>>;
export type ICallHierarchyItemDto = Dto<CallHierarchyItem>;
@@ -1713,10 +1657,10 @@ export interface ExtHostLanguageFeaturesShape {
$provideCodeLenses(handle: number, resource: UriComponents, token: CancellationToken): Promise<ICodeLensListDto | undefined>;
$resolveCodeLens(handle: number, symbol: ICodeLensDto, token: CancellationToken): Promise<ICodeLensDto | undefined>;
$releaseCodeLenses(handle: number, id: number): void;
$provideDefinition(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<IDefinitionLinkDto[]>;
$provideDeclaration(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<IDefinitionLinkDto[]>;
$provideImplementation(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<IDefinitionLinkDto[]>;
$provideTypeDefinition(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<IDefinitionLinkDto[]>;
$provideDefinition(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<ILocationLinkDto[]>;
$provideDeclaration(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<ILocationLinkDto[]>;
$provideImplementation(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<ILocationLinkDto[]>;
$provideTypeDefinition(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<ILocationLinkDto[]>;
$provideHover(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<modes.Hover | undefined>;
$provideEvaluatableExpression(handle: number, resource: UriComponents, position: IPosition, token: CancellationToken): Promise<modes.EvaluatableExpression | undefined>;
$provideInlineValues(handle: number, resource: UriComponents, range: IRange, context: modes.InlineValueContext, token: CancellationToken): Promise<modes.InlineValue[] | undefined>;

View File

@@ -8,7 +8,7 @@ import { ICommandHandlerDescription } from 'vs/platform/commands/common/commands
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
import * as extHostTypeConverter from 'vs/workbench/api/common/extHostTypeConverters';
import { cloneAndChange } from 'vs/base/common/objects';
import { MainContext, MainThreadCommandsShape, ExtHostCommandsShape, ObjectIdentifier, ICommandDto, ICommandHandlerDescriptionDto } from './extHost.protocol';
import { MainContext, MainThreadCommandsShape, ExtHostCommandsShape, ICommandDto, ICommandHandlerDescriptionDto } from './extHost.protocol';
import { isNonEmptyArray } from 'vs/base/common/arrays';
import * as modes from 'vs/editor/common/languages';
import type * as vscode from 'vscode';
@@ -355,11 +355,10 @@ export class CommandsConverter {
return result;
}
fromInternal(command: modes.Command): vscode.Command | undefined {
fromInternal(command: ICommandDto): vscode.Command | undefined {
const id = ObjectIdentifier.of(command);
if (typeof id === 'number') {
return this._cache.get(id);
if (typeof command.$ident === 'number') {
return this._cache.get(command.$ident);
} else {
return {

View File

@@ -550,8 +550,7 @@ class OnTypeFormattingAdapter {
class NavigateTypeAdapter {
private readonly _symbolCache = new Map<number, vscode.SymbolInformation>();
private readonly _resultCache = new Map<number, [number, number]>();
private readonly _cache = new Cache<vscode.SymbolInformation>('WorkspaceSymbols');
constructor(
private readonly _provider: vscode.WorkspaceSymbolProvider,
@@ -559,26 +558,30 @@ class NavigateTypeAdapter {
) { }
async provideWorkspaceSymbols(search: string, token: CancellationToken): Promise<extHostProtocol.IWorkspaceSymbolsDto> {
const result: extHostProtocol.IWorkspaceSymbolsDto = extHostProtocol.IdObject.mixin({ symbols: [] });
const value = await this._provider.provideWorkspaceSymbols(search, token);
if (isNonEmptyArray(value)) {
for (const item of value) {
if (!item) {
// drop
continue;
}
if (!item.name) {
this._logService.warn('INVALID SymbolInformation, lacks name', item);
continue;
}
const symbol = extHostProtocol.IdObject.mixin(typeConvert.WorkspaceSymbol.from(item));
this._symbolCache.set(symbol._id!, item);
result.symbols.push(symbol);
if (!isNonEmptyArray(value)) {
return { symbols: [] };
}
const sid = this._cache.add(value);
const result: extHostProtocol.IWorkspaceSymbolsDto = {
cacheId: sid,
symbols: []
};
for (let i = 0; i < value.length; i++) {
const item = value[i];
if (!item || !item.name) {
this._logService.warn('INVALID SymbolInformation', item);
continue;
}
result.symbols.push({
...typeConvert.WorkspaceSymbol.from(item),
cacheId: [sid, i]
});
}
if (result.symbols.length > 0) {
this._resultCache.set(result._id!, [result.symbols[0]._id!, result.symbols[result.symbols.length - 1]._id!]);
}
return result;
}
@@ -586,8 +589,10 @@ class NavigateTypeAdapter {
if (typeof this._provider.resolveWorkspaceSymbol !== 'function') {
return symbol;
}
const item = this._symbolCache.get(symbol._id!);
if (!symbol.cacheId) {
return symbol;
}
const item = this._cache.get(...symbol.cacheId);
if (item) {
const value = await this._provider.resolveWorkspaceSymbol(item, token);
return value && mixin(symbol, typeConvert.WorkspaceSymbol.from(value), true);
@@ -596,13 +601,7 @@ class NavigateTypeAdapter {
}
releaseWorkspaceSymbols(id: number): any {
const range = this._resultCache.get(id);
if (range) {
for (let [from, to] = range; from <= to; from++) {
this._symbolCache.delete(from);
}
this._resultCache.delete(id);
}
this._cache.delete(id);
}
}
@@ -1260,8 +1259,8 @@ class InlayHintsAdapter {
tooltip: hint.tooltip && typeConvert.MarkdownString.from(hint.tooltip),
position: typeConvert.Position.from(hint.position),
kind: typeConvert.InlayHintKind.from(hint.kind ?? InlayHintKind.Other),
whitespaceBefore: hint.paddingLeft,
whitespaceAfter: hint.paddingRight,
paddingLeft: hint.paddingLeft,
paddingRight: hint.paddingRight,
};
if (typeof hint.label === 'string') {
@@ -1311,7 +1310,7 @@ class LinkProviderAdapter {
} else {
// cache links for future resolving
const pid = this._cache.add(links);
const result: extHostProtocol.ILinksListDto = { links: [], id: pid };
const result: extHostProtocol.ILinksListDto = { links: [], cacheId: pid };
for (let i = 0; i < links.length; i++) {
if (!LinkProviderAdapter._validateLink(links[i])) {

View File

@@ -834,7 +834,7 @@ export namespace DefinitionLink {
: undefined,
};
}
export function to(value: extHostProtocol.IDefinitionLinkDto): vscode.LocationLink {
export function to(value: extHostProtocol.ILocationLinkDto): vscode.LocationLink {
return {
targetUri: URI.revive(value.uri),
targetRange: Range.to(value.range),