luau-lsp
luau-lsp copied to clipboard
`:FindFirstChild()` and similar functions shouldn't override the type when the companion studio plugin is on
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.
EDIT: nvm, I am wrong. I will look into this
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: