Repository: godot
Issue: Autocompletion from `get_node()` still does not work for some cases
Labels: bug,topic:gdscript,topic:editor

### Tested versions

v4.2.1.stable.official [b09f793f5]
v4.2.1.stable.official [b09f793f5] + #85224
v3.5.3.stable.official [6c814135b]

### System information

Ubuntu 20.04 LTS

### Issue description

Since https://github.com/godotengine/godot/pull/79386, autocompletion improved, but it still does not work for other `get_node()` cases.
This is a regression (since GDScript 2.0 as far as I can tell) from Godot 3.5 since all cases (except 4, see `NOTES` in `Steps to reproduce`) autocomplete.

These related bugs differ slightly and are not using `get_node()` directly.
https://github.com/godotengine/godot/issues/74888 (custom function returns)
https://github.com/godotengine/godot/issues/71296 (autoload)
https://github.com/godotengine/godot/issues/78860 (superseded by this new bug, I also thought it's a little unclear)
https://github.com/godotengine/godot/issues/78820 (return from Dictionary)

I also thought it would be nice to have one MRP to exhaust all combinations for `get_node()` autocompletion since it's a common usecase.

### Steps to reproduce

1. Load the MRP
2. In the script attached to node `A`.  Try typing out `do_something()` and observe similar behavior as noted in the comments.  I've pasted script `A.gd` below for reference.
``` gdscript
extends Control

@onready var b = $B
@onready var b_get_node = get_node("B")
@onready var b_typed := $B
@onready var b_typed_get_node := get_node("B")

@onready var c = $C
@onready var c_get_node = get_node("C")
@onready var c_typed : C = $C
@onready var c_typed_get_node : C = get_node("C")

var d
var d_get_node

var e
var e_get_node
var e_typed : E
var e_typed_get_node : E

@onready var f = %F
@onready var f_get_node = get_node("%F")
@onready var f_typed := %F
@onready var f_typed_get_node := get_node("%F")

@onready var g = %G
@onready var g_get_node = get_node("%G")
@onready var g_typed : G = %G
@onready var g_typed_get_node : G = get_node("%G")

var h
var h_get_node

var i
var i_get_node
var i_typed : I
var i_typed_get_node : I

func _ready():
  # -- B (onready)

  # inline
  $B.do_something() # autocompletes with 4.2.1-stable + #85224 + #86111
  get_node("B").do_something() # does not autocomplete

  # script vars
  b.do_something() # autocompletes
  b_get_node.do_something() # does not autocomplete
  b_typed.do_something() # autocompletes
  b_typed_get_node.do_something() # does not autocomplete

  # local vars
  var blocal = $B
  var blocal_get_node = get_node("B")
  var blocal_typed := $B
  var blocal_typed_get_node := get_node("B")
  blocal.do_something() # does not autocomplete
  blocal_get_node.do_something() # does not autocomplete
  blocal_typed.do_something() # does not autocomplete
  blocal_typed_get_node.do_something() # does not autocomplete

  # -- C (onready, class_name)

  # inline
  $C.do_something() # autocompletes with 4.2.1-stable + #85224 + #86111
  get_node("C").do_something() # does not autocomplete

  # script vars
  c.do_something() # autocompletes
  c_get_node.do_something() # does not autocomplete
  c_typed.do_something() # autocompletes
  c_typed_get_node.do_something() # autocompletes

  # local vars
  var clocal = $C
  var clocal_get_node = get_node("C")
  var clocal_typed : C = $C
  var clocal_typed_get_node : C = get_node("C")
  clocal.do_something() # does not autocomplete
  clocal_get_node.do_something() # does not autocomplete
  clocal_typed.do_something() # autocompletes with 4.2.1-stable + #85224
  clocal_typed_get_node.do_something() # autocompletes with 4.2.1-stable + #85224

  # -- D

  # script vars
  d = $D
  d.do_something() # does not autocomplete
  d_get_node = get_node("D")
  d_get_node.do_something() # does not autocomplete

  # -- E (class_name)

  # script vars
  e = $E
  e.do_something() # does not autocomplete
  e_get_node = get_node("E")
  e_get_node.do_something() # does not autocomplete
  e_typed = $E
  e_typed.do_something() # autocompletes with 4.2.1-stable + #85224 + #86111
  e_typed_get_node = get_node("E")
  e_typed_get_node.do_something() # autocompletes with 4.2.1-stable + #85224 + #86111

  # -- F (onready, unique name)

  # inline
  %F.do_something() # autocompletes with 4.2.1-stable + #85224 + #86111
  get_node("%F").do_something() # does not autocomplete

  # script vars
  f.do_something() # autocompletes
  f_get_node.do_something() # does not autocomplete
  f_typed.do_something() # autocompletes
  f_typed_get_node.do_something() # does not autocomplete

  # local vars
  var flocal = %F
  var flocal_get_node = get_node("%F")
  var flocal_typed := %F
  var flocal_typed_get_node := get_node("%F")
  flocal.do_something() # does not autocomplete
  flocal_get_node.do_something() # does not autocomplete
  flocal_typed.do_something() # does not autocomplete
  flocal_typed_get_node.do_something() # does not autocomplete

  # -- G (onready, class_name, unique name)

  # inline
  %G.do_something() # autocompletes with 4.2.1-stable + #85224 + #86111
  get_node("%G").do_something() # does not autocomplete

  # script vars
  g.do_something() # autocompletes
  g_get_node.do_something() # does not autocomplete
  g_typed.do_something() # autocompletes
  g_typed_get_node.do_something() # autocompletes

  # local vars
  var glocal = %G
  var glocal_get_node = get_node("%G")
  var glocal_typed : G = %G
  var glocal_typed_get_node : G = get_node("%G")
  glocal.do_something() # does not autocomplete
  glocal_get_node.do_something() # does not autocomplete
  glocal_typed.do_something() # autocompletes with 4.2.1-stable + #85224
  glocal_typed_get_node.do_something() # autocompletes with 4.2.1-stable + #85224

  # -- H (unique_name)

  # script vars
  h = %H
  h.do_something() # does not autocomplete
  h_get_node = get_node("%H")
  h_get_node.do_something() # does not autocomplete

  # -- I (class_name, unique_name)

  # script vars
  i = %I
  i.do_something() # does not autocomplete
  i_get_node = get_node("%I")
  i_get_node.do_something() # does not autocomplete
  i_typed = %I
  i_typed.do_something() # autocompletes with 4.2.1-stable + #85224 + #86111
  i_typed_get_node = get_node("%I")
  i_typed_get_node.do_something() # autocompletes with 4.2.1-stable + #85224 + #86111
```

**NOTES**
- These repro steps were intended to be an exhaustive list of `get_node()` that does not include custom functions, inlined classes, or returns from other data types (like Dictionaries).  It is likely I missed some cases though.
- I ran the same test with https://github.com/godotengine/godot/pull/85224 cherry-picked to 4.2.1-stable.  It improves autocompletion slightly; the differences are noted in the comments.
EDIT: updated with 4.2.1-stable + #85224 + #86111
EDIT (12/25/2023): updated again with latest #85224.  Also made some of the comments consistent.
- I ran the same test with v3.5.3.stable.official [6c814135b] (in a 3.5.3 project; I didn't include the MRP), and all applicable cases autocomplete correctly except for these:
``` gdscript
  blocal.do_something()
  blocal_get_node.do_something()
  blocal_typed.do_something()
  blocal_typed_get_node.do_something()
```

### Minimal reproduction project (MRP)

[getnodebug.zip](https://github.com/godotengine/godot/files/13677406/getnodebug.zip)