Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track the local binding that a prefixed type reference is linked to #1108

Open
JohnnyMorganz opened this issue Nov 18, 2023 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@JohnnyMorganz
Copy link
Contributor

JohnnyMorganz commented Nov 18, 2023

Right now, all local bindings are nicely linked together as they share a pointer to the same AstLocal. But the same is not true for type references

Consider the following code:

local Types = require("path/to/types")

type Foo = Types.Foo

It would be nice to be able to link the Types in Types.Foo to the local definition.
Use case: if a user requests to rename the "Types" local variable, it should rename the imported type prefix (and vice versa).

From first glance, I think this is doable by storing the prefix as an AstLocal here, and tracking it appropriately:

luau/Ast/include/Luau/Ast.h

Lines 883 to 899 in 74c5320

class AstTypeReference : public AstType
{
public:
LUAU_RTTI(AstTypeReference)
AstTypeReference(const Location& location, std::optional<AstName> prefix, AstName name, std::optional<Location> prefixLocation,
const Location& nameLocation, bool hasParameterList = false, const AstArray<AstTypeOrPack>& parameters = {});
void visit(AstVisitor* visitor) override;
bool hasParameterList;
std::optional<AstName> prefix;
std::optional<Location> prefixLocation;
AstName name;
Location nameLocation;
AstArray<AstTypeOrPack> parameters;
};

Or maybe you have other ideas

@JohnnyMorganz JohnnyMorganz added the enhancement New feature or request label Nov 18, 2023
@JohnnyMorganz JohnnyMorganz changed the title Track the local binding that a type reference is linked to Track the local binding that a prefixed type reference is linked to Dec 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

1 participant