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

Commit 91396fc

Browse files
authored
Merge pull request #4733 from microsoft/aeschli/expected-swan-713
PromptsServiceImpl: avoid using openTextDocument to not trigger validation
2 parents fde4cfe + c001885 commit 91396fc

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ describe('CopilotCLIChatSessionParticipant.handleRequest', () => {
413413
workspaceFolderService,
414414
telemetry,
415415
logger,
416-
new PromptsServiceImpl(new NullWorkspaceService()),
416+
new PromptsServiceImpl(new NullWorkspaceService(), fileSystem),
417417
delegationService,
418418
folderRepositoryManager,
419419
configurationService,
@@ -758,7 +758,7 @@ describe('CopilotCLIChatSessionParticipant.handleRequest', () => {
758758
workspaceFolderService,
759759
telemetry,
760760
logService,
761-
new PromptsServiceImpl(new NullWorkspaceService()),
761+
new PromptsServiceImpl(new NullWorkspaceService(), new MockFileSystemService()),
762762
new class extends mock<IChatDelegationSummaryService>() {
763763
override async summarize(_context: vscode.ChatContext, _token: vscode.CancellationToken): Promise<string | undefined> {
764764
return undefined;
@@ -1903,7 +1903,7 @@ describe('CopilotCLIChatSessionParticipant.handleRequest', () => {
19031903
workspaceFolderService,
19041904
telemetry,
19051905
logService,
1906-
new PromptsServiceImpl(new NullWorkspaceService()),
1906+
new PromptsServiceImpl(new NullWorkspaceService(), new MockFileSystemService()),
19071907
nullDelegationService,
19081908
folderRepositoryManager,
19091909
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 the creating 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)