| 36 | } from "core"; |
| 37 | |
| 38 | class VsCodeIde implements IDE { |
| 39 | ideUtils: VsCodeIdeUtils; |
| 40 | secretStorage: SecretStorage; |
| 41 | |
| 42 | constructor( |
| 43 | private readonly vscodeWebviewProtocolPromise: Promise<VsCodeWebviewProtocol>, |
| 44 | private readonly context: vscode.ExtensionContext, |
| 45 | ) { |
| 46 | this.ideUtils = new VsCodeIdeUtils(); |
| 47 | this.secretStorage = new SecretStorage(context); |
| 48 | } |
| 49 | |
| 50 | async readSecrets(keys: string[]): Promise<Record<string, string>> { |
| 51 | const secretValuePromises = keys.map((key) => this.secretStorage.get(key)); |
| 52 | const secretValues = await Promise.all(secretValuePromises); |
| 53 | |
| 54 | return keys.reduce( |
| 55 | (acc, key, index) => { |
| 56 | if (secretValues[index] === undefined) { |
| 57 | return acc; |
| 58 | } |
| 59 | |
| 60 | acc[key] = secretValues[index]; |
| 61 | return acc; |
| 62 | }, |
| 63 | {} as Record<string, string>, |
| 64 | ); |
| 65 | } |
| 66 | |
| 67 | async writeSecrets(secrets: { [key: string]: string }): Promise<void> { |
| 68 | for (const [key, value] of Object.entries(secrets)) { |
| 69 | await this.secretStorage.store(key, value); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | async fileExists(uri: string): Promise<boolean> { |
| 74 | try { |
| 75 | const stat = await this.ideUtils.stat(vscode.Uri.parse(uri)); |
| 76 | return stat !== null; |
| 77 | } catch (error) { |
| 78 | if (error instanceof vscode.FileSystemError) { |
| 79 | return false; |
| 80 | } |
| 81 | throw error; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | async gotoDefinition(location: Location): Promise<RangeInFile[]> { |
| 86 | const result = await executeGotoProvider({ |
| 87 | uri: vscode.Uri.parse(location.filepath), |
| 88 | line: location.position.line, |
| 89 | character: location.position.character, |
| 90 | name: "vscode.executeDefinitionProvider", |
| 91 | }); |
| 92 | |
| 93 | return result; |
| 94 | } |
| 95 |
nothing calls this directly
no test coverage detected