mirror of
https://github.com/luau-lang/luau.git
synced 2024-11-15 14:25:44 +08:00
Attach definition location to TableType
(#801)
Having the location where the table type is defined is useful for tracking other info such as documentation comments, or pointing back through "Go To Definition" functionality etc. This adds in the required info
This commit is contained in:
parent
86494918f5
commit
0af10417cd
@ -375,6 +375,7 @@ struct TableType
|
|||||||
std::vector<TypeId> instantiatedTypeParams;
|
std::vector<TypeId> instantiatedTypeParams;
|
||||||
std::vector<TypePackId> instantiatedTypePackParams;
|
std::vector<TypePackId> instantiatedTypePackParams;
|
||||||
ModuleName definitionModuleName;
|
ModuleName definitionModuleName;
|
||||||
|
Location definitionLocation;
|
||||||
|
|
||||||
std::optional<TypeId> boundTo;
|
std::optional<TypeId> boundTo;
|
||||||
Tags tags;
|
Tags tags;
|
||||||
|
@ -59,6 +59,7 @@ TypeId Anyification::clean(TypeId ty)
|
|||||||
{
|
{
|
||||||
TableType clone = TableType{ttv->props, ttv->indexer, ttv->level, TableState::Sealed};
|
TableType clone = TableType{ttv->props, ttv->indexer, ttv->level, TableState::Sealed};
|
||||||
clone.definitionModuleName = ttv->definitionModuleName;
|
clone.definitionModuleName = ttv->definitionModuleName;
|
||||||
|
clone.definitionLocation = ttv->definitionLocation;
|
||||||
clone.name = ttv->name;
|
clone.name = ttv->name;
|
||||||
clone.syntheticName = ttv->syntheticName;
|
clone.syntheticName = ttv->syntheticName;
|
||||||
clone.tags = ttv->tags;
|
clone.tags = ttv->tags;
|
||||||
|
@ -263,6 +263,7 @@ void TypeCloner::operator()(const TableType& t)
|
|||||||
arg = clone(arg, dest, cloneState);
|
arg = clone(arg, dest, cloneState);
|
||||||
|
|
||||||
ttv->definitionModuleName = t.definitionModuleName;
|
ttv->definitionModuleName = t.definitionModuleName;
|
||||||
|
ttv->definitionLocation = t.definitionLocation;
|
||||||
ttv->tags = t.tags;
|
ttv->tags = t.tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -446,6 +447,7 @@ TypeId shallowClone(TypeId ty, TypeArena& dest, const TxnLog* log, bool alwaysCl
|
|||||||
LUAU_ASSERT(!ttv->boundTo);
|
LUAU_ASSERT(!ttv->boundTo);
|
||||||
TableType clone = TableType{ttv->props, ttv->indexer, ttv->level, ttv->scope, ttv->state};
|
TableType clone = TableType{ttv->props, ttv->indexer, ttv->level, ttv->scope, ttv->state};
|
||||||
clone.definitionModuleName = ttv->definitionModuleName;
|
clone.definitionModuleName = ttv->definitionModuleName;
|
||||||
|
clone.definitionLocation = ttv->definitionLocation;
|
||||||
clone.name = ttv->name;
|
clone.name = ttv->name;
|
||||||
clone.syntheticName = ttv->syntheticName;
|
clone.syntheticName = ttv->syntheticName;
|
||||||
clone.instantiatedTypeParams = ttv->instantiatedTypeParams;
|
clone.instantiatedTypeParams = ttv->instantiatedTypeParams;
|
||||||
|
@ -116,6 +116,7 @@ TypeId ReplaceGenerics::clean(TypeId ty)
|
|||||||
{
|
{
|
||||||
TableType clone = TableType{ttv->props, ttv->indexer, level, scope, TableState::Free};
|
TableType clone = TableType{ttv->props, ttv->indexer, level, scope, TableState::Free};
|
||||||
clone.definitionModuleName = ttv->definitionModuleName;
|
clone.definitionModuleName = ttv->definitionModuleName;
|
||||||
|
clone.definitionLocation = ttv->definitionLocation;
|
||||||
return addType(std::move(clone));
|
return addType(std::move(clone));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1535,6 +1535,7 @@ void TypeChecker::check(const ScopePtr& scope, const AstStatTypeAlias& typealias
|
|||||||
// This is a shallow clone, original recursive links to self are not updated
|
// This is a shallow clone, original recursive links to self are not updated
|
||||||
TableType clone = TableType{ttv->props, ttv->indexer, ttv->level, ttv->state};
|
TableType clone = TableType{ttv->props, ttv->indexer, ttv->level, ttv->state};
|
||||||
clone.definitionModuleName = ttv->definitionModuleName;
|
clone.definitionModuleName = ttv->definitionModuleName;
|
||||||
|
clone.definitionLocation = ttv->definitionLocation;
|
||||||
clone.name = name;
|
clone.name = name;
|
||||||
|
|
||||||
for (auto param : binding->typeParams)
|
for (auto param : binding->typeParams)
|
||||||
@ -2370,6 +2371,7 @@ TypeId TypeChecker::checkExprTable(
|
|||||||
TableState state = TableState::Unsealed;
|
TableState state = TableState::Unsealed;
|
||||||
TableType table = TableType{std::move(props), indexer, scope->level, state};
|
TableType table = TableType{std::move(props), indexer, scope->level, state};
|
||||||
table.definitionModuleName = currentModuleName;
|
table.definitionModuleName = currentModuleName;
|
||||||
|
table.definitionLocation = expr.location;
|
||||||
return addType(table);
|
return addType(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5371,6 +5373,7 @@ TypeId TypeChecker::resolveTypeWorker(const ScopePtr& scope, const AstType& anno
|
|||||||
|
|
||||||
TableType ttv{props, tableIndexer, scope->level, TableState::Sealed};
|
TableType ttv{props, tableIndexer, scope->level, TableState::Sealed};
|
||||||
ttv.definitionModuleName = currentModuleName;
|
ttv.definitionModuleName = currentModuleName;
|
||||||
|
ttv.definitionLocation = annotation.location;
|
||||||
return addType(std::move(ttv));
|
return addType(std::move(ttv));
|
||||||
}
|
}
|
||||||
else if (const auto& func = annotation.as<AstTypeFunction>())
|
else if (const auto& func = annotation.as<AstTypeFunction>())
|
||||||
@ -5572,6 +5575,7 @@ TypeId TypeChecker::instantiateTypeFun(const ScopePtr& scope, const TypeFun& tf,
|
|||||||
ttv->instantiatedTypeParams = typeParams;
|
ttv->instantiatedTypeParams = typeParams;
|
||||||
ttv->instantiatedTypePackParams = typePackParams;
|
ttv->instantiatedTypePackParams = typePackParams;
|
||||||
ttv->definitionModuleName = currentModuleName;
|
ttv->definitionModuleName = currentModuleName;
|
||||||
|
ttv->definitionLocation = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
return instantiated;
|
return instantiated;
|
||||||
|
Loading…
Reference in New Issue
Block a user