-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(core): Support large text range reads #6404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d94230c
8bdf40b
574191f
aa7d786
e1d7893
8819b16
61d43f5
0e3a2c2
f9a3d77
48292f1
7ef3b68
20da646
8c79197
0053346
ed5b9ef
e2e61a7
817b65b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| */ | ||
|
|
||
| import os from 'node:os'; | ||
| import type { Stats } from 'node:fs'; | ||
| import * as path from 'node:path'; | ||
| import { globSync } from 'glob'; | ||
| import { atomicWriteFile } from '../utils/atomicFileWrite.js'; | ||
|
|
@@ -29,10 +30,26 @@ export type ReadTextFileResponse = { | |
| bom?: boolean; | ||
| encoding?: string; | ||
| originalLineCount?: number; | ||
| originalLineCountExact?: boolean; | ||
| lineEnding?: LineEnding; | ||
| truncatedByBytes?: boolean; | ||
| }; | ||
| }; | ||
|
|
||
| export type CoreReadTextFileRequest = Omit< | ||
| ReadTextFileRequest, | ||
| 'sessionId' | 'line' | ||
| > & { | ||
| /** | ||
| * Core-local callers use 0-based line offsets. ACP protocol boundaries remain | ||
| * 1-based and convert explicitly before remote calls. | ||
| */ | ||
| line?: number | null; | ||
| maxOutputBytes?: number; | ||
| signal?: AbortSignal; | ||
| stats?: Stats; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking scope note: Could we keep the main PR focused on the large-text range behavior and either avoid threading |
||
| }; | ||
|
|
||
| /** | ||
| * Supported file encodings for new files. | ||
| */ | ||
|
|
@@ -50,9 +67,7 @@ export type FileEncodingType = (typeof FileEncoding)[keyof typeof FileEncoding]; | |
| * Interface for file system operations that may be delegated to different implementations | ||
| */ | ||
| export interface FileSystemService { | ||
| readTextFile( | ||
| params: Omit<ReadTextFileRequest, 'sessionId'>, | ||
| ): Promise<ReadTextFileResponse>; | ||
| readTextFile(params: CoreReadTextFileRequest): Promise<ReadTextFileResponse>; | ||
|
|
||
| writeTextFile( | ||
| params: Omit<WriteTextFileRequest, 'sessionId'>, | ||
|
|
@@ -261,18 +276,32 @@ export function encodeTextFileContent( | |
| */ | ||
| export class StandardFileSystemService implements FileSystemService { | ||
| async readTextFile( | ||
| params: Omit<ReadTextFileRequest, 'sessionId'>, | ||
| params: CoreReadTextFileRequest, | ||
| ): Promise<ReadTextFileResponse> { | ||
| const { path, limit, line } = params; | ||
| // Use encoding-aware reader that handles BOM and non-UTF-8 encodings (e.g. GBK) | ||
| const { content, bom, encoding, originalLineCount } = | ||
| await readFileWithLineAndLimit({ | ||
| path, | ||
| limit: limit ?? Number.POSITIVE_INFINITY, | ||
| line: line || 0, | ||
| }); | ||
| const lineEnding = detectLineEnding(content); | ||
| return { content, _meta: { bom, encoding, originalLineCount, lineEnding } }; | ||
| const { path, limit, line, maxOutputBytes, signal, stats } = params; | ||
| const readResult = await readFileWithLineAndLimit({ | ||
| path, | ||
| limit: limit ?? Number.POSITIVE_INFINITY, | ||
| ...(line !== undefined && line !== null ? { line } : {}), | ||
| ...(maxOutputBytes !== undefined ? { maxOutputBytes } : {}), | ||
| ...(signal !== undefined ? { signal } : {}), | ||
| ...(stats !== undefined ? { stats } : {}), | ||
| }); | ||
| const detectedLineEnding = | ||
| readResult.lineEnding ?? detectLineEnding(readResult.content); | ||
| return { | ||
| content: readResult.content, | ||
| _meta: { | ||
| bom: readResult.bom, | ||
| encoding: readResult.encoding, | ||
| originalLineCount: readResult.originalLineCount, | ||
| originalLineCountExact: readResult.originalLineCountExact, | ||
| lineEnding: detectedLineEnding, | ||
| ...(readResult.truncatedByBytes !== undefined | ||
| ? { truncatedByBytes: readResult.truncatedByBytes } | ||
| : {}), | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| async writeTextFile( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.