(
client: RpcIntelligenceClient,
project: string,
filePath: string,
)
| 168 | * Vollstaendigkeit beurteilen. |
| 169 | */ |
| 170 | export async function loadFileDocument( |
| 171 | client: RpcIntelligenceClient, |
| 172 | project: string, |
| 173 | filePath: string, |
| 174 | ): Promise<ReaderDocument> { |
| 175 | const path = normalizeWorkspacePath(filePath); |
| 176 | const derivedQualifiedName = moduleQualifiedName(project, path); |
| 177 | |
| 178 | const node = await lookupModuleNode(client, project, path); |
| 179 | if (node === undefined) { |
| 180 | throw notReadable( |
| 181 | path, |
| 182 | `The index has no module node for ${path}. This server delivers file content only through get_code_snippet on an indexed symbol, so a file the index did not record cannot be read here.`, |
| 183 | ); |
| 184 | } |
| 185 | |
| 186 | const qualifiedName = node.qualifiedName; |
| 187 | const snippet = await client.getCodeSnippet(project, qualifiedName); |
| 188 | if (snippet.source.length === 0 || snippet.source === SOURCE_UNAVAILABLE) { |
| 189 | throw notReadable( |
| 190 | path, |
| 191 | snippet.source === SOURCE_UNAVAILABLE |
| 192 | ? `The server could not read ${path} from the repository (${qualifiedName}): ` |
| 193 | + 'the index knows the file, the disk does not have it where the index expects it.' |
| 194 | : `get_code_snippet returned no source for ${qualifiedName}.`, |
| 195 | ); |
| 196 | } |
| 197 | |
| 198 | /* |
| 199 | * Since the lean output contract the server pages source 500 lines at a |
| 200 | * time and names the next page in `next_start_line`. The pages are |
| 201 | * fetched one after the other and joined; a page that does not arrive |
| 202 | * ends the loading, and the note below names what is missing rather |
| 203 | * than a guess. Before the contract there was one window and no |
| 204 | * `next_start_line`, and that path is unchanged. |
| 205 | */ |
| 206 | const firstLine = snippet.start_line ?? 1; |
| 207 | let source = snippet.source; |
| 208 | let lastLine = snippet.end_line ?? firstLine; |
| 209 | let next = snippet.next_start_line; |
| 210 | let pages = 1; |
| 211 | let pageFailed = false; |
| 212 | while (next !== undefined && pages < MAX_SOURCE_PAGES) { |
| 213 | let page: CodeSnippetResult; |
| 214 | try { |
| 215 | page = await client.getCodeSnippet(project, qualifiedName, { |
| 216 | startLine: next, |
| 217 | maxLines: SOURCE_PAGE_LINES, |
| 218 | }); |
| 219 | } catch { |
| 220 | pageFailed = true; |
| 221 | break; |
| 222 | } |
| 223 | if (page.source.length === 0 || page.source === SOURCE_UNAVAILABLE |
| 224 | || (page.start_line !== undefined && page.start_line !== next)) { |
| 225 | pageFailed = true; |
| 226 | break; |
| 227 | } |
no test coverage detected