* Convert a file path to a webview-accessible URI * This method safely converts file paths to URIs that can be loaded in the webview * * @param filePath - The absolute file path to convert * @returns The webview URI string, or the original file URI if conversion fails * @throws {Error} Whe
(filePath: string)
| 3864 | * @throws {TypeError} When file path is invalid |
| 3865 | */ |
| 3866 | public convertToWebviewUri(filePath: string): string { |
| 3867 | try { |
| 3868 | const fileUri = vscode.Uri.file(filePath) |
| 3869 | |
| 3870 | // Check if we have a webview available |
| 3871 | if (this.view?.webview) { |
| 3872 | const webviewUri = this.view.webview.asWebviewUri(fileUri) |
| 3873 | return webviewUri.toString() |
| 3874 | } |
| 3875 | |
| 3876 | // Specific error for no webview available |
| 3877 | const error = new Error("No webview available for URI conversion") |
| 3878 | console.error(error.message) |
| 3879 | // Fallback to file URI if no webview available |
| 3880 | return fileUri.toString() |
| 3881 | } catch (error) { |
| 3882 | // More specific error handling |
| 3883 | if (error instanceof TypeError) { |
| 3884 | console.error("Invalid file path provided for URI conversion:", error) |
| 3885 | } else { |
| 3886 | console.error("Failed to convert to webview URI:", error) |
| 3887 | } |
| 3888 | // Return file URI as fallback |
| 3889 | return vscode.Uri.file(filePath).toString() |
| 3890 | } |
| 3891 | } |
| 3892 | } |
no test coverage detected