Skip to content

Commit d2c2a22

Browse files
committed
add more doc comments
1 parent 2da00ee commit d2c2a22

File tree

5 files changed

+58
-55
lines changed

5 files changed

+58
-55
lines changed

src/vs/workbench/contrib/chat/common/promptFileReferenceErrors.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ export class RecursiveReference extends ResolveError {
135135
uri,
136136
`Recursive references found: ${pathString}.`,
137137
);
138-
this.recursivePathString = pathString;
139138
}
140139

141140
/**
@@ -145,6 +144,14 @@ export class RecursiveReference extends ResolveError {
145144
filename: 'basename' | 'fullpath',
146145
pathJoinCharacter: string = DEFAULT_RECURSIVE_PATH_JOIN_CHAR,
147146
): string {
147+
/**
148+
* TODO: @lego - this not currently true though
149+
* TODO: @lego - cache
150+
*/
151+
if (filename === 'fullpath' && pathJoinCharacter === DEFAULT_RECURSIVE_PATH_JOIN_CHAR) {
152+
return this.recursivePathString;
153+
}
154+
148155
return this.recursivePath
149156
.map((path) => {
150157
if (filename === 'fullpath') {
@@ -176,6 +183,8 @@ export class RecursiveReference extends ResolveError {
176183
return false;
177184
}
178185

186+
// TODO: @lego - check array lengths first
187+
179188
// performance optimization - if the paths lengths don't match,
180189
// no need to compare entire strings as they must be different
181190
if (this.recursivePathString.length !== other.recursivePathString.length) {

src/vs/workbench/contrib/chat/common/promptSyntax/languageFeatures/promptLinkDiagnosticsProvider.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ import { IConfigurationService } from '../../../../../../platform/configuration/
2525
import { IMarkerData, IMarkerService, MarkerSeverity } from '../../../../../../platform/markers/common/markers.js';
2626

2727
/**
28-
* TODO: @legomushroom
28+
* Unique ID of the markers provider class.
2929
*/
3030
const MARKERS_OWNER_ID = 'reusable-prompts-syntax';
3131

3232
/**
33-
* TODO: @legomushroom
33+
* Prompt links diagnostics provider for a single text model.
3434
*/
3535
class PromptLinkDiagnosticsProvider extends ObservableDisposable {
3636
/**
37-
* TODO: @legomushroom
37+
* Reference to the current prompt syntax parser instance.
3838
*/
3939
private readonly parser: TextModelPromptParser;
4040

@@ -56,7 +56,7 @@ class PromptLinkDiagnosticsProvider extends ObservableDisposable {
5656
}
5757

5858
/**
59-
* TODO: @legomushroom
59+
* Update diagnostic markers for the current editor.
6060
*/
6161
private async updateMarkers() {
6262
// ensure that parsing process is settled
@@ -94,9 +94,14 @@ class PromptLinkDiagnosticsProvider extends ObservableDisposable {
9494
}
9595

9696
/**
97-
* TODO: @legomushroom
97+
* Convert a prompt link with an issue to a marker data.
98+
*
99+
* @throws
100+
* - if there is no link issue (e.g., `topError` undefined)
101+
* - if there is no link range to highlight (e.g., `linkRange` undefined)
102+
* - if the original error is of `NotPromptFile` type - we don't want to
103+
* show diagnostic markers for non-prompt file links in the prompts
98104
*/
99-
// TODO: @legomushroom - add @throws info
100105
const toMarker = (
101106
link: IPromptFileReference,
102107
): IMarkerData => {
@@ -132,11 +137,12 @@ const toMarker = (
132137
};
133138

134139
/**
135-
* TODO: @legomushroom
140+
* The class that manages creation and disposal of {@link PromptLinkDiagnosticsProvider}
141+
* classes for each specific editor text model.
136142
*/
137-
export class PromptsLinkDiagnosticsProvider extends Disposable {
143+
export class PromptLinkDiagnosticsInstanceManager extends Disposable {
138144
/**
139-
* TODO: @legomushroom
145+
* Currently available {@link PromptLinkDiagnosticsProvider} instances.
140146
*/
141147
private readonly providers: ObjectCache<PromptLinkDiagnosticsProvider, ITextModel>;
142148

@@ -187,7 +193,7 @@ export class PromptsLinkDiagnosticsProvider extends Disposable {
187193
}
188194

189195
/**
190-
* TODO: @legomushroom
196+
* Initialize a new {@link PromptLinkDiagnosticsProvider} for the given editor.
191197
*/
192198
private handleNewEditor(editor: IEditor): this {
193199
const model = editor.getModel();
@@ -215,4 +221,4 @@ export class PromptsLinkDiagnosticsProvider extends Disposable {
215221

216222
// register the provider as a workbench contribution
217223
Registry.as<IWorkbenchContributionsRegistry>(Extensions.Workbench)
218-
.registerWorkbenchContribution(PromptsLinkDiagnosticsProvider, LifecyclePhase.Eventually);
224+
.registerWorkbenchContribution(PromptLinkDiagnosticsInstanceManager, LifecyclePhase.Eventually);

src/vs/workbench/contrib/chat/common/promptSyntax/parsers/basePromptParser.ts

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -398,32 +398,18 @@ export abstract class BasePromptParser<T extends IPromptContentsProvider> extend
398398
}
399399

400400
/**
401-
* TODO: @legomushroom
401+
* Get list of errors for the direct links of the current reference.
402402
*/
403403
public get errors(): readonly ResolveError[] {
404-
// collect error conditions of direct child references
405-
const childErrors = this
406-
// get immediate references
407-
.references
408-
// filter out children without error conditions or
409-
// the ones that are non-prompt snippet files
410-
.filter((childReference) => {
411-
const { errorCondition } = childReference;
412-
413-
return errorCondition && !(errorCondition instanceof NotPromptFile);
414-
})
415-
// map to error condition objects
416-
.map((childReference): ResolveError => {
417-
const { errorCondition } = childReference;
418-
419-
// `must` always be `true` because of the `filter` call above
420-
assertDefined(
421-
errorCondition,
422-
`Error condition must be present for '${childReference.uri.path}'.`,
423-
);
424-
425-
return errorCondition;
426-
});
404+
const childErrors: ResolveError[] = [];
405+
406+
for (const reference of this.references) {
407+
const { errorCondition } = reference;
408+
409+
if (errorCondition && (!(errorCondition instanceof NotPromptFile))) {
410+
childErrors.push(errorCondition);
411+
}
412+
}
427413

428414
return childErrors;
429415
}

src/vs/workbench/contrib/chat/common/promptSyntax/parsers/topError.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import { assertDefined } from '../../../../../../base/common/types.js';
1010
import { OpenFailed, RecursiveReference, FailedToResolveContentsStream } from '../../promptFileReferenceErrors.js';
1111

1212
/**
13-
* TODO: @lego
13+
* The top-most error of the reference tree.
1414
*/
1515
export class TopError implements ITopError {
16-
public readonly errorSubject = this.options.errorSubject;
1716
public readonly originalError = this.options.originalError;
17+
public readonly errorSubject = this.options.errorSubject;
1818
public readonly errorsCount = this.options.errorsCount;
1919
public readonly parentUri = this.options.parentUri;
2020

@@ -24,7 +24,6 @@ export class TopError implements ITopError {
2424

2525

2626
public get localizedMessage(): string {
27-
// TODO: @legomushroom - update localization IDs
2827
const { originalError, parentUri, errorSubject: subject, errorsCount } = this;
2928

3029
assert(
@@ -33,37 +32,37 @@ export class TopError implements ITopError {
3332
);
3433

3534
// a note about how many more link issues are there
36-
const moreIssuesNote = (errorsCount > 1)
37-
? localize('chatPromptInstructionsBrokenReferenceSuffix222222', "\n(+{0} more issues)", errorsCount - 1)
35+
const moreIssuesLabel = (errorsCount > 1)
36+
? localize('workbench.reusable-prompts.top-error.more-issues-label', "\n(+{0} more issues)", errorsCount - 1)
3837
: '';
3938

4039
if (subject === 'root') {
4140
if (originalError instanceof OpenFailed) {
4241
return localize(
43-
'chatPromptInstructionsFileOpenFailed111',
42+
'workbench.reusable-prompts.top-error.open-failed',
4443
"Cannot open '{0}'.{1}",
4544
originalError.uri.path,
46-
moreIssuesNote,
45+
moreIssuesLabel,
4746
);
4847
}
4948

5049
if (originalError instanceof FailedToResolveContentsStream) {
5150
return localize(
52-
'chatPromptInstructionsStreamOpenFailed1111',
51+
'workbench.reusable-prompts.top-error.cannot-read',
5352
"Cannot read '{0}'.{1}",
5453
originalError.uri.path,
55-
moreIssuesNote,
54+
moreIssuesLabel,
5655
);
5756
}
5857

5958
if (originalError instanceof RecursiveReference) {
6059
return localize(
61-
'chatPromptInstructionsSelfRecursion4444',
60+
'workbench.reusable-prompts.top-error.recursive-reference',
6261
"Recursion to itself.",
6362
);
6463
}
6564

66-
return originalError.message + moreIssuesNote;
65+
return originalError.message + moreIssuesLabel;
6766
}
6867

6968
// a sanity check - because the error subject is not `root`, the parent must set
@@ -73,24 +72,27 @@ export class TopError implements ITopError {
7372
);
7473

7574
const errorMessageStart = (subject === 'child')
76-
? localize('chatPromptInstructionsBrokenReferenceFile', "Contains")
75+
? localize(
76+
'workbench.reusable-prompts.top-error.child.direct',
77+
"Contains",
78+
)
7779
: localize(
78-
'chatPromptInstructionsBrokenChildReference',
80+
'workbench.reusable-prompts.top-error.child.indirect',
7981
"Indirectly referenced prompt '{0}' contains",
8082
parentUri.path,
8183
);
8284

8385
const linkIssueName = (originalError instanceof RecursiveReference)
84-
? localize('chatPromptInstructionsBrokenChildRecursiveLink', "recursive")
85-
: localize('chatPromptInstructionsBrokenChildBrokenLink', "broken");
86+
? localize('recursive', "recursive")
87+
: localize('broken', "broken");
8688

8789
return localize(
88-
'chatPromptInstructionsBrokenReference111',
90+
'workbench.reusable-prompts.top-error.child.final-message',
8991
"{0} a {1} link to '{2}' that will be ignored.{3}",
9092
errorMessageStart,
9193
linkIssueName,
9294
originalError.uri.path,
93-
moreIssuesNote,
95+
moreIssuesLabel,
9496
);
9597
}
9698
}

src/vs/workbench/contrib/chat/common/promptSyntax/parsers/types.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { IDisposable } from '../../../../../../base/common/lifecycle.js';
99
import { IRange, Range } from '../../../../../../editor/common/core/range.js';
1010

1111
/**
12-
* TODO: @legomushroom
12+
* A resolve error with a parent prompt URI, if any.
1313
*/
1414
export interface IResolveError {
1515
/**
@@ -113,7 +113,7 @@ interface IPromptReferenceBase extends IDisposable {
113113
readonly errorCondition: ResolveError | undefined;
114114

115115
/**
116-
* TODO: @legomushroom
116+
* Get list of errors for the direct links of the current reference.
117117
*/
118118
readonly errors: readonly ResolveError[];
119119

0 commit comments

Comments
 (0)