mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Use the correct overload symbol
This commit is contained in:
parent
cecea7785b
commit
eef309f386
1 changed files with 33 additions and 27 deletions
|
@ -427,19 +427,14 @@ ExprOrLocal findExprOrLocalAtPosition(const SourceModule& source, Position pos)
|
||||||
return findVisitor.result;
|
return findVisitor.result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<DocumentationSymbol> getDocumentationSymbolAtPosition(const SourceModule& source, const Module& module, Position position)
|
static std::optional<DocumentationSymbol> checkOverloadedDocumentationSymbol(
|
||||||
|
const Module& module, const Luau::TypeId ty, const AstExpr* parentExpr, const std::optional<DocumentationSymbol> documentationSymbol)
|
||||||
{
|
{
|
||||||
std::vector<AstNode*> ancestry = findAstAncestryOfPosition(source, position);
|
if (!documentationSymbol)
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
AstExpr* targetExpr = ancestry.size() >= 1 ? ancestry[ancestry.size() - 1]->asExpr() : nullptr;
|
// This might be an overloaded function.
|
||||||
AstExpr* parentExpr = ancestry.size() >= 2 ? ancestry[ancestry.size() - 2]->asExpr() : nullptr;
|
if (get<IntersectionTypeVar>(follow(ty)))
|
||||||
|
|
||||||
if (std::optional<Binding> binding = findBindingAtPosition(module, source, position))
|
|
||||||
{
|
|
||||||
if (binding->documentationSymbol)
|
|
||||||
{
|
|
||||||
// This might be an overloaded function binding.
|
|
||||||
if (get<IntersectionTypeVar>(follow(binding->typeId)))
|
|
||||||
{
|
{
|
||||||
TypeId matchingOverload = nullptr;
|
TypeId matchingOverload = nullptr;
|
||||||
if (parentExpr && parentExpr->is<AstExprCall>())
|
if (parentExpr && parentExpr->is<AstExprCall>())
|
||||||
|
@ -452,15 +447,26 @@ std::optional<DocumentationSymbol> getDocumentationSymbolAtPosition(const Source
|
||||||
|
|
||||||
if (matchingOverload)
|
if (matchingOverload)
|
||||||
{
|
{
|
||||||
std::string overloadSymbol = *binding->documentationSymbol + "/overload/";
|
std::string overloadSymbol = *documentationSymbol + "/overload/";
|
||||||
// Default toString options are fine for this purpose.
|
// Default toString options are fine for this purpose.
|
||||||
overloadSymbol += toString(matchingOverload);
|
overloadSymbol += toString(matchingOverload);
|
||||||
return overloadSymbol;
|
return overloadSymbol;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return documentationSymbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
return binding->documentationSymbol;
|
std::optional<DocumentationSymbol> getDocumentationSymbolAtPosition(const SourceModule& source, const Module& module, Position position)
|
||||||
|
{
|
||||||
|
std::vector<AstNode*> ancestry = findAstAncestryOfPosition(source, position);
|
||||||
|
|
||||||
|
AstExpr* targetExpr = ancestry.size() >= 1 ? ancestry[ancestry.size() - 1]->asExpr() : nullptr;
|
||||||
|
AstExpr* parentExpr = ancestry.size() >= 2 ? ancestry[ancestry.size() - 2]->asExpr() : nullptr;
|
||||||
|
|
||||||
|
if (std::optional<Binding> binding = findBindingAtPosition(module, source, position))
|
||||||
|
{
|
||||||
|
return checkOverloadedDocumentationSymbol(module, binding->typeId, parentExpr, *binding->documentationSymbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetExpr)
|
if (targetExpr)
|
||||||
|
@ -474,14 +480,14 @@ std::optional<DocumentationSymbol> getDocumentationSymbolAtPosition(const Source
|
||||||
{
|
{
|
||||||
if (auto propIt = ttv->props.find(indexName->index.value); propIt != ttv->props.end())
|
if (auto propIt = ttv->props.find(indexName->index.value); propIt != ttv->props.end())
|
||||||
{
|
{
|
||||||
return propIt->second.documentationSymbol;
|
return checkOverloadedDocumentationSymbol(module, propIt->second.type, parentExpr, propIt->second.documentationSymbol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (const ClassTypeVar* ctv = get<ClassTypeVar>(parentTy))
|
else if (const ClassTypeVar* ctv = get<ClassTypeVar>(parentTy))
|
||||||
{
|
{
|
||||||
if (auto propIt = ctv->props.find(indexName->index.value); propIt != ctv->props.end())
|
if (auto propIt = ctv->props.find(indexName->index.value); propIt != ctv->props.end())
|
||||||
{
|
{
|
||||||
return propIt->second.documentationSymbol;
|
return checkOverloadedDocumentationSymbol(module, propIt->second.type, parentExpr, propIt->second.documentationSymbol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue