Commits

aarondandy  committed e93ddfa

new ignore rules for types related to identifiers

  • Participants
  • Parent commits 274278e

Comments (0)

Files changed (2)

File src/YouCantSpell.ReSharper.Shared/CSharp/CSharpSpellCheckDaemonStageProcess.cs

 			);
 		}
 
+		private IEnumerable<IDeclaredType> GetSuperTypes(ITypeDeclaration typeElement) {
+			if (null == typeElement)
+				return Enumerable.Empty<IDeclaredType>();
+			return typeElement.SuperTypes;
+		}
+
+		[Obsolete]
 		private IEnumerable<string> ParseSuperWords(ITypeElement typeElement) {
 			if (null == typeElement)
 				return Enumerable.Empty<string>();
 			}
 		}
 
+		private IEnumerable<IType> GetRelatedTypes(IDeclaration declaration) {
+			if (declaration is ITypeDeclaration)
+				return GetSuperTypes(declaration as ITypeDeclaration).Cast<IType>();
+			if (declaration is IFieldDeclaration)
+				return new[] {(declaration as IFieldDeclaration).Type};
+			if (declaration is IParameterDeclaration)
+				return new[] {(declaration as IParameterDeclaration).Type};
+			if (declaration is IPropertyDeclaration)
+				return new[] {(declaration as IPropertyDeclaration).Type};
+			if (declaration is ILocalVariableDeclaration)
+				return new[] {(declaration as ILocalVariableDeclaration).Type};
+			if (declaration is IMethodDeclaration) {
+				var methodDeclaration = declaration as IMethodDeclaration;
+				return new List<IType>(methodDeclaration.ParameterDeclarations.Select(x => x.Type)) {
+					methodDeclaration.Type
+				};
+			}
+			return Enumerable.Empty<IType>();
+		}
+
 		private IEnumerable<HighlightingInfo> FindHighlightings(IIdentifier identifier) {
 
 			var validRange = FindTrueDocumentRange(identifier.GetTreeTextRange());
 			if (!validRange.HasValue)
 				yield break;
+			
 			var validPartRange = validRange.Value;
+			var declaration = ReSharperUtil.GetDeclaration(identifier);
+			if(null == declaration)
+				yield break;
 
-			var declared = ReSharperUtil.GetDeclaredElement(identifier);
+			var declared = declaration.DeclaredElement;
 			if (null == declared)
 				yield break;
 
-			var localIgnoredWords = new HashSet<string>(
-				ParseSuperWords(declared as ITypeElement),
-				StringComparer.InvariantCultureIgnoreCase);
+			var localIgnoredWords = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
+			var relatedTypeNames = GetRelatedTypes(declaration)
+				.Select(x => x.GetPresentableName(CSharpLanguage.Instance))
+				.ToList();
+
+			localIgnoredWords.AddRange(relatedTypeNames);
+			localIgnoredWords.AddRange(relatedTypeNames.SelectMany(ParseNameParts).Select(x => x.SubText));
 
 			var parsedNameParts = ParseNameParts(identifier.Name).ToList();
 			var formatter = new CSharpSpellingSuggestionFormatter(

File src/YouCantSpell.ReSharper.Shared/ReSharperUtil.cs

 		public static readonly Regex ReSharperLineRegex = new Regex(@"ReSharper\s+(disable|restore)\s+(.*)", RegexOptions.Compiled);
 
 		/// <summary>
+		/// Extracts the declaration from a tree node.
+		/// </summary>
+		/// <param name="node">The node to get the declaration from.</param>
+		/// <returns>The declaration node.</returns>
+		public static IDeclaration GetDeclaration(ITreeNode node) {
+			while (null != node) {
+				var declaration = node as IDeclaration;
+				if (null != declaration)
+					return declaration;
+				node = node.Parent;
+			}
+			return null;
+		}
+
+		/// <summary>
 		/// Extracts a declared element from an node or its parent.
 		/// </summary>
 		/// <param name="node">The node to extract the declared element from.</param>
 		/// This method walks up the parent nodes to find a declared element.
 		/// </remarks>
 		public static IDeclaredElement GetDeclaredElement(ITreeNode node) {
-			while(null != node) {
-				if (node is IDeclaration)
-					return (node as IDeclaration).DeclaredElement;
-				node = node.Parent;
-			}
-			return null;
+			var declaration = GetDeclaration(node);
+			return null == declaration ? null : declaration.DeclaredElement;
 		}
 
 	}