internal static TokenRenameInfo GetTokenRenameInfo( ISemanticFactsService semanticFacts, SemanticModel semanticModel, SyntaxToken token, CancellationToken cancellationToken) { var symbol = semanticFacts.GetDeclaredSymbol(semanticModel, token, cancellationToken); if (symbol != null) { return(TokenRenameInfo.CreateSingleSymbolTokenInfo(symbol)); } var symbolInfo = semanticModel.GetSymbolInfo(token, cancellationToken); if (symbolInfo.Symbol != null) { if (symbolInfo.Symbol.IsTupleType()) { return(TokenRenameInfo.NoSymbolsTokenInfo); } return(TokenRenameInfo.CreateSingleSymbolTokenInfo(symbolInfo.Symbol)); } if (symbolInfo.CandidateReason == CandidateReason.MemberGroup && symbolInfo.CandidateSymbols.Any()) { // This is a reference from a nameof expression. Allow the rename but set the RenameOverloads option return(TokenRenameInfo.CreateMemberGroupTokenInfo(symbolInfo.CandidateSymbols)); } return(TokenRenameInfo.NoSymbolsTokenInfo); }
internal static TokenRenameInfo GetTokenRenameInfo( ISemanticFactsService semanticFacts, SemanticModel semanticModel, SyntaxToken token, CancellationToken cancellationToken ) { var symbol = semanticFacts.GetDeclaredSymbol(semanticModel, token, cancellationToken); if (symbol != null) { return(TokenRenameInfo.CreateSingleSymbolTokenInfo(symbol)); } var symbolInfo = semanticModel.GetSymbolInfo(token, cancellationToken); if (symbolInfo.Symbol != null) { if (symbolInfo.Symbol.IsTupleType()) { return(TokenRenameInfo.NoSymbolsTokenInfo); } return(TokenRenameInfo.CreateSingleSymbolTokenInfo(symbolInfo.Symbol)); } if ( symbolInfo.CandidateReason == CandidateReason.MemberGroup && symbolInfo.CandidateSymbols.Any() ) { // This is a reference from a nameof expression. Allow the rename but set the RenameOverloads option return(TokenRenameInfo.CreateMemberGroupTokenInfo(symbolInfo.CandidateSymbols)); } if ( RenameLocation.ShouldRename(symbolInfo.CandidateReason) && symbolInfo.CandidateSymbols.Length == 1 ) { // TODO(cyrusn): We're allowing rename here, but we likely should let the user // know that there is an error in the code and that rename results might be // inaccurate. return(TokenRenameInfo.CreateSingleSymbolTokenInfo(symbolInfo.CandidateSymbols[0])); } return(TokenRenameInfo.NoSymbolsTokenInfo); }