@@ -170,38 +170,51 @@ export class ChatContext {
170
170
const highlightedContext : HighlightMessageContext [ ] = [ ] ;
171
171
for ( const node of selected ) {
172
172
const oid = node . oid ;
173
- if ( ! oid ) {
174
- console . error ( 'No oid found for node' , node ) ;
175
- continue ;
176
- }
173
+ const instanceId = node . instanceId ;
177
174
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 ) ;
182
178
}
183
179
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 ) ;
188
183
}
189
184
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
+ }
200
188
}
201
189
202
190
return highlightedContext ;
203
191
}
204
192
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
+
205
218
// TODO: Enhance with custom rules
206
219
getProjectContext ( ) : ProjectMessageContext [ ] {
207
220
return [
0 commit comments