history.ts ×23

Frontier kind: Code frontier

unlabeled · c_86213f825870

30 tests · 25120 LOC · 131 files · introduces 0 tests · 146 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
24 ranges146 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
2778 ranges25120 lines · 131 files · Browse complete extent
All tests (intent)
30 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

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 native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 146 introduced LOC across 24 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/contrib/terminalContrib/history/common/history.ts 114 introduced LOC · 23 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- history.ts
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 { Disposable } from '../../../../../base/common/lifecycle.js';
7 > import { LRUCache } from '../../../../../base/common/map.js';
8 > import { Schemas } from '../../../../../base/common/network.js';
9 > import { join } from '../../../../../base/common/path.js';
10 > import { isWindows, OperatingSystem } from '../../../../../base/common/platform.js';
11 > import { env } from '../../../../../base/common/process.js';
12 > import { isNumber } from '../../../../../base/common/types.js';
13 > import { URI } from '../../../../../base/common/uri.js';
14 > import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
15 > import { FileOperationError, FileOperationResult, IFileContent, IFileService } from '../../../../../platform/files/common/files.js';
16 > import { IInstantiationService, ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js';
17 > import { IStorageService, StorageScope, StorageTarget } from '../../../../../platform/storage/common/storage.js';
18 > import { GeneralShellType, PosixShellType, TerminalShellType } from '../../../../../platform/terminal/common/terminal.js';
19 > import { IRemoteAgentService } from '../../../../services/remote/common/remoteAgentService.js';
20 > import { TerminalHistorySettingId } from './terminal.history.js';
21 >
22 > /**
23 > * Tracks a list of generic entries.
24 > */
25 > export interface ITerminalPersistedHistory<T> {
26 > /**
27 > * The persisted entries.
28 > */
29 > readonly entries: IterableIterator<[string, T]>;
30 > /**
31 > * Adds an entry.
32 > */
33 > add(key: string, value: T): void;
34 > /**
35 > * Removes an entry.
36 > */
37 > remove(key: string): void;
38 > /**
39 > * Clears all entries.
40 > */
41 > clear(): void;
42 > }
43 >
44 > interface ISerializedCache<T> {
45 > entries: { key: string; value: T }[];
46 > }
47 >
48 > const enum Constants {
49 > DefaultHistoryLimit = 100
50 > }
51 >
52 > const enum StorageKeys {
53 > Entries = 'terminal.history.entries',
54 > Timestamp = 'terminal.history.timestamp'
55 > }
56 >
57 > let directoryHistory: ITerminalPersistedHistory<{ remoteAuthority?: string }> | undefined = undefined;
58 > export function getDirectoryHistory(accessor: ServicesAccessor): ITerminalPersistedHistory<{ remoteAuthority?: string }> {
59 if (!directoryHistory) {
60 directoryHistory = accessor.get(IInstantiationService).createInstance(TerminalPersistedHistory, 'dirs') as TerminalPersistedHistory<{ remoteAuthority?: string }>;
62 return directoryHistory;
63 }
64 > history.ts
65 > let commandHistory: ITerminalPersistedHistory<{ shellType: TerminalShellType }> | undefined = undefined;
66 > export function getCommandHistory(accessor: ServicesAccessor): ITerminalPersistedHistory<{ shellType: TerminalShellType | undefined }> {
67 if (!commandHistory) {
68 commandHistory = accessor.get(IInstantiationService).createInstance(TerminalPersistedHistory, 'commands') as TerminalPersistedHistory<{ shellType: TerminalShellType }>;
70 return commandHistory;
71 }
72 > history.ts
73 > export class TerminalPersistedHistory<T> extends Disposable implements ITerminalPersistedHistory<T> {
74 > private readonly _entries: LRUCache<string, T>;
75 > private _timestamp: number = 0;
76 > private _isReady = false;
77 > private _isStale = true;
78 >
79 > get entries(): IterableIterator<[string, T]> {
80 > this._ensureUpToDate();
81 > return this._entries.entries();
82 > }
83 >
84 > constructor(
85 private readonly _storageDataKey: string,
86 @IConfigurationService private readonly _configurationService: IConfigurationService,
106 }));
107 }
108 > history.ts
109 > add(key: string, value: T) {
110 this._ensureUpToDate();
111 this._entries.set(key, value);
112 this._saveState();
113 }
114 > history.ts
115 > remove(key: string) {
116 this._ensureUpToDate();
117 this._entries.delete(key);
118 this._saveState();
119 }
120 > history.ts
121 > clear() {
122 this._ensureUpToDate();
123 this._entries.clear();
124 this._saveState();
125 }
126 > history.ts
127 > private _ensureUpToDate() {
128 // Initial load
129 if (!this._isReady) {
141 }
142 }
143 > history.ts
144 > private _loadState() {
145 this._timestamp = this._storageService.getNumber(this._getTimestampStorageKey(), StorageScope.APPLICATION, 0);
146
153 }
154 }
155 > history.ts
156 > private _loadPersistedState(): ISerializedCache<T> | undefined {
157 const raw = this._storageService.get(this._getEntriesStorageKey(), StorageScope.APPLICATION);
158 if (raw === undefined || raw.length === 0) {
168 return serialized;
169 }
170 > history.ts
171 > private _saveState() {
172 const serialized: ISerializedCache<T> = { entries: [] };
173 this._entries.forEach((value, key) => serialized.entries.push({ key, value }));
176 this._storageService.store(this._getTimestampStorageKey(), this._timestamp, StorageScope.APPLICATION, StorageTarget.MACHINE);
177 }
178 > history.ts
179 > private _getHistoryLimit() {
180 const historyLimit = this._configurationService.getValue(TerminalHistorySettingId.ShellIntegrationCommandHistory);
181 return isNumber(historyLimit) ? historyLimit : Constants.DefaultHistoryLimit;
182 }
183 > history.ts
184 > private _getTimestampStorageKey() {
185 return `${StorageKeys.Timestamp}.${this._storageDataKey}`;
186 }
187 > history.ts
188 > private _getEntriesStorageKey() {
189 return `${StorageKeys.Entries}.${this._storageDataKey}`;
190 }
191 > } history.ts
192 >
193 > // Shell file history loads once per shell per window
194 > interface IShellFileHistoryEntry {
195 > sourceLabel: string;
196 > sourceResource: URI;
197 > commands: string[];
198 > }
199 > const shellFileHistory: Map<TerminalShellType | undefined, IShellFileHistoryEntry | null> = new Map();
200 export async function getShellFileHistory(accessor: ServicesAccessor, shellType: TerminalShellType | undefined): Promise<IShellFileHistoryEntry | undefined> {
201 const cached = shellFileHistory.get(shellType);
232 return result;
233 }
234 > export function clearShellFileHistory() { history.ts
235 shellFileHistory.clear();
236 }
237 > history.ts
238 export async function fetchBashHistory(accessor: ServicesAccessor): Promise<IShellFileHistoryEntry | undefined> {
239 const fileService = accessor.get(IFileService);
288 };
289 }
290 > history.ts
291 export async function fetchZshHistory(accessor: ServicesAccessor): Promise<IShellFileHistoryEntry | undefined> {
292 const fileService = accessor.get(IFileService);
318 };
319 }
320 > history.ts
321 >
322 export async function fetchPythonHistory(accessor: ServicesAccessor): Promise<IShellFileHistoryEntry | undefined> {
323 const fileService = accessor.get(IFileService);
349 };
350 }
351 > history.ts
352 export async function fetchPwshHistory(accessor: ServicesAccessor): Promise<IShellFileHistoryEntry | undefined> {
353 const fileService: Pick<IFileService, 'readFile'> = accessor.get(IFileService);
425 };
426 }
427 > history.ts
428 export async function fetchFishHistory(accessor: ServicesAccessor): Promise<IShellFileHistoryEntry | undefined> {
429 const fileService = accessor.get(IFileService);
494 };
495 }
496 > history.ts
497 > export function sanitizeFishHistoryCmd(cmd: string): string {
498 /**
499 * NOTE
510 return repeatedReplace(/(^|[^\\])((?:\\\\)*)(\\n)/g, cmd, '$1$2\n');
511 }
512 > history.ts
513 function repeatedReplace(pattern: RegExp, value: string, replaceValue: string): string {
514 let last;
522 }
523 }
524 > history.ts
525 async function fetchFileContents(
526 folderPrefix: string | undefined,
src/vs/workbench/contrib/terminalContrib/history/common/terminal.history.ts 32 introduced LOC · 1 range

Open complete file

1 > /*--------------------------------------------------------------------------------------------- terminal.history.ts
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 type { IStringDictionary } from '../../../../../base/common/collections.js';
7 > import { localize } from '../../../../../nls.js';
8 > import type { IConfigurationPropertySchema } from '../../../../../platform/configuration/common/configurationRegistry.js';
9 >
10 > export const enum TerminalHistoryCommandId {
11 > ClearPreviousSessionHistory = 'workbench.action.terminal.clearPreviousSessionHistory',
12 > GoToRecentDirectory = 'workbench.action.terminal.goToRecentDirectory',
13 > RunRecentCommand = 'workbench.action.terminal.runRecentCommand',
14 > }
15 >
16 > export const defaultTerminalHistoryCommandsToSkipShell = [
17 > TerminalHistoryCommandId.GoToRecentDirectory,
18 > TerminalHistoryCommandId.RunRecentCommand
19 > ];
20 >
21 > export const enum TerminalHistorySettingId {
22 > ShellIntegrationCommandHistory = 'terminal.integrated.shellIntegration.history',
23 > }
24 >
25 > export const terminalHistoryConfiguration: IStringDictionary<IConfigurationPropertySchema> = {
26 > [TerminalHistorySettingId.ShellIntegrationCommandHistory]: {
27 > restricted: true,
28 > markdownDescription: localize('terminal.integrated.shellIntegration.history', "Controls the number of recently used commands to keep in the terminal command history. Set to 0 to disable terminal command history."),
29 > type: 'number',
30 > default: 100
31 > },
32 > };