in resharper/resharper-unity/src/Unity/CSharp/Feature/Services/CodeCompletion/UnityEventFunctionRule.cs [390:457]
private static bool ShouldComplete(ITreeNode nodeInFile, ICSharpIdentifier identifier)
{
var methodDeclaration = identifier.GetContainingNode<IMethodDeclaration>();
if (methodDeclaration != null)
{
// Don't complete in the parameter list
if (nodeInFile.GetContainingNode<IFormalParameterList>() != null) return false;
// Don't complete in the attribute list
if (nodeInFile.GetContainingNode<IAttributeSectionList>() != null) return false;
// Don't complete if there is a preceding [SerializeField] attribute
if (HasSerializedFieldAttribute(methodDeclaration)) return false;
// Check the whole text of the declaration - if it ends (or even starts) with "__" (which is the
// completion marker) then we have an incomplete method declaration and we're good to complete at this
// position
var declarationText = methodDeclaration.GetText();
if (declarationText.StartsWith("__") || declarationText.EndsWith("__") ||
declarationText.Contains(SyntheticComments.CodeCompletionIdentifierToken))
{
return true;
}
if (identifier == methodDeclaration.NameIdentifier)
return true;
// E.g. `OnAni{caret} [SerializeField]` causes the parser to treat the next construct's attribute as an
// array specifier to the type usage we're typing. (If there's already a type, then the parser thinks
// it's a property). So, if we have an array rank, check to see if the token following the `[` is an
// identifier. If so, it's likely it should be an attribute instead, so allow completion.
var typeUsage = identifier.GetContainingNode<IArrayTypeUsage>();
if (typeUsage != null)
{
var arrayRanks = typeUsage.ArrayRanks;
if (arrayRanks.Count > 0)
{
var lbracket = arrayRanks[0].LBracket;
var next = lbracket.GetNextMeaningfulSibling();
if (next == null)
{
next = lbracket.GetNextMeaningfulToken();
if (next != null && next.NodeType == CSharpTokenType.IDENTIFIER)
return true;
}
}
}
return false;
}
// E.g. `public void OnAni{caret} [SerializeField]` causes the parser to
// treat this as a field declaration, using the brackets as an array specifier
var fieldDeclaration = identifier.GetContainingNode<IFieldDeclaration>();
if (fieldDeclaration?.LBracket != null)
{
if (fieldDeclaration.FixedBufferSizeExpression == null
|| !fieldDeclaration.FixedBufferSizeExpression.IsConstantValue())
{
if (HasSerializedFieldAttribute(fieldDeclaration))
return false;
return identifier == fieldDeclaration.NameIdentifier;
}
}
return false;
}