Skip to content
This repository was archived by the owner on May 20, 2026. It is now read-only.

Commit a25edaf

Browse files
aeschliCopilot
andauthored
PromptsServiceImpl: avoid using openTextDocument to not trigger validations (#4805)
* PromptsServiceImpl: avoid using openTextDocument to not trigger validations * Update src/platform/promptFiles/common/promptsServiceImpl.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix test --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent a0c6c0b commit a25edaf

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

src/extension/chatSessions/vscode-node/test/copilotCLIChatSessionParticipant.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ describe('CopilotCLIChatSessionParticipant.handleRequest', () => {
412412
workspaceFolderService,
413413
telemetry,
414414
logger,
415-
new PromptsServiceImpl(new NullWorkspaceService()),
415+
new PromptsServiceImpl(new NullWorkspaceService(), fileSystem),
416416
delegationService,
417417
folderRepositoryManager,
418418
configurationService,
@@ -755,7 +755,7 @@ describe('CopilotCLIChatSessionParticipant.handleRequest', () => {
755755
workspaceFolderService,
756756
telemetry,
757757
logService,
758-
new PromptsServiceImpl(new NullWorkspaceService()),
758+
new PromptsServiceImpl(new NullWorkspaceService(), new MockFileSystemService()),
759759
new class extends mock<IChatDelegationSummaryService>() {
760760
override async summarize(_context: vscode.ChatContext, _token: vscode.CancellationToken): Promise<string | undefined> {
761761
return undefined;
@@ -1901,7 +1901,7 @@ describe('CopilotCLIChatSessionParticipant.handleRequest', () => {
19011901
workspaceFolderService,
19021902
telemetry,
19031903
logService,
1904-
new PromptsServiceImpl(new NullWorkspaceService()),
1904+
new PromptsServiceImpl(new NullWorkspaceService(), new MockFileSystemService()),
19051905
nullDelegationService,
19061906
folderRepositoryManager,
19071907
configurationService,
@@ -2033,7 +2033,7 @@ describe('CopilotCLIChatSessionParticipant.handleRequest', () => {
20332033
workspaceFolderService,
20342034
telemetry,
20352035
logService,
2036-
new PromptsServiceImpl(new NullWorkspaceService()),
2036+
new PromptsServiceImpl(new NullWorkspaceService(), new MockFileSystemService()),
20372037
new (mock<IChatDelegationSummaryService>())(),
20382038
folderRepositoryManager,
20392039
configurationService,

src/platform/promptFiles/common/promptsServiceImpl.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,33 @@
55

66
import { raceCancellationError } from '../../../util/vs/base/common/async';
77
import { CancellationToken } from '../../../util/vs/base/common/cancellation';
8+
import { extUriBiasedIgnorePathCase } from '../../../util/vs/base/common/resources';
89
import { URI } from '../../../util/vs/base/common/uri';
910
import { PromptFileParser } from '../../../util/vs/workbench/contrib/chat/common/promptSyntax/promptFileParser';
11+
import { IFileSystemService } from '../../filesystem/common/fileSystemService';
1012
import { IWorkspaceService } from '../../workspace/common/workspaceService';
1113
import { IPromptsService, ParsedPromptFile } from './promptsService';
1214

1315
export class PromptsServiceImpl implements IPromptsService {
1416
declare _serviceBrand: undefined;
1517
constructor(
16-
@IWorkspaceService private readonly workspaceService: IWorkspaceService
18+
@IWorkspaceService private readonly workspaceService: IWorkspaceService,
19+
@IFileSystemService private readonly fileService: IFileSystemService,
1720
) { }
1821

1922
public async parseFile(uri: URI, token: CancellationToken): Promise<ParsedPromptFile> {
20-
const doc = await raceCancellationError(this.workspaceService.openTextDocument(uri), token);
21-
return new PromptFileParser().parse(uri, doc.getText());
23+
// a temporary workaround to avoid creating a text document to read the file content, which triggers the validation of the file in core (fixed in 1.114)
24+
const getTextContent = async (uri: URI) => {
25+
const existingDoc = this.workspaceService.textDocuments.find(doc => extUriBiasedIgnorePathCase.isEqual(doc.uri, uri));
26+
if (!existingDoc) {
27+
// if the document is not already open in the workspace, check if the file exists on disk before trying to open it, to avoid triggering unwanted "file not found" errors from the text document service
28+
const bytes = await this.fileService.readFile(uri);
29+
return new TextDecoder().decode(bytes);
30+
} else {
31+
return existingDoc.getText();
32+
}
33+
};
34+
const text = await raceCancellationError(getTextContent(uri), token);
35+
return new PromptFileParser().parse(uri, text);
2236
}
2337
}

0 commit comments

Comments
 (0)