@@ -122,6 +122,24 @@ bool GDScriptParser::annotation_exists(const String &p_annotation_name) const {
122122 return valid_annotations.has (p_annotation_name);
123123}
124124
125+ GDScriptTokenizer::Token GDScriptParser::get_token (int p_line, int p_column) const {
126+ ERR_FAIL_COND_V (p_line < 1 , {});
127+ ERR_FAIL_COND_V (p_column < 1 , {});
128+
129+ Pair<int , int > position = { p_line, p_column };
130+
131+ for (const GDScriptTokenizer::Token &token : tokens) {
132+ GDScriptTokenizer::CodeArea token_area = token.get_code_area ();
133+ if (token_area.contains (position)) {
134+ return token;
135+ }
136+ if (token_area.is_after (position)) {
137+ return {};
138+ }
139+ }
140+ return {};
141+ }
142+
125143GDScriptParser::GDScriptParser () {
126144 // Register valid annotations.
127145 if (unlikely (valid_annotations.is_empty ())) {
@@ -377,42 +395,13 @@ void GDScriptParser::set_last_completion_call_arg(int p_argument) {
377395 completion_call_stack.back ()->get ().argument = p_argument;
378396}
379397
380- bool GDScriptParser::refactor_rename_is_cursor_between_tokens (const GDScriptTokenizer::Token &p_token_start, const GDScriptTokenizer::Token &p_token_end) const {
381- if (!is_for_refactor_rename ()) {
382- return false ;
383- }
384- if (p_token_start.type == GDScriptTokenizer::Token::Type::EMPTY || p_token_end.type == GDScriptTokenizer::Token::Type::EMPTY) {
385- return false ;
386- }
387-
388- if (previous.start_line < p_token_start.start_line ) {
389- return false ;
390- }
391- if (p_token_end.end_line < previous.end_line ) {
392- return false ;
393- }
394- if (previous.start_column < p_token_start.start_column ) {
395- return false ;
396- }
397- if (p_token_end.end_column < previous.end_column ) {
398- return false ;
399- }
400-
401- return true ;
402- }
403-
404398bool GDScriptParser::refactor_rename_does_node_contains_cursor (const GDScriptParser::Node *p_node) const {
405399 if (!is_for_refactor_rename ()) {
406400 return false ;
407401 }
408402 ERR_FAIL_NULL_V (p_node, false );
409- if (tokenizer->get_cursor_line () < p_node->start_line || tokenizer->get_cursor_line () > p_node->end_line ) {
410- return false ;
411- }
412- if (tokenizer->get_cursor_column () < p_node->start_column || tokenizer->get_cursor_column () > p_node->end_column ) {
413- return false ;
414- }
415- return true ;
403+
404+ return p_node->get_code_area ().contains (tokenizer->get_cursor_line (), tokenizer->get_cursor_column ());
416405}
417406
418407bool GDScriptParser::refactor_rename_does_token_have_cursor (const GDScriptTokenizer::Token &p_token) const {
@@ -436,30 +425,12 @@ bool GDScriptParser::refactor_rename_is_node_more_specific(const GDScriptParser:
436425 ERR_FAIL_NULL_V (refactor_rename_context.node , false );
437426
438427 GDScriptParser::Node *other_node = refactor_rename_context.node ;
439-
440- // `p_node` must start after `other_node`.
441- if (p_node->start_line < other_node->start_line ) {
442- return false ;
443- }
444- if (p_node->start_line == other_node->start_line && p_node->start_column < other_node->start_column ) {
445- return false ;
446- }
447- // If `other_node` ends before `p_node` starts, `p_node` is more specific.
448- if (other_node->end_line < p_node->start_line ) {
428+ GDScriptTokenizer::CodeArea other_code_area = other_node->get_code_area ();
429+ GDScriptTokenizer::CodeArea node_code_area = p_node->get_code_area ();
430+ if (node_code_area.is_after (other_code_area)) {
449431 return true ;
450432 }
451- if (other_node->end_line == p_node->start_line && other_node->end_column < p_node->start_column ) {
452- return true ;
453- }
454- // `p_node` must end before `other_node`.
455- if (p_node->end_line > other_node->end_line ) {
456- return false ;
457- }
458- if (p_node->end_line == other_node->end_line && p_node->end_column > other_node->end_column ) {
459- return false ;
460- }
461-
462- return true ;
433+ return other_code_area.contains (node_code_area);
463434}
464435
465436void GDScriptParser::refactor_rename_set_context (RefactorRenameType p_type) {
@@ -478,87 +449,6 @@ void GDScriptParser::refactor_rename_set_context(RefactorRenameType p_type) {
478449 refactor_rename_context = context;
479450}
480451
481- // void GDScriptParser::make_refactor_rename_context(RefactorRenameContextSetup p_setup) {
482- // if (!is_for_refactor_rename()) {
483- // return;
484- // }
485-
486- // if (p_setup.flags.has_flag(RefactorRenameContextSetup::OVERRIDE)) {
487- // if (p_setup.overriden_node == nullptr) {
488- // return;
489- // }
490- // if (refactor_rename_context.node != p_setup.overriden_node) {
491- // return;
492- // }
493- // }
494-
495- // if (p_setup.flags.has_flag(RefactorRenameContextSetup::CHECK_TOKEN_FOR_CURSOR)) {
496- // ERR_FAIL_NULL(p_setup.token);
497- // if (p_setup.token->cursor_place == GDScriptTokenizer::CURSOR_NONE) {
498- // return;
499- // }
500- // }
501-
502- // if (p_setup.flags.has_flag(RefactorRenameContextSetup::CHECK_IF_CURSOR_IS_INBETWEEN_TOKEN_START_END)) {
503- // ERR_FAIL_NULL(p_setup.token_start);
504- // ERR_FAIL_NULL(p_setup.token_end);
505- // if (p_setup.token_start->type == GDScriptTokenizer::Token::Type::EMPTY || p_setup.token_end->type == GDScriptTokenizer::Token::Type::EMPTY) {
506- // return;
507- // }
508-
509- // if (previous.start_line < p_setup.token_start->start_line) {
510- // return;
511- // }
512- // if (p_setup.token_end->end_line < previous.end_line) {
513- // return;
514- // }
515- // if (previous.start_column < p_setup.token_start->start_column) {
516- // return;
517- // }
518- // if (p_setup.token_end->end_column < previous.end_column) {
519- // return;
520- // }
521- // }
522-
523- // if (p_setup.flags.has_flag(RefactorRenameContextSetup::CHECK_FOR_CURSOR)) {
524- // if (previous.cursor_place == GDScriptTokenizerText::CURSOR_NONE && current.cursor_place == GDScriptTokenizerText::CURSOR_NONE) {
525- // return;
526- // }
527- // }
528-
529- // if (p_setup.flags.has_flag(RefactorRenameContextSetup::CHECK_SPECIFICITY)) {
530- // if (refactor_rename_context.node) {
531- // }
532- // }
533-
534- // RefactorRenameContext context;
535- // context.type = p_setup.type;
536- // context.current_class = current_class;
537- // context.current_function = current_function;
538- // context.current_suite = current_suite;
539- // context.current_line = tokenizer->get_cursor_line();
540- // context.parser = this;
541-
542- // if (p_setup.flags.has_flag(RefactorRenameContextSetup::APPLY_OVERRIDEN_NODE)) {
543- // context.node = p_setup.node;
544- // }
545-
546- // if (p_setup.flags.has_flag(RefactorRenameContextSetup::APPLY_CURRENT_ARGUMENT)) {
547- // context.current_argument = p_setup.current_argument;
548- // }
549-
550- // if (p_setup.flags.has_flag(RefactorRenameContextSetup::APPLY_BUILTIN_TYPE)) {
551- // context.builtin_type = p_setup.builtin_type;
552- // }
553-
554- // if (p_setup.flags.has_flag(RefactorRenameContextSetup::APPLY_TOKEN)) {
555- // ERR_FAIL_NULL(p_setup.token);
556- // context.token = *p_setup.token;
557- // }
558-
559- // refactor_rename_context = context;
560- // }
561-
562452Error GDScriptParser::parse (const String &p_source_code, const String &p_script_path, ParsingType p_type, bool p_parse_body) {
563453 clear ();
564454
@@ -687,6 +577,8 @@ GDScriptTokenizer::Token GDScriptParser::advance() {
687577 update_extents (n);
688578 }
689579 }
580+
581+ tokens.push_back (previous);
690582 return previous;
691583}
692584
@@ -3663,10 +3555,6 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_attribute(ExpressionNode *
36633555 Variant::Type builtin_type = get_builtin_type (id->name );
36643556 if (builtin_type < Variant::VARIANT_MAX) {
36653557 make_completion_context (COMPLETION_BUILT_IN_TYPE_CONSTANT_OR_STATIC_METHOD, builtin_type);
3666- if (refactor_rename_was_cursor_just_parsed ()) {
3667- refactor_rename_set_context (REFACTOR_RENAME_TYPE_BUILT_IN_TYPE_CONSTANT_OR_STATIC_METHOD);
3668- refactor_rename_context.builtin_type = builtin_type;
3669- }
36703558 is_builtin = true ;
36713559 }
36723560 }
0 commit comments