Skip to content

Commit 83b6da4

Browse files
committed
emit fn issue solved
1 parent 236f548 commit 83b6da4

1 file changed

Lines changed: 48 additions & 3 deletions

File tree

src/features/realtime.ts

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,30 @@ export class RealtimeAnalyzer {
532532
let hintPos: vscode.Position;
533533

534534
if (isEvent) {
535-
// For events, show after 'emit EventName('
536-
hintPos = document.positionAt(match.index + match[0].length);
535+
// For events, find the closing parenthesis after emit
536+
const emitStart = match.index;
537+
const afterEmit = content.substring(emitStart);
538+
// Find matching closing parenthesis
539+
let depth = 0;
540+
let closingParenIndex = -1;
541+
for (let i = 0; i < afterEmit.length; i++) {
542+
if (afterEmit[i] === '(') {
543+
depth++;
544+
}
545+
if (afterEmit[i] === ')') {
546+
depth--;
547+
if (depth === 0) {
548+
closingParenIndex = i;
549+
break;
550+
}
551+
}
552+
}
553+
if (closingParenIndex !== -1) {
554+
hintPos = document.positionAt(emitStart + closingParenIndex + 1);
555+
} else {
556+
// Fallback: after opening paren if we can't find closing
557+
hintPos = document.positionAt(match.index + match[0].length);
558+
}
537559
} else {
538560
// For functions, modifiers, structs, constructors - show after '{'
539561
const braceIndex = match[0].lastIndexOf('{');
@@ -623,7 +645,30 @@ export class RealtimeAnalyzer {
623645
let hintPos: vscode.Position;
624646

625647
if (isEvent) {
626-
hintPos = document.positionAt(match.index + match[0].length);
648+
// For events, find the closing parenthesis after emit
649+
const emitStart = match.index;
650+
const afterEmit = content.substring(emitStart);
651+
// Find matching closing parenthesis
652+
let depth = 0;
653+
let closingParenIndex = -1;
654+
for (let i = 0; i < afterEmit.length; i++) {
655+
if (afterEmit[i] === '(') {
656+
depth++;
657+
}
658+
if (afterEmit[i] === ')') {
659+
depth--;
660+
if (depth === 0) {
661+
closingParenIndex = i;
662+
break;
663+
}
664+
}
665+
}
666+
if (closingParenIndex !== -1) {
667+
hintPos = document.positionAt(emitStart + closingParenIndex + 1);
668+
} else {
669+
// Fallback: after opening paren if we can't find closing
670+
hintPos = document.positionAt(match.index + match[0].length);
671+
}
627672
} else {
628673
const braceIndex = match[0].lastIndexOf('{');
629674
hintPos = document.positionAt(match.index + braceIndex + 1);

0 commit comments

Comments
 (0)