luau-lsp icon indicating copy to clipboard operation
luau-lsp copied to clipboard

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

Open Aspecky opened this issue 1 year ago • 2 comments

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.

Aspecky avatar Jan 26 '24 15:01 Aspecky

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

JohnnyMorganz avatar Jan 27 '24 10:01 JohnnyMorganz

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

Aspecky avatar Jan 29 '24 12:01 Aspecky