Skip to content

Commit

Permalink
scope console history to workspaces (posit-dev#3518)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcphers authored Jun 13, 2024
1 parent a40a86a commit ed7a9a6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import { IExecutionHistoryEntry, IExecutionHistoryService, IInputHistoryEntry } from 'vs/workbench/contrib/executionHistory/common/executionHistoryService';
import { Disposable } from 'vs/base/common/lifecycle';
import { ILanguageRuntimeSession, IRuntimeSessionService } from 'vs/workbench/services/runtimeSession/common/runtimeSessionService';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { ILogService } from 'vs/platform/log/common/log';
import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { RuntimeExecutionHistory } from 'vs/workbench/contrib/executionHistory/common/runtimeExecutionHistory';
import { LanguageInputHistory } from 'vs/workbench/contrib/executionHistory/common/languageInputHistory';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';

/**
* Service that manages execution histories for all runtimes.
Expand All @@ -29,7 +30,8 @@ export class ExecutionHistoryService extends Disposable implements IExecutionHis
@IRuntimeSessionService private readonly _runtimeSessionService: IRuntimeSessionService,
@IStorageService private readonly _storageService: IStorageService,
@ILogService private readonly _logService: ILogService,
@IConfigurationService private readonly _configurationService: IConfigurationService
@IConfigurationService private readonly _configurationService: IConfigurationService,
@IWorkspaceContextService private readonly _workspaceContextService: IWorkspaceContextService
) {
super();

Expand Down Expand Up @@ -105,7 +107,18 @@ export class ExecutionHistoryService extends Disposable implements IExecutionHis
if (this._inputHistories.has(languageId)) {
return this._inputHistories.get(languageId)!;
}
const history = new LanguageInputHistory(languageId, this._storageService, this._logService, this._configurationService);

// If we're in an empty workspace, use the profile storage scope; otherwise,
// use the workspace scope.
const storageScope =
this._workspaceContextService.getWorkbenchState() === WorkbenchState.EMPTY ?
StorageScope.PROFILE :
StorageScope.WORKSPACE;
const history = new LanguageInputHistory(languageId,
this._storageService,
storageScope,
this._logService,
this._configurationService);
this._inputHistories.set(languageId, history);
this._register(history);
return history;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class LanguageInputHistory extends Disposable {
constructor(
private readonly _languageId: string,
private readonly _storageService: IStorageService,
private readonly _storageScope: StorageScope,
private readonly _logService: ILogService,
private readonly _configurationService: IConfigurationService) {
super();
Expand Down Expand Up @@ -98,7 +99,7 @@ export class LanguageInputHistory extends Disposable {
*/
public getInputHistory(): IInputHistoryEntry[] {
// Read the existing entries from storage.
const entries = this._storageService.get(this._storageKey, StorageScope.PROFILE, '[]');
const entries = this._storageService.get(this._storageKey, this._storageScope, '[]');
let parsedEntries: IInputHistoryEntry[] = [];
try {
parsedEntries = JSON.parse(entries);
Expand All @@ -122,7 +123,7 @@ export class LanguageInputHistory extends Disposable {
this._pendingEntries.splice(0, this._pendingEntries.length);

// Clear the underlying storage
this._storageService.remove(this._storageKey, StorageScope.PROFILE);
this._storageService.remove(this._storageKey, this._storageScope);
}

private save(forShutdown: boolean): void {
Expand All @@ -136,7 +137,7 @@ export class LanguageInputHistory extends Disposable {

// Read the existing entries. We do this every time we save because
// another instance of the app may have written to the same storage.
const entries = this._storageService.get(this._storageKey, StorageScope.PROFILE, '[]');
const entries = this._storageService.get(this._storageKey, this._storageScope, '[]');
let parsedEntries: IInputHistoryEntry[] = [];
try {
parsedEntries = JSON.parse(entries);
Expand Down Expand Up @@ -177,7 +178,7 @@ export class LanguageInputHistory extends Disposable {
// history in this "session"
this._storageService.store(this._storageKey,
storageState,
StorageScope.PROFILE,
this._storageScope,
StorageTarget.USER);

// Clear the pending entries now that they've been flushed to storage.
Expand Down

0 comments on commit ed7a9a6

Please sign in to comment.