|
5 | 5 | import * as vscode from 'vscode'; |
6 | 6 | import { disposeAll } from './lifecycle'; |
7 | 7 | import Logger from './logger'; |
| 8 | +import { isDescendant } from './utils'; |
8 | 9 |
|
9 | 10 | let tempState: TemporaryState | undefined; |
10 | 11 |
|
@@ -39,14 +40,13 @@ export class TemporaryState extends vscode.Disposable { |
39 | 40 | } |
40 | 41 | } |
41 | 42 |
|
42 | | - private async writeState(subpath: string, filename: string, contents: Uint8Array, persistInSession: boolean, repositoryUri?: vscode.Uri): Promise<vscode.Uri> { |
| 43 | + private async writeState(subpath: string, filename: string, contents: Uint8Array, persistInSession: boolean, repositoryUri: vscode.Uri): Promise<vscode.Uri> { |
43 | 44 | let filePath: vscode.Uri = this.path; |
44 | 45 | let workspace: string | undefined; |
45 | 46 |
|
46 | | - // If repositoryUri is provided, find the matching workspace folder |
47 | | - if (repositoryUri && vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) { |
| 47 | + if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) { |
48 | 48 | const matchingFolder = vscode.workspace.workspaceFolders.find(folder => |
49 | | - folder.uri.toString() === repositoryUri.toString() |
| 49 | + isDescendant(folder.uri.fsPath, repositoryUri.fsPath) || isDescendant(repositoryUri.fsPath, folder.uri.fsPath) |
50 | 50 | ); |
51 | 51 | workspace = matchingFolder?.name; |
52 | 52 | } |
@@ -80,14 +80,13 @@ export class TemporaryState extends vscode.Disposable { |
80 | 80 | return file; |
81 | 81 | } |
82 | 82 |
|
83 | | - private async readState(subpath: string, filename: string, repositoryUri?: vscode.Uri): Promise<Uint8Array> { |
| 83 | + private async readState(subpath: string, filename: string, repositoryUri: vscode.Uri): Promise<Uint8Array> { |
84 | 84 | let filePath: vscode.Uri = this.path; |
85 | 85 | let workspace: string | undefined; |
86 | 86 |
|
87 | | - // If repositoryUri is provided, find the matching workspace folder |
88 | | - if (repositoryUri && vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) { |
| 87 | + if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) { |
89 | 88 | const matchingFolder = vscode.workspace.workspaceFolders.find(folder => |
90 | | - folder.uri.toString() === repositoryUri.toString() |
| 89 | + isDescendant(folder.uri.fsPath, repositoryUri.fsPath) || isDescendant(repositoryUri.fsPath, folder.uri.fsPath) |
91 | 90 | ); |
92 | 91 | workspace = matchingFolder?.name; |
93 | 92 | } |
@@ -123,15 +122,15 @@ export class TemporaryState extends vscode.Disposable { |
123 | 122 | } |
124 | 123 | } |
125 | 124 |
|
126 | | - static async write(subpath: string, filename: string, contents: Uint8Array, persistInSession: boolean = false, repositoryUri?: vscode.Uri): Promise<vscode.Uri | undefined> { |
| 125 | + static async write(subpath: string, filename: string, contents: Uint8Array, persistInSession: boolean = false, repositoryUri: vscode.Uri): Promise<vscode.Uri | undefined> { |
127 | 126 | if (!tempState) { |
128 | 127 | return; |
129 | 128 | } |
130 | 129 |
|
131 | 130 | return tempState.writeState(subpath, filename, contents, persistInSession, repositoryUri); |
132 | 131 | } |
133 | 132 |
|
134 | | - static async read(subpath: string, filename: string, repositoryUri?: vscode.Uri): Promise<Uint8Array | undefined> { |
| 133 | + static async read(subpath: string, filename: string, repositoryUri: vscode.Uri): Promise<Uint8Array | undefined> { |
135 | 134 | if (!tempState) { |
136 | 135 | return; |
137 | 136 | } |
|
0 commit comments