private void MarkErrorWord(SyntaxEditor editor, int lineNumber, int characterPos, string message) { string text = editor.Document.Lines[lineNumber].Text; string compileText = CompileHelper.ReplaceUserOptionCalls(text); string preceedingText = characterPos <= compileText.Length ? compileText.Substring(0, characterPos) : ""; #region Find all GetUserOption calls and discount them int index = preceedingText.LastIndexOf("GetUserOption"); int offsetUO = "GetUserOptionValue('')".Length - "UserOptions.".Length; int castEndPos = 0; int castStartPos = 0; while (index >= 0) { characterPos -= offsetUO; while (preceedingText[index] != ')') { castEndPos = index; index -= 1; } while (preceedingText[index] != '(') { castStartPos = index; index -= 1; } characterPos -= castEndPos - castStartPos + 1; index = preceedingText.LastIndexOf("GetUserOption", index); } #endregion DocumentPosition position = new DocumentPosition(lineNumber, characterPos); int offset = editor.Document.PositionToOffset(position); DynamicToken token = (DynamicToken)editor.Document.Tokens.GetTokenAtOffset(offset); SpanIndicator indicator = new WaveLineSpanIndicator("ErrorIndicator", Color.Red); indicator.Tag = message; SpanIndicatorLayer indicatorLayer = editor.Document.SpanIndicatorLayers[ErrorLayerKey]; if (indicatorLayer == null) { indicatorLayer = new SpanIndicatorLayer(ErrorLayerKey, 1); editor.Document.SpanIndicatorLayers.Add(indicatorLayer); } int startOffset = Math.Min(token.StartOffset, indicatorLayer.Document.Length - 1); int length = Math.Max(token.Length, 1); SpanIndicator[] indicators = indicatorLayer.GetIndicatorsForTextRange(new TextRange(startOffset, startOffset + length)); foreach (SpanIndicator i in indicators) { // If there is already an error indicator on that word, don't add another one. if (i.TextRange.StartOffset == startOffset && i.TextRange.Length == length) return; } indicatorLayer.Add(indicator, startOffset, length); }