fixed in_rule_line, in_reduce_action bool combination into LocationType enum - #87
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the LSP completion and hover logic by replacing boolean flags with a more precise LocationType enum (Outside, NonTerminalDefinition, ProductionLine, ReduceAction). This change enables context-aware completions and hovers, preventing irrelevant suggestions such as directives inside reduce actions. Feedback on this PR highlights a regression where hovering over global substitution variables (e.g., $num or $Expr) inside a non-terminal definition header returns None because hover documentation lookups are now restricted to LocationType::ReduceAction. A fix is suggested to allow dollar-name substitution lookups when the location type is LocationType::NonTerminalDefinition.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| documentation = match location_type { | ||
| LocationType::ReduceAction => reduce_action_variable_documentation(args, &word) | ||
| .or_else(|| { | ||
| reduce_action_reference_documentation_for_word(args, content, offset, &word) | ||
| }), | ||
| LocationType::Outside | ||
| | LocationType::NonTerminalDefinition | ||
| | LocationType::ProductionLine => None, | ||
| }; |
There was a problem hiding this comment.
Hovering over global substitution variables (such as $num or $Expr) in a non-terminal definition header (e.g., Expr($num)) will return None because reduce_action_reference_documentation_for_word is only called when location_type is LocationType::ReduceAction.
To fix this regression, we should allow calling dollar_name_substitution_documentation when location_type is LocationType::NonTerminalDefinition and the hovered word starts with $ (excluding numeric positional variables).
documentation = match location_type {
LocationType::ReduceAction => reduce_action_variable_documentation(args, &word)
.or_else(|| {
reduce_action_reference_documentation_for_word(args, content, offset, &word)
}),
LocationType::NonTerminalDefinition => {
if word.starts_with('$') && word.strip_prefix('$').and_then(|s| s.parse::<usize>().ok()).is_none() {
dollar_name_substitution_documentation(args, content, &word)
} else {
None
}
}
LocationType::Outside | LocationType::ProductionLine => None,
};
LocationType: