Skip to content

Commit

Permalink
Fix refactor context
Browse files Browse the repository at this point in the history
  • Loading branch information
adamscott committed Dec 19, 2024
1 parent be8af36 commit dd2801d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
26 changes: 25 additions & 1 deletion modules/gdscript/gdscript_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,26 @@ void GDScriptParser::make_refactor_context(GDScriptParser::RefactorSymbolType p_
if (!for_refactor) {
return;
}
if (previous.cursor_place != GDScriptTokenizerText::CURSOR_MIDDLE && previous.cursor_place != GDScriptTokenizerText::CURSOR_END && current.cursor_place == GDScriptTokenizerText::CURSOR_NONE) {
return;
}

RefactorContext context;
context.type = p_type;
context.current_line = tokenizer->get_cursor_line();
context.node = p_node;
context.parser = this;
refactor_context = context;
}

void GDScriptParser::override_refactor_context(const Node *p_for_node, GDScriptParser::RefactorSymbolType p_type, Node *p_node) {
if (!for_refactor) {
return;
}
if (p_for_node == nullptr || completion_context.node != p_for_node) {
return;
}

RefactorContext context;
context.type = p_type;
context.current_line = tokenizer->get_cursor_line();
Expand Down Expand Up @@ -1746,6 +1766,7 @@ GDScriptParser::AnnotationNode *GDScriptParser::parse_annotation(uint32_t p_vali

if (argument->type == Node::LITERAL) {
override_completion_context(argument, COMPLETION_ANNOTATION_ARGUMENTS, annotation, argument_index);
override_refactor_context(argument, REFACTOR_SYMBOL_ANNOTATION_ARGUMENTS, annotation);
}
}

Expand Down Expand Up @@ -3082,6 +3103,7 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_assignment(ExpressionNode
#ifdef TOOLS_ENABLED
if (assignment->assigned_value != nullptr && assignment->assigned_value->type == GDScriptParser::Node::IDENTIFIER) {
override_completion_context(assignment->assigned_value, COMPLETION_ASSIGN, assignment);
override_refactor_context(assignment->assigned_value, REFACTOR_SYMBOL_ASSIGN, assignment);
}
#endif
if (assignment->assigned_value == nullptr) {
Expand Down Expand Up @@ -3241,7 +3263,7 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_attribute(ExpressionNode *
reset_extents(attribute, p_previous_operand);
update_extents(attribute);

if (for_completion) {
if (for_completion || for_refactor) {
bool is_builtin = false;
if (p_previous_operand && p_previous_operand->type == Node::IDENTIFIER) {
const IdentifierNode *id = static_cast<const IdentifierNode *>(p_previous_operand);
Expand Down Expand Up @@ -3290,6 +3312,7 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_subscript(ExpressionNode *
#ifdef TOOLS_ENABLED
if (subscript->index != nullptr && subscript->index->type == Node::LITERAL) {
override_completion_context(subscript->index, COMPLETION_SUBSCRIPT, subscript);
override_refactor_context(subscript->index, RefactorSymbolType::REFACTOR_SYMBOL_SUBSCRIPT, subscript);
}
#endif

Expand Down Expand Up @@ -3411,6 +3434,7 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_call(ExpressionNode *p_pre

if (argument->type == Node::LITERAL) {
override_completion_context(argument, completion_type, call, argument_index);
override_refactor_context(argument, symbol_type, call);
}
}

Expand Down
1 change: 1 addition & 0 deletions modules/gdscript/gdscript_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,7 @@ class GDScriptParser {
void set_last_completion_call_arg(int p_argument);

void make_refactor_context(RefactorSymbolType p_type, Node *p_node);
void override_refactor_context(const Node *p_for_node, RefactorSymbolType p_type, Node *p_node);

GDScriptTokenizer::Token advance();
bool match(GDScriptTokenizer::Token::Type p_token_type);
Expand Down

0 comments on commit dd2801d

Please sign in to comment.