private static void AddLocationsToRenameInStringsAndComments( Document document, SyntaxTree tree, string renameText, IEnumerable <Tuple <string, int, TextSpan> > renameStringsAndPositions, List <RenameLocation> renameLocations, bool isRenameInStrings, bool isRenameInComments) { var regex = GetRegexForMatch(renameText); foreach (var renameStringAndPosition in renameStringsAndPositions) { string renameString = renameStringAndPosition.Item1; int renameStringPosition = renameStringAndPosition.Item2; var containingSpan = renameStringAndPosition.Item3; MatchCollection matches = regex.Matches(renameString); foreach (Match match in matches) { int start = renameStringPosition + match.Index; Debug.Assert(renameText.Length == match.Length); var matchTextSpan = new TextSpan(start, renameText.Length); var matchLocation = tree.GetLocation(matchTextSpan); var renameLocation = new RenameLocation(matchLocation, document.Id, containingLocationForStringOrComment: containingSpan); renameLocations.Add(renameLocation); } } }
public static SerializableRenameLocation Dehydrate(RenameLocation location) => new SerializableRenameLocation { Location = location.Location.SourceSpan, DocumentId = location.DocumentId, CandidateReason = location.CandidateReason, IsRenamableAliasUsage = location.IsRenamableAliasUsage, IsRenamableAccessor = location.IsRenamableAccessor, ContainingLocationForStringOrComment = location.ContainingLocationForStringOrComment, IsWrittenTo = location.IsWrittenTo, };
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); }
public static SerializableRenameLocation Dehydrate(RenameLocation location) => new(location.Location.SourceSpan,