fix: improve {{var}} detection using cursor-based brace matching#6691
fix: improve {{var}} detection using cursor-based brace matching#6691sid-bruno merged 3 commits intousebruno:mainfrom
Conversation
WalkthroughReplaced token-based hover detection with cursor-position scanning in Changes
Sequence Diagram(s)(omitted — change is localized and does not introduce multi-component sequential flows requiring a diagram) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI Agents
In @packages/bruno-app/src/utils/codemirror/brunoVarInfo.js:
- Around line 880-882: Update the inaccurate inline comment immediately after
the else-if that uses variableNameRegex (the block that sets variableName = str
and variableValue = interpolate(get(variables, variableName), variables));
replace the existing text that says it only covers "{" "}" or random JSON syntax
with a clear fallback comment such as "Fallback: return undefined for strings
that don't match any supported format" and add a short JSDoc note near
variableNameRegex (the /^[\w-.]*$/ pattern) clarifying that it intentionally
allows word chars, hyphens, and dots and thus will match short strings.
🧹 Nitpick comments (1)
packages/bruno-app/src/utils/codemirror/brunoVarInfo.js (1)
883-885: Update comment to reflect broader scope.The comment states "If it's just '{', '}', or random JSON syntax" but this else block now catches ALL non-matching strings, not just those specific cases. Consider updating to:
} else { - // If it's just "{", "}", or random JSON syntax, return undefined + // No matching pattern - return undefined for non-variable strings return { variableName: undefined, variableValue: undefined }; }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/bruno-app/src/utils/codemirror/brunoVarInfo.js
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (CODING_STANDARDS.md)
**/*.{js,jsx,ts,tsx}: Use 2 spaces for indentation. No tabs, just spaces
Stick to single quotes for strings. For JSX/TSX attributes, use double quotes (e.g., )
Always add semicolons at the end of statements
No trailing commas
Always use parentheses around parameters in arrow functions, even for single params
For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
No newlines inside function parentheses
Space before and after the arrow in arrow functions.() => {}is good
No space between function name and parentheses.func()notfunc ()
Semicolons go at the end of the line, not on a new line
Names for functions need to be concise and descriptive
Add in JSDoc comments to add more details to the abstractions if needed
Add in meaningful comments instead of obvious ones where complex code flow is explained properly
Files:
packages/bruno-app/src/utils/codemirror/brunoVarInfo.js
🧠 Learnings (1)
📚 Learning: 2025-12-17T21:41:24.730Z
Learnt from: naman-bruno
Repo: usebruno/bruno PR: 6407
File: packages/bruno-app/src/components/Environments/ConfirmCloseEnvironment/index.js:5-41
Timestamp: 2025-12-17T21:41:24.730Z
Learning: Do not suggest PropTypes validation for React components in the Bruno codebase. The project does not use PropTypes, so reviews should avoid proposing PropTypes and rely on the existing typing/validation approach (e.g., TypeScript or alternative runtime checks) if applicable. This guideline applies broadly to all JavaScript/JSX components in the repo.
Applied to files:
packages/bruno-app/src/utils/codemirror/brunoVarInfo.js
| } else if (variableNameRegex.test(str)) { | ||
| variableName = str; | ||
| variableValue = interpolate(get(variables, variableName), variables); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# Find the variableNameRegex pattern definition
rg -n "variableNameRegex\s*=" packages/bruno-app/src/utils -A 2 --type=js --type=tsRepository: usebruno/bruno
Length of output: 285
🏁 Script executed:
# Check imports and usage of variableNameRegex in brunoVarInfo.js
rg -n "variableNameRegex" packages/bruno-app/src/utils/codemirror/brunoVarInfo.js -B 2 -A 2Repository: usebruno/bruno
Length of output: 776
🏁 Script executed:
# Find all calls to extractVariableInfo in the codebase
rg -n "extractVariableInfo\(" packages/bruno-app/src --type=js --type=ts -C 2Repository: usebruno/bruno
Length of output: 13754
🏁 Script executed:
# Read the full extractVariableInfo function to understand the context
sed -n '850,900p' packages/bruno-app/src/utils/codemirror/brunoVarInfo.js | cat -nRepository: usebruno/bruno
Length of output: 1727
Update the comment at line 883 to reflect the actual fallback behavior.
The new code at lines 880-882 is intentional—comprehensive test cases confirm it's a feature to support direct variable name references (e.g., baseUrl, userId). However, the comment at line 883 is inaccurate. It states "If it's just "{", "}", or random JSON syntax" but this block actually catches all other strings that don't match the three preceding patterns (double braces, path params, or valid variable names).
Suggest updating the comment to something like:
// Fallback: return undefined for strings that don't match any supported format
Also note: the regex /^[\w-.]*$/ is permissive and will match any string containing only word characters, hyphens, or dots—including very short strings. This is intentional per the test suite, but consider if this behavior should be documented in JSDoc.
🤖 Prompt for AI Agents
In @packages/bruno-app/src/utils/codemirror/brunoVarInfo.js around lines 880 -
882, Update the inaccurate inline comment immediately after the else-if that
uses variableNameRegex (the block that sets variableName = str and variableValue
= interpolate(get(variables, variableName), variables)); replace the existing
text that says it only covers "{" "}" or random JSON syntax with a clear
fallback comment such as "Fallback: return undefined for strings that don't
match any supported format" and add a short JSDoc note near variableNameRegex
(the /^[\w-.]*$/ pattern) clarifying that it intentionally allows word chars,
hyphens, and dots and thus will match short strings.

Description
This PR is for fixing hover tooltip {{...}} detection in JSON by matching around cursor and ignoring empty/escaped vars.
PR for fixing {{...}} detection in JSON - #6671
Jira
Contribution Checklist:
Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.
Publishing to New Package Managers
Please see here for more information.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.