Skip to content

Commit 5ccacbe

Browse files
authored
fix: include instance in selected context (#2913)
1 parent 2931e91 commit 5ccacbe

File tree

1 file changed

+35
-22
lines changed
  • apps/web/client/src/components/store/editor/chat

1 file changed

+35
-22
lines changed

apps/web/client/src/components/store/editor/chat/context.ts

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -170,38 +170,51 @@ export class ChatContext {
170170
const highlightedContext: HighlightMessageContext[] = [];
171171
for (const node of selected) {
172172
const oid = node.oid;
173-
if (!oid) {
174-
console.error('No oid found for node', node);
175-
continue;
176-
}
173+
const instanceId = node.instanceId;
177174

178-
const codeBlock = await this.editorEngine.templateNodes.getCodeBlock(oid);
179-
if (codeBlock === null) {
180-
console.error('No code block found for node', node);
181-
continue;
175+
if (oid) {
176+
const context = await this.getHighlightContextById(oid, node.tagName, false);
177+
if (context) highlightedContext.push(context);
182178
}
183179

184-
const templateNode = this.editorEngine.templateNodes.getTemplateNode(oid);
185-
if (!templateNode) {
186-
console.error('No template node found for node', node);
187-
continue;
180+
if (instanceId) {
181+
const context = await this.getHighlightContextById(instanceId, node.tagName, true);
182+
if (context) highlightedContext.push(context);
188183
}
189184

190-
highlightedContext.push({
191-
type: MessageContextType.HIGHLIGHT,
192-
displayName: node.tagName.toLowerCase(),
193-
path: templateNode.path,
194-
content: codeBlock,
195-
start: templateNode.startTag.start.line,
196-
end: templateNode.endTag?.end.line || templateNode.startTag.start.line,
197-
oid,
198-
branchId: templateNode.branchId,
199-
});
185+
if (!oid && !instanceId) {
186+
console.error('No oid or instanceId found for node', node);
187+
}
200188
}
201189

202190
return highlightedContext;
203191
}
204192

193+
private async getHighlightContextById(id: string, tagName: string, isInstance: boolean): Promise<HighlightMessageContext | null> {
194+
const codeBlock = await this.editorEngine.templateNodes.getCodeBlock(id);
195+
if (codeBlock === null) {
196+
console.error('No code block found for id', id);
197+
return null;
198+
}
199+
200+
const templateNode = this.editorEngine.templateNodes.getTemplateNode(id);
201+
if (!templateNode) {
202+
console.error('No template node found for id', id);
203+
return null;
204+
}
205+
206+
return {
207+
type: MessageContextType.HIGHLIGHT,
208+
displayName: (isInstance && templateNode.component) ? templateNode.component : tagName.toLowerCase(),
209+
path: templateNode.path,
210+
content: codeBlock,
211+
start: templateNode.startTag.start.line,
212+
end: templateNode.endTag?.end.line || templateNode.startTag.start.line,
213+
oid: id,
214+
branchId: templateNode.branchId,
215+
};
216+
}
217+
205218
// TODO: Enhance with custom rules
206219
getProjectContext(): ProjectMessageContext[] {
207220
return [

0 commit comments

Comments
 (0)