From d15e1cf98d6aada02c8601ebf3d8f737c948e246 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 21 Jun 2009 17:30:19 +0000 Subject: [PATCH] reverted old highlighting functionality git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4336 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../XamlBinding/XamlBinding/XamlColorizer.cs | 80 +++++++------------ .../XamlBinding/XamlColorizerServer.cs | 4 +- 2 files changed, 32 insertions(+), 52 deletions(-) diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs index cc63362ffa..dc2044f9f5 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs @@ -25,6 +25,8 @@ namespace ICSharpCode.XamlBinding XamlColorizerSettings settings = defaultSettings; string fileContent; string fileName; + ParseInformation parseInfo; + XamlResolver resolver = new XamlResolver(); public IViewContent Content { get; set; } @@ -40,6 +42,7 @@ namespace ICSharpCode.XamlBinding if (document == null) return; + this.parseInfo = ParserService.GetParseInformation(Content.PrimaryFileName); this.fileContent = document.GetDocumentForFile(this.Content.PrimaryFile).CreateSnapshot().Text; this.fileName = this.Content.PrimaryFileName; @@ -48,65 +51,42 @@ namespace ICSharpCode.XamlBinding protected override void ColorizeLine(DocumentLine line) { - Stopwatch watch = new Stopwatch(); - watch.Start(); - - XamlResolver resolver = new XamlResolver(); - if (!line.IsDeleted) { - foreach (HighlightingInfo info in GetInfoForLine(fileContent, fileName, (string)line.Text.Clone(), line.LineNumber, line.Offset)) { - MemberResolveResult rr = resolver.Resolve(info.GetExpressionResult(), info.Context.ParseInformation, fileContent) as MemberResolveResult; + HighlightingInfo[] infos = GetInfoForLine(line); + + foreach (HighlightingInfo info in infos) { + MemberResolveResult rr = resolver.Resolve(info.GetExpressionResult(), parseInfo, fileContent) as MemberResolveResult; IMember member = (rr != null) ? rr.ResolvedMember : null; - Colorize(member, info, line.Offset); + if (member != null) { + if (member is IEvent) + ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightEvent); + else + ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightProperty); + } else { + if (info.Token.StartsWith("xmlns")) + ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightNamespaceDeclaration); + } } } - - watch.Stop(); - Core.LoggingService.Debug("ColorizeLine line: " + line.LineNumber + " took: " + watch.ElapsedMilliseconds + "ms"); } - void Colorize(IMember member, HighlightingInfo info, int offset) + HighlightingInfo[] GetInfoForLine(DocumentLine line) { - try { - if (member != null) { - if (member is IEvent) - ChangeLinePart(offset + info.StartOffset, offset + info.EndOffset, HighlightEvent); - else - ChangeLinePart(offset + info.StartOffset, offset + info.EndOffset, HighlightProperty); - } else { - if (info.Token.StartsWith("xmlns")) - ChangeLinePart(offset + info.StartOffset, offset + info.EndOffset, HighlightNamespaceDeclaration); - } - } catch (Exception e) { - Debug.Print(e.ToString()); - } - } - - static ParallelQuery GetInfoForLine(string fileContent, string fileName, string lineText, int line, int offset) - { - Stopwatch watch = new Stopwatch(); - watch.Start(); - - List indices = new List(); + int index = -1; List infos = new List(); - - int cIndex = lineText.IndexOf('='); - - while (cIndex > -1) { - indices.Add(cIndex); - cIndex = lineText.IndexOf('=', cIndex + 1); - } - - return indices.AsParallel() - .Select(index => new { Context = CompletionDataHelper.ResolveContext(fileContent, fileName, line, index + 1), Index = index, Offset = offset }) - .Where(item => !string.IsNullOrEmpty(item.Context.AttributeName)) - .Select(context => GetInfo(context.Index, lineText, line, context.Context)); - } - static HighlightingInfo GetInfo(int index, string lineText, int line, XamlContext context) - { - int startIndex = lineText.Substring(0, index).LastIndexOf(context.AttributeName); - return new HighlightingInfo(context.AttributeName, startIndex, startIndex + context.AttributeName.Length, line, context); + do { + index = line.Text.IndexOf('=', index + 1); + if (index > -1) { + XamlContext context = CompletionDataHelper.ResolveContext(this.fileContent, this.fileName, line.LineNumber, index + 1); + if (!string.IsNullOrEmpty(context.AttributeName)) { + int startIndex = line.Text.Substring(0, index).LastIndexOf(context.AttributeName); + infos.Add(new HighlightingInfo(context.AttributeName, startIndex, startIndex + context.AttributeName.Length, line.Offset, context)); + } + } + } while (index > -1); + + return infos.ToArray(); } void HighlightProperty(VisualLineElement element) diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizerServer.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizerServer.cs index 16237151af..4cb6b4a8b0 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizerServer.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizerServer.cs @@ -32,8 +32,8 @@ namespace ICSharpCode.XamlBinding ITextEditorProvider textEditor = e.Content as ITextEditorProvider; if (textEditor != null) { TextView textView = textEditor.TextEditor.GetService(typeof(TextView)) as TextView; - //if (textView != null) - //textView.LineTransformers.Add(new XamlColorizer(e.Content)); + if (textView != null) + textView.LineTransformers.Add(new XamlColorizer(e.Content)); } } }