Script Editor: Luau-Powered Autocomplete & Language Features Beta

Script Editor: Luau-Powered Autocomplete & Language Features Beta

Hi developers,

You (auto) complete us! Today we’re excited to announce a beta of our new Luau-powered autocomplete. Code completions will now be more comprehensive, more accurate, and more performant enabling you to code faster than ever before. Please see below for a breakdown of new functionality you should expect to work and a few things that are not implemented yet.

The beta can be enabled by toggling Studio > Beta Features > Luau-Powered Autocomplete.

New Features

Function parameters for functions in current script

Autocomplete will now give type-aligned completions for annotated function parameters. In the example below, autocomplete recognizes parameter ‘s’ as a string, and offers corresponding completions.

function abc(s:string)
    s...
end
Current New
With the cursor on a function parameter within a function, no autocomplete suggestions are shown With the cursor on a function parameter within a function, several autocomplete suggestions are shown

Nested variables and functions

Completions will now be given for variables nested within functions, regardless of possible indirection. In the below example autocomplete recognizes that P refers to a function that returns ‘x’ and ‘y’, and suggests completions for the two variables.

function origin()
    return {x = 0, y = 0}
end

local P = origin()
print(P...
Current New
With the cursor on a table returned by a function, no autocomplete suggestions are shown With the cursor on a table returned by a function, several autocomplete suggestions are shown

Context-aware keywords

When you begin a new expression or statement, autocomplete suggestions will have an emphasis on keywords that make sense at this syntactic position. In the below example the context-relevant keyword ‘true’ is suggested instead of generic completions that would not be syntactically sound.

if true t...
Current New
With the cursor after a "t" following an if statement, autocomplete suggestions many options With the cursor after a "t" following an if statement, autocomplete suggests "then"

Better awareness of instances as return types

Autocomplete will now show suggestions for functions that return an instance, as demonstrated by the below examples.

function getWorkspace()
    return workspace
end

getWorkspace()...
function getMyScripts()
    return game:getService("ReplicatedStorage")
end

getMyScripts()...
Current New
With the cursor after a function that returns "workspace", there are no autocomplete suggestions With the cursor after a function that returns "workspace", there are several autocomplete suggestions
With the cursor after a function that returns "ReplicatedStorage", there are no autocomplete suggestions With the cursor after a function that returns "ReplicatedStorage", there are several autocomplete suggestions

Access to Luau type annotations

Autocomplete uses its knowledge of the Luau architecture to suggest completions for type-annotated variables. In the example below p is recognized as a ‘Part’ and completions for corresponding properties are provided.

local p:Part

p...
Current New
With the cursor after a variable declared as "Part" type, there are no autocomplete suggestions With the cursor after a variable declared as "Part" type, there are several autocomplete suggestions

General Improvements

Improved recognition of local variable names

The previous iteration of autocomplete often failed to provide completions for locally declared variables. This will never occur with Luau-powered Autocomplete.

local some_int = 5

so...
Current New
With the cursor after a variable declared locally, autocomplete does not suggest completing the variable With the cursor after a variable declared locally, autocomplete suggests completing the variable

Logic improvements to reduce noise and improve ordering in autocomplete suggestions

We’ve refined our autocomplete search algorithm to provide and rank completions in a more intuitive way across the board. Below, completions can be seen that are likely much more in line with the user’s expectations than before.

enu...

ran...
Current New
With the cursor after text reading "enu", many autocomplete suggestions are shown With the cursor after text reading "enu", only "Enum" is suggested
With the cursor after text reading "ran", many autocomplete suggestions are shown With the cursor after text reading "ran", only "Random" and "NumberRange" are suggested

Identifying Expression Type: The Gritty Details

(you’ve been warned)

Meme of Gritty, NHL mascot of the Philadelphia Flyers

The new Autocomplete system (as well as a few other Script Editor features) use Luau types to provide accuracy in their suggestions and checks. Better types lead to better performance. In strict mode, everything behaves as intended. However, in nonstrict and nocheck mode, there is not enough type information present to inform these features - many expressions just return type “any” in these modes.

So what do we do? In the background, Studio actually runs two typecheck passes - one in whatever mode is specified in the Script header and one that is always in strict mode. This second strict pass is then used to inform the features that require it. Where types are displayed in the Studio UI, we are following the principle of “display the type that is informing the feature”. This means that a single expression may display different types in different Studio UI. Luckily this isn’t too complex:

Type Hover and Script Analysis will always utilize the “less strict” type associated with the first type-check pass, corresponding directly to the mode indicated in the script header. It logically follows that in nocheck mode, Type Hover will not appear (as the language service is not keeping track of any types).

Type Hover

--!nocheck --!nonstrict --!strict
Type hover does not work in nocheck mode Type hover displays "any" in nonstrict mode unless types are explicitly defined Type hover displays the resolved type in strict mode

Script Analysis

--!nocheck --!nonstrict --!strict
Script Analysis does not flag type errors in nocheck mode Script Analysis does not flag type errors in nonstrict mode Script Analysis will flag type errors in strict mode

Autocomplete, Signature Help, and Go To Declaration will always utilize the “most strict” type associated with the second type-check pass, regardless of the mode indicated in the script header.

Autocomplete

--!nocheck --!nonstrict --!strict
Autocomplete uses strict type to inform suggestions in nocheck mode Autocomplete uses strict type to inform suggestions in nonstrict mode Autocomplete uses strict type to inform suggestions in strict mode

Signature Help

--!nocheck --!nonstrict --!strict
Signature Help uses strict type to inform help hover in nocheck mode Signature Help uses strict type to inform help hover in nonstrict mode Signature Help uses strict type to inform help hover in strict mode

Go To Declaration

--!nocheck --!nonstrict --!strict
Go To Declaration uses strict type to inform behavior in nocheck mode Go To Declaration uses strict type to inform behavior in nonstrict mode Go To Declaration uses strict type to inform behavior in strict mode

This is a temporary implementation. As type-checking of nocheck and nonstrict mode scripts improves, we will be able to remove the redundant typecheck pass.

Coming Soon

There are a couple items that are currently missing from Autocomplete and will be added over the next several weeks prior to full release. These are:

  • Embedded documentation to help inform completion selection
  • Icon refresh for a cleaner look
  • (fixed next week) A fix for the following bug where “else” does not show up when expected
if (1) then
    print("Hello world!")
e...
  • (fixed next week) A fix for this bug, where the correct capitalization of Workspace being marked as deprecated
    The correct capitalization of Workspace is marked as deprecated even though it is not

Please try it out and tell us what you think!

Many, many thanks to @fun_enthusiast, @FunnyOldWorld, @swmaniac, @WheretIB, @1ceF1y, @mrow_pizza, @Apakovtac, @yohooyohoo, @HugoBLH, @cruiser_forever, @iriszh, @sunny0724 and @Rusi_002!

418 Likes

This topic was automatically opened after 6 minutes.

While these optimisations and changes are a step in the right direction, when can we expect to see the script editor and studio in general optimised for M1 chips, since currently as a mac user studio is painful and sometimes impossible to use.

Given mac’s are one of the most popular devices for content creation I feel it is reasonable to expect a script editor to run on above 5 FPS.

54 Likes

Very excited about the access to Luau type annotations part, without that it was one of the main reasons I don’t use the studio editor. At least for the ones that don’t, it will be a less painful experience trying to write code.

Will this also work when type casting? That is, if you do (a :: b)., after the period, will autocomplete suggest members of b ?

Also, will event listener parameters be automatically typed? I use roblox-ts to use typescript, and what I love is that event listener parameters already are typed, so it’s as simple as Players.PlayerAdded.Connect((player) -> { ... }); without the need for a type annotation.

28 Likes

That’s really useful thing! I used to have to use dev hub to find what I wrote wrong tbh, but this probably gonna make my scripting life much easier

9 Likes

This seems pretty darn cool.

If you don’t mind telling, when would this feature be out of beta and implemented for everyone?

Can’t wait to use this feature!

8 Likes

This is a very useful implementation and will make scripting way faster. Thank you. :slight_smile:

5 Likes

Will developers be able to utilitise with a sort of --!summary comment keyword

6 Likes

Woahhhh! Auto-complete. This is an amazing step in the right direction for the Roblox Studio editor, can’t wait to see more upcoming changes. :smiley:

8 Likes

Would it be possible to adjust the font in settings? It’s disturbing at the current font it’s at, and it’s looking too big.

Also, you can now auto complete numbers :skull:
and I can’t take screenshot anymore as it just disables instantly when I press any control key. (Ctrl, Alt, Windows)

image
(Recorded, then took screenshot)

But honestly, overall as a user constantly using auto complete, this is really much useful for me to not have an unwanted autocomplete when pressing enter while not paying attention. As I’m used to pressing enter when typing “s”. Love the info given on the keyword.

22 Likes

I have been using this beta before it was released publicly by editing a fast flag value and I have to say, I’m a fan of this beta by a lot.

It fixes a lot of issues that used to slow the scripters down that used the studio built-in editor and actually gives a very decent reason to use type declarations now.

However, I have found a few issues and questions about this beta because of the autocomplete results:

Issues:

1)Some of the global types are declared incorrectly (Especially some of the Enums.), causing autocomplete to not work properly. This is the list I have gathered:
Enum.AutoIndentRule declared as any
Enum.DraftStatusCode declared as any
Enum.HoverAnimateSpeed declared as any
Enum.LanguagePreference declared as any
Enum.ListDisplayMode declared as any
Enum.OutputLayoutMode declared as any
Enum.PermissionLevelShown declared as any
Enum.ServerAudioBehavior declared as any
Enum.StudioStyleGuideColor declared as any
Enum.StudioStyleGuideModifier declared as any
_G declared as any
shared declared as any
plugin declared as any

2) Callbacks are not shown in autocomplete:
image

Questions:
1) I have noticed some of the globals show some generic function info like rawget, rawset, rawequal, ect (Unless I’m interpreting that info very wrongly.):
image

My first question is, are globals that have generic info like these will act like generic functions when generic functions gets re-released?

2) And if first answer to that question is a yes, will this trend expand to instance methods like :FindFirstChild?

10 Likes

This might make me use the built in script editor instead of VSCode on Rojo… Especially with how auto complete on VScode for me is giving me things like :GetActor() on game when I want to use :GetService().

If anyone knows something that improves auto complete searching please DM me

I’m happy that now it seems like using :GetService actually shows auto completion for that service properly. That was something that made people not use :GetService when using the built in editor, there’s some stuff to fix to stop things like that, but mostly this fixes a lot of those issues.

Edit: Lol no Roblox LSP just got crazy better as of yesterday

7 Likes

Huh, I haven’t had any issues with the script editor on my M1 Macbook Air. Do you have any MacOS updates that you haven’t installed yet? There could be a stability update you’re missing or something.

Besides that, I have experienced numerous weird glitches, not only on Studio, but also while playing Roblox games experiences in general (sometimes rendering them unplayable).

7 Likes

As a fellow M1 Mac user, this made me switch to VSCode. I feel like I need to restart studio every 10 minutes because something breaks or it just suddenly drops to 5 fps.

5 Likes

UI is uncomfortably giant on smaller resolutions (take for example 1440x900):

Argument types are wonky too ( supposed to show x : number, y : number or something like that )
image

15 Likes

Seems like identity levels have been added to command bar, great addition to the new autocomplete, yet no intellisense for plugin, any period when this will become available?

Could we get functions in Instance, e.g, childAdded, remove a strikethrough as well, as they’re deprecated, or a heads up (warning)?

10 Likes

I think You can enable PluginSecurity members autocomplete from script editor settings in studio.

5 Likes

Nah. You get the best performance for your money when you purchase a stock m1 powered Mac. I was tired of Windows crashing and notifying me of updates all day, so I switched and never looked back. :sunglasses:

8 Likes

This feels kinda weird getting used to but its pretty neat.

3 Likes

This is a great long waited for update to the script editor, glad to see engineers are treating it as a professional IDE now.

5 Likes