src/vs/base/common/cache.ts

153 LOC · 130 covered · 23 uncovered · 19 ranges · 16824 concepts · 8 introducers · 10556 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filesrc/vs/base/common/strings.ts · 1413 LOCcommon/strings.tssrc/vs/editor/common/languages/languageConfigurationRegistry.ts · 477 LOClanguages/languageConfig…src/vs/editor/common/languages/supports/languageBracketsConfiguration.ts · 168 LOCsupports/languageBracket…promptsServiceImpl.ts ×1 · 4 introduced LOCpromptsServiceImpl.ts ×1tokenizer.ts ×1 · 4 introduced LOCtokenizer.ts ×1smallImmutableSet.ts ×2 · 12 introduced LOCsmallImmutableSet.ts ×2tokenizer.ts ×4 · 26 introduced LOCtokenizer.ts ×4textModelWithTokens.test|title=TextModelWithTokens regression tests issue #11856: Bracket matching does not work as expected if the opening brace symbol is contained in the closing brace symbol|occurrence=1 · 0 introduced LOCtextModelWithTokens.test…tokenizer.ts ×1 · 3 introduced LOCtokenizer.ts ×1tokenizer.ts ×2 · 6 introduced LOCtokenizer.ts ×2bracketPairsTree.ts ×6 · 93 introduced LOCbracketPairsTree.ts ×6bracketPairsImpl.ts ×1 · 1 introduced LOCbracketPairsImpl.ts ×1bracketPairsImpl.ts ×2 · 9 introduced LOCbracketPairsImpl.ts ×2brackets.ts ×2 · 4 introduced LOCbrackets.ts ×2textModelWithTokens.test|title=TextModel.getLineIndentGuide issue #49173|occurrence=1 · 0 introduced LOCtextModelWithTokens.test…unicodeTextModelHighlighter.ts ×19 · 133 introduced LOCunicodeTextModelHighligh…languageBracketsConfiguration.ts ×1 · 1 introduced LOClanguageBracketsConfigur…chatModel.test|title=ChatModel addCompleteRequest|occurrence=1 · 0 introduced LOCchatModel.test|title=Cha…brackets.ts ×1 · 3 introduced LOCbrackets.ts ×1brackets.ts ×1 · 2 introduced LOCbrackets.ts ×1languageBracketsConfiguration.ts ×4 · 29 introduced LOClanguageBracketsConfigur…cache.ts ×1 · 2 introduced LOCcache.ts ×1languageBracketsConfiguration.ts ×1 · 7 introduced LOClanguageBracketsConfigur…languageBracketsConfiguration.ts ×7 · 50 introduced LOClanguageBracketsConfigur…languageConfigurationRegistry.ts ×1 · 2 introduced LOClanguageConfigurationReg…serverAgentHostManager.ts ×7 · 138 introduced LOCserverAgentHostManager.t…unicodeTextModelHighlighter.ts ×8 · 65 introduced LOCunicodeTextModelHighligh…languageBracketsConfiguration.ts ×1 · 5 introduced LOClanguageBracketsConfigur…range.ts ×1 · 2 introduced LOCrange.ts ×1languageConfigurationRegistry.ts ×4 · 47 introduced LOClanguageConfigurationReg…testLanguageConfigurationService.ts ×2 · 2 introduced LOCtestLanguageConfiguratio…languageConfigurationRegistry.ts ×1 · 2 introduced LOClanguageConfigurationReg…languageConfigurationRegistry.ts ×7 · 52 introduced LOClanguageConfigurationReg…cache.ts ×1 · 4 introduced LOCcache.ts ×1cache.ts ×2 · 14 introduced LOCcache.ts ×2testLineToken.ts ×26 · 79 introduced LOCtestLineToken.ts ×26agentService.ts ×15 · 2049 introduced LOCagentService.ts ×15range.ts ×2 · 3 introduced LOCrange.ts ×2textLength.ts ×21 · 60 introduced LOCtextLength.ts ×21textModelSearch.ts ×26 · 132 introduced LOCtextModelSearch.ts ×26offsetRange.ts ×2 · 2 introduced LOCoffsetRange.ts ×2stringBuilder.ts ×14 · 49 introduced LOCstringBuilder.ts ×14hash.ts ×17 · 74 introduced LOChash.ts ×17filters.ts ×3 · 7 introduced LOCfilters.ts ×3filters.ts ×47 · 212 introduced LOCfilters.ts ×47wordHelper.ts ×5 · 70 introduced LOCwordHelper.ts ×5strings.ts ×2 · 10 introduced LOCstrings.ts ×2strings.ts ×5 · 65 introduced LOCstrings.ts ×5cache.ts ×1 · 2 introduced LOCcache.ts ×1network.ts ×20 · 292 introduced LOCnetwork.ts ×20strings.test|title=Strings trimWhitespace|occurrence=1 · 0 introduced LOCstrings.test|title=Strin…strings.ts ×1 · 2 introduced LOCstrings.ts ×1strings.ts ×2 · 10 introduced LOCstrings.ts ×2strings.ts ×101 · 542 introduced LOCstrings.ts ×101cache.test|title=Cache should retry cancellations|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/cache.test|title=Cache should retry cancellations|occurrence=1cache.test|title=Cache s…cache.test|title=Cache simple error|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/cache.test|title=Cache simple error|occurrence=1cache.test|title=Cache s…cache.test|title=Cache simple value|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/cache.test|title=Cache simple value|occurrence=1cache.test|title=Cache s…filters.test|title=Filters matchesContiguousSubString|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/filters.test|title=Filters matchesContiguousSubString|occurrence=1filters.test|title=Filte…strings.test|title=Strings containsAmbiguousCharacter|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/strings.test|title=Strings containsAmbiguousCharacter|occurrence=1strings.test|title=Strin…strings.test|title=Strings trimWhitespace|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/strings.test|title=Strings trimWhitespace|occurrence=1strings.test|title=Strin…strings.test|title=htmlAttributeEncodeValue|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/strings.test|title=htmlAttributeEncodeValue|occurrence=1strings.test|title=htmlA…brackets.test|title=Bracket Pair Colorizer - Brackets Basic|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/editor/test/common/model/bracketPairColorizer/brackets.test|title=Bracket Pair Colorizer - Brackets Basic|occurrence=1brackets.test|title=Brac…getBracketPairsInRange.test|title=Bracket Pair Colorizer - Tokenizer Basic|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/editor/test/common/model/bracketPairColorizer/getBracketPairsInRange.test|title=Bracket Pair Colorizer - Tokenizer Basic|occurrence=1getBracketPairsInRange.t…textModelWithTokens.test|title=TextModel.getLineIndentGuide issue #49173|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/editor/test/common/model/textModelWithTokens.test|title=TextModel.getLineIndentGuide issue #49173|occurrence=1textModelWithTokens.test…textModelWithTokens.test|title=TextModelWithTokens 2 issue #95843: Highlighting of closing braces is indicating wrong brace when cursor is behind opening brace|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/editor/test/common/model/textModelWithTokens.test|title=TextModelWithTokens 2 issue #95843: Highlighting of closing braces is indicating wrong brace when cursor is behind opening brace|occurrence=1textModelWithTokens.test…textModelWithTokens.test|title=TextModelWithTokens brackets1|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/editor/test/common/model/textModelWithTokens.test|title=TextModelWithTokens brackets1|occurrence=1textModelWithTokens.test…textModelWithTokens.test|title=TextModelWithTokens regression tests issue #11856: Bracket matching does not work as expected if the opening brace symbol is contained in the closing brace symbol|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/editor/test/common/model/textModelWithTokens.test|title=TextModelWithTokens regression tests issue #11856: Bracket matching does not work as expected if the opening brace symbol is contained in the closing brace symbol|occurrence=1textModelWithTokens.test…monaco-editor#133: Error: Cannot read property 'modeId' of undefined|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/editor/test/common/model/textModelWithTokens.test|title=TextModelWithTokens regression tests microsoft/monaco-editor#133: Error: Cannot read property 'modeId' of undefined|occurrence=1monaco-editor#133: Error…unicodeTextModelHighlighter.test|title=UnicodeTextModelHighlighter computeUnicodeHighlights (#168068)|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/editor/test/common/services/unicodeTextModelHighlighter.test|title=UnicodeTextModelHighlighter computeUnicodeHighlights (#168068)|occurrence=1unicodeTextModelHighligh…serverAgentHostManager.test|title=ServerAgentHostManager no lifetime token initially|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverAgentHostManager.test|title=ServerAgentHostManager no lifetime token initially|occurrence=1serverAgentHostManager.t…chatModel.test|title=ChatModel addCompleteRequest|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/chat/test/common/model/chatModel.test|title=ChatModel addCompleteRequest|occurrence=1chatModel.test|title=Cha…promptsService.test|title=PromptsService getCustomAgents body with tool references|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/contrib/chat/test/common/promptSyntax/service/promptsService.test|title=PromptsService getCustomAgents body with tool references|occurrence=1promptsService.test|titl…Focused file · src/vs/base/common/cache.ts · 153 LOCcommon/cache.ts

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- strings.ts ×101
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { CancellationToken, CancellationTokenSource } from './cancellation.js';
7 > import { IDisposable } from './lifecycle.js';
8 >
9 > export interface CacheResult<T> extends IDisposable {
10 > promise: Promise<T>;
11 > }
12 >
13 > export class Cache<T> {
14 >
15 > private result: CacheResult<T> | null = null;
16 > constructor(private task: (ct: CancellationToken) => Promise<T>) { }
17 >
18 > get(): CacheResult<T> {
19 > if (this.result) { cache.ts ×2
20 > return this.result;
21 > }
22 >
23 > const cts = new CancellationTokenSource();
24 > const promise = this.task(cts.token);
25 >
26 > this.result = {
27 > promise,
28 > dispose: () => {
29 > this.result = null; cache.ts ×1
30 > cts.cancel();
31 > cts.dispose();
32 > }
33 > }; cache.ts ×2
34 >
35 > return this.result;
36 > }
38 >
39 > export function identity<T>(t: T): T {
40 > return t; cache.ts ×1
41 > }
43 > interface ICacheOptions<TArg> {
44 > /**
45 > * The cache key is used to identify the cache entry.
46 > * Strict equality is used to compare cache keys.
47 > */
48 > getCacheKey: (arg: TArg) => unknown;
49 > }
50 >
51 > /**
52 > * Uses a LRU cache to make a given parametrized function cached.
53 > * Caches just the last key/value.
54 > */
55 > export class LRUCachedFunction<TArg, TComputed> {
56 > private lastCache: TComputed | undefined = undefined;
57 > private lastArgKey: unknown | undefined = undefined;
58 >
59 > private readonly _fn: (arg: TArg) => TComputed;
60 > private readonly _computeKey: (arg: TArg) => unknown;
61 >
62 > constructor(fn: (arg: TArg) => TComputed);
63 > constructor(options: ICacheOptions<TArg>, fn: (arg: TArg) => TComputed);
64 > constructor(arg1: ICacheOptions<TArg> | ((arg: TArg) => TComputed), arg2?: (arg: TArg) => TComputed) {
65 > if (typeof arg1 === 'function') {
66 > this._fn = arg1;
67 > this._computeKey = identity;
68 > } else {
69 this._fn = arg2!;
70 this._computeKey = arg1.getCacheKey;
71 }
73 >
74 > public get(arg: TArg): TComputed {
75 > const key = this._computeKey(arg); strings.ts ×5
76 > if (this.lastArgKey !== key) {
77 > this.lastArgKey = key;
78 > this.lastCache = this._fn(arg);
79 > }
80 > return this.lastCache!;
81 > }
83 >
84 > /**
85 > * Uses an unbounded cache to memoize the results of the given function.
86 > */
87 > export class CachedFunction<TArg, TComputed> {
88 > private readonly _map = new Map<TArg, TComputed>();
89 > private readonly _map2 = new Map<unknown, TComputed>();
90 > public get cachedValues(): ReadonlyMap<TArg, TComputed> {
91 > return this._map;
92 > }
93 >
94 > private readonly _fn: (arg: TArg) => TComputed;
95 > private readonly _computeKey: (arg: TArg) => unknown;
96 >
97 > constructor(fn: (arg: TArg) => TComputed);
98 > constructor(options: ICacheOptions<TArg>, fn: (arg: TArg) => TComputed);
99 > constructor(arg1: ICacheOptions<TArg> | ((arg: TArg) => TComputed), arg2?: (arg: TArg) => TComputed) {
100 > if (typeof arg1 === 'function') { languageConfigurationRegistry.ts ×7
101 > this._fn = arg1;
102 > this._computeKey = identity;
103 > } else {
104 this._fn = arg2!;
105 this._computeKey = arg1.getCacheKey;
106 }
109 > public get(arg: TArg): TComputed {
110 > const key = this._computeKey(arg); languageBracketsConfiguration.ts ×7
111 > if (this._map2.has(key)) {
112 > return this._map2.get(key)!; cache.ts ×1
113 > }
115 > const value = this._fn(arg);
116 > this._map.set(arg, value);
117 > this._map2.set(key, value);
118 > return value;
119 > }
121 >
122 > /**
123 > * Uses an unbounded cache to memoize the results of the given function.
124 > */
125 > export class WeakCachedFunction<TArg, TComputed> {
126 > private readonly _map = new WeakMap<WeakKey, TComputed>();
127 >
128 > private readonly _fn: (arg: TArg) => TComputed;
129 > private readonly _computeKey: (arg: TArg) => unknown;
130 >
131 > constructor(fn: (arg: TArg) => TComputed);
132 > constructor(options: ICacheOptions<TArg>, fn: (arg: TArg) => TComputed);
133 > constructor(arg1: ICacheOptions<TArg> | ((arg: TArg) => TComputed), arg2?: (arg: TArg) => TComputed) {
134 if (typeof arg1 === 'function') {
135 this._fn = arg1;
136 this._computeKey = identity;
137 } else {
138 this._fn = arg2!;
139 this._computeKey = arg1.getCacheKey;
140 }
141 }
143 > public get(arg: TArg): TComputed {
144 const key = this._computeKey(arg) as WeakKey;
145 if (this._map.has(key)) {
146 return this._map.get(key)!;
147 }
148
149 const value = this._fn(arg);
150 this._map.set(key, value);
151 return value;
152 }