JohnnyMorganz / luau-lsp

Language Server Implementation for Luau
MIT License
247 stars 58 forks source link

`:FindFirstChild()` and similar functions shouldn't override the type when the companion studio plugin is on #543

Closed Aspecky closed 4 months ago

Aspecky commented 9 months ago

The . operator gives proper autocompletes about the children of an instance when the companion studio plugin is on, but when getting the children using :FindFirstChild or similar, the type gets overridden which makes you lose autocompletes:

local template = workspace.TemplateR15
local head = template.Head -- gets proper autocompletes and is typed correctly

local template = workspace:FindFirstChild("TemplateR15")
local head = template.Head -- type is *error-type*

Roblox studio also does respect those functions along with their arguments whereas luau-lsp doesnt, e.g:

--[[
    Animator is not a direct child of TemplateR15, it is a descendant of it
    |_ TemplateR15
        |_ Humanoid
        |   |_ Animator
        |_ ...
]]
local template = workspace.TemplateR15
local animator = template:FindFirstChild("Animator") -- type is Instance?

local template = workspace.TemplateR15
local animator = template:FindFirstChild("Animator", true) -- type is Animator

This logic applies to all the functions that traverse the tree of an instance.

Current workaround is to cast the type using typeof(Instance.Child) but that can get verbose very quick.

JohnnyMorganz commented 9 months ago

EDIT: nvm, I am wrong. I will look into this

Aspecky commented 9 months ago

Could you also see into FindFirstChild and WaitForChild autocompleting the children like it does in studio or does that deserve its own issue?

This is what I mean:

image

JohnnyMorganz commented 4 months ago

Sorry for the delay in this. Your second comment will be under the #685 issue. I will also fix the first part for this. I will make a separate issue (#689) about supporting recursive find first childs.

JohnnyMorganz commented 4 months ago

Fixed by f657718dcb1d709e82cb7202e242b34530cd7d6c