Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't store/restore ports in an empty workspace #174663

Merged
merged 2 commits into from Feb 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/vs/workbench/services/remote/common/remoteExplorerService.ts
Expand Up @@ -519,9 +519,13 @@ export class TunnelModel extends Disposable {
return URI.parse(`${protocol}://${localAddress}`);
}

private async getStorageKey(): Promise<string> {
private async getStorageKey(): Promise<string | undefined> {
const workspace = this.workspaceContextService.getWorkspace();
const workspaceHash = workspace.configuration ? hash(workspace.configuration.path) : (workspace.folders.length > 0 ? hash(workspace.folders[0].uri.path) : undefined);
if (workspaceHash === undefined) {
this.logService.debug('Could not get workspace hash for forwarded ports storage key.');
return undefined;
}
return `${TUNNELS_TO_RESTORE}.${this.environmentService.remoteAuthority}.${workspaceHash}`;
}

Expand All @@ -532,8 +536,11 @@ export class TunnelModel extends Disposable {
await this.storeForwarded();
return deprecatedValue;
}

return this.storageService.get(await this.getStorageKey(), StorageScope.PROFILE);
const storageKey = await this.getStorageKey();
if (!storageKey) {
return undefined;
}
return this.storageService.get(storageKey, StorageScope.PROFILE);
}

async restoreForwarded() {
Expand Down Expand Up @@ -561,8 +568,9 @@ export class TunnelModel extends Disposable {
const key = await this.getStorageKey();
this.restoreListener = this._register(this.storageService.onDidChangeValue(async (e) => {
if (e.key === key) {
this.tunnelRestoreValue = Promise.resolve(this.storageService.get(await this.getStorageKey(), StorageScope.PROFILE));
this.tunnelRestoreValue = Promise.resolve(this.storageService.get(key, StorageScope.PROFILE));
await this.restoreForwarded();

}
}));
}
Expand All @@ -574,7 +582,10 @@ export class TunnelModel extends Disposable {
const valueToStore = JSON.stringify(Array.from(this.forwarded.values()).filter(value => value.source.source === TunnelSource.User));
if (valueToStore !== this.knownPortsRestoreValue) {
this.knownPortsRestoreValue = valueToStore;
this.storageService.store(await this.getStorageKey(), this.knownPortsRestoreValue, StorageScope.PROFILE, StorageTarget.USER);
const key = await this.getStorageKey();
if (key) {
this.storageService.store(key, this.knownPortsRestoreValue, StorageScope.PROFILE, StorageTarget.USER);
}
}
}
}
Expand Down