1. aarondandy
  2. YouCantSpell

Commits

aarondandy  committed be461eb

xml spell fix for attributes and text

  • Participants
  • Parent commits 1d0f0b0
  • Branches default

Comments (0)

Files changed (3)

File src/YouCantSpell.ReSharper.Shared/Xml/XmlFreeTextSpellingHighlightFinder.cs

View file
 			string text,
 			DocumentRange textRange
 		) {
+			var highlights = new List<HighlightingInfo>(0);
 			var parser = new CStyleFreeTextParser();
 			var wordParts = parser.ParseSentenceWordsForSpellCheck(new TextSubString(text));
 			foreach(var wordPart in wordParts) {
 					word,
 					null
 				);
-				yield return new HighlightingInfo(wordRange, highlight);
+				highlights.Add(new HighlightingInfo(wordRange, highlight));
 			}
+			return highlights;
 		}
 
 	}

File src/YouCantSpell.ReSharper.Shared/Xml/XmlSpellCheckDaemonStageProcess.cs

View file
 		}
 
 		private IEnumerable<HighlightingInfo> FindWordHighlightings(XmlValueToken node) {
-			var validRange = FindTrueDocumentRange(node.GetTreeTextRange());
+			var absoluteUnquotedRange = node.GetTreeTextRange();
+			absoluteUnquotedRange = new TreeTextRange(
+				absoluteUnquotedRange.StartOffset + node.UnquotedValueRange.StartOffset,
+				node.UnquotedValueRange.Length
+			);
+			var validRange = FindTrueDocumentRange(absoluteUnquotedRange);
 			if (!validRange.HasValue) return Enumerable.Empty<HighlightingInfo>();
 
-			return _freeTextSpellingHighlightFinder.FindWordHighlightings(node, node.UnquotedValue, validRange.Value);
+			return _freeTextSpellingHighlightFinder.FindWordHighlightings(
+				node,
+				node.UnquotedValue,
+				validRange.Value
+			);
 		}
 
 		public void Execute(Action<DaemonStageResult> commiter) {
 			_xmlFile.ProcessChildren<ITreeNode>(allNodes.Add);
 
 			_xmlFile.ProcessChildren<XmlFloatingTextToken>(node => {
-				if(!node.IsIdentifier())
+				if(!node.IsIdentifier() && !node.IsWhitespaceToken())
 					highlightings.AddRange(FindWordHighlightings(node));
 			});
 

File src/YouCantSpell.ReSharper.Shared/Xml/XmlSpellingFixBulbItem.cs

View file
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
+using JetBrains.ReSharper.Psi;
+using JetBrains.ReSharper.Psi.ExtensionsAPI.Tree;
 using JetBrains.ReSharper.Psi.Tree;
+using JetBrains.ReSharper.Psi.Xml.Impl.Tree;
+using JetBrains.ReSharper.Psi.Xml.Parsing;
+using JetBrains.Text;
 using YouCantSpell.Utility;
 
 namespace YouCantSpell.ReSharper.Xml
 				badWordTextRange.Length
 			);
 
-			
+			if(node is XmlValueToken) {
+				var newElm = new XmlValueToken(
+					(node as XmlValueToken).GetTokenType(),
+					new StringBuffer(newText), 
+					new TreeOffset(0), 
+					new TreeOffset(newText.Length)
+				);
+				ModificationUtil.ReplaceChild(node, newElm);
+				return null;
+			}
+			if (node is XmlFloatingTextToken) {
+				var newElm = new XmlFloatingTextToken(
+					(node as XmlFloatingTextToken).GetTokenType(),
+					newText
+				);
+				ModificationUtil.ReplaceChild(node, newElm);
+				return null;
+			}
 			return null;
 		}