mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-04-30 12:40:44 +00:00
Merge pull request #2073 from QwenLM/fix-issue-qwen-code
fix: preserve original encoding when reading/writing non-UTF-8 files
This commit is contained in:
commit
38e49c1d39
12 changed files with 645 additions and 33 deletions
|
|
@ -11,6 +11,9 @@ import { ACP_ERROR_CODES } from '../errorCodes.js';
|
|||
|
||||
const createFallback = (): FileSystemService => ({
|
||||
readTextFile: vi.fn(),
|
||||
readTextFileWithInfo: vi
|
||||
.fn()
|
||||
.mockResolvedValue({ content: '', encoding: 'utf-8', bom: false }),
|
||||
writeTextFile: vi.fn(),
|
||||
detectFileBOM: vi.fn().mockResolvedValue(false),
|
||||
findFiles: vi.fn().mockReturnValue([]),
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import type { FileSystemService } from '@qwen-code/qwen-code-core';
|
||||
import type { FileSystemService , FileReadResult } from '@qwen-code/qwen-code-core';
|
||||
import type * as acp from '../acp.js';
|
||||
import { ACP_ERROR_CODES } from '../errorCodes.js';
|
||||
|
||||
|
|
@ -54,10 +54,16 @@ export class AcpFileSystemService implements FileSystemService {
|
|||
return response.content;
|
||||
}
|
||||
|
||||
async readTextFileWithInfo(filePath: string): Promise<FileReadResult> {
|
||||
// ACP protocol does not expose encoding metadata; delegate to the local
|
||||
// fallback which performs a single-pass read with encoding detection.
|
||||
return this.fallback.readTextFileWithInfo(filePath);
|
||||
}
|
||||
|
||||
async writeTextFile(
|
||||
filePath: string,
|
||||
content: string,
|
||||
options?: { bom?: boolean },
|
||||
options?: { bom?: boolean; encoding?: string },
|
||||
): Promise<void> {
|
||||
if (!this.capabilities.writeTextFile) {
|
||||
return this.fallback.writeTextFile(filePath, content, options);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue