( uri: vscode.Uri, webviewProtocol: VsCodeWebviewProtocol | undefined, ideUtils: VsCodeIdeUtils, )
| 106 | } |
| 107 | |
| 108 | export async function addEntireFileToContext( |
| 109 | uri: vscode.Uri, |
| 110 | webviewProtocol: VsCodeWebviewProtocol | undefined, |
| 111 | ideUtils: VsCodeIdeUtils, |
| 112 | ) { |
| 113 | // If a directory, add all files in the directory |
| 114 | const stat = await ideUtils.stat(uri); |
| 115 | if (stat?.type === vscode.FileType.Directory) { |
| 116 | const files = (await ideUtils.readDirectory(uri))!; //files can't be null if we reached this point |
| 117 | for (const [filename, type] of files) { |
| 118 | if (type === vscode.FileType.File) { |
| 119 | addEntireFileToContext( |
| 120 | vscode.Uri.joinPath(uri, filename), |
| 121 | webviewProtocol, |
| 122 | ideUtils, |
| 123 | ); |
| 124 | } |
| 125 | } |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | // Get the contents of the file |
| 130 | const contents = (await vscode.workspace.fs.readFile(uri)).toString(); |
| 131 | const rangeInFileWithContents = { |
| 132 | filepath: uri.toString(), |
| 133 | contents: contents, |
| 134 | range: { |
| 135 | start: { |
| 136 | line: 0, |
| 137 | character: 0, |
| 138 | }, |
| 139 | end: { |
| 140 | line: contents.split(os.EOL).length - 1, |
| 141 | character: 0, |
| 142 | }, |
| 143 | }, |
| 144 | }; |
| 145 | |
| 146 | webviewProtocol?.request("highlightedCode", { |
| 147 | rangeInFileWithContents, |
| 148 | }); |
| 149 | } |
| 150 | |
| 151 | export function isEmptyFile(document: vscode.TextDocument) { |
| 152 | return document.lineCount === 1 && document.lineAt(0).range.isEmpty; |
no test coverage detected