Browse Source

- fixed build

- reintegrated some unit tests
- removed syntax highlighting (temporary)
- now using incremental XML parsing on GUI thread

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4692 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 16 years ago
parent
commit
e8a2a71648
  1. 2
      src/AddIns/BackendBindings/XamlBinding/XamlBinding.Tests/MockTextEditor.cs
  2. 28
      src/AddIns/BackendBindings/XamlBinding/XamlBinding.Tests/ResolveContextTests.cs
  3. 45
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs
  4. 6
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs
  5. 19
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlLanguageBinding.cs
  6. 1
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParser.cs
  7. 1
      src/AddIns/Misc/SharpRefactoring/Src/ExtractMethodCommand.cs
  8. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/XmlParser/SimpleTests.cs

2
src/AddIns/BackendBindings/XamlBinding/XamlBinding.Tests/MockTextEditor.cs

@ -54,6 +54,8 @@ namespace ICSharpCode.XamlBinding.Tests @@ -54,6 +54,8 @@ namespace ICSharpCode.XamlBinding.Tests
this.TextEditor.TextArea.TextView.Services.AddService(typeof(ISyntaxHighlighter), new AvalonEditSyntaxHighlighterAdapter(this.TextEditor));
this.TextEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("XML");
new XamlLanguageBinding().Attach(this);
}
public override string FileName {

28
src/AddIns/BackendBindings/XamlBinding/XamlBinding.Tests/ResolveContextTests.cs

@ -14,7 +14,6 @@ using System.IO; @@ -14,7 +14,6 @@ using System.IO;
namespace ICSharpCode.XamlBinding.Tests
{
[TestFixture]
[Ignore("Ignore bugs in XmlParser")]
public class ResolveContextTests
{
[Test]
@ -97,6 +96,33 @@ namespace ICSharpCode.XamlBinding.Tests @@ -97,6 +96,33 @@ namespace ICSharpCode.XamlBinding.Tests
Assert.AreEqual(XamlContextDescription.InTag, context.Description);
}
[Test]
public void ContextInTagDescriptionTest2()
{
string xaml = @"<Window x:Class='Vokabeltrainer.Window1'
xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
Title=''>
<Grid>
<StackPanel>
<RadioButton
</StackPanel>
</Grid>
</Window>";
int offset = @"<Window x:Class='Vokabeltrainer.Window1'
xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
Title=''>
<Grid>
<StackPanel>
<RadioButton ".Length;
XamlContext context = CompletionDataHelper.ResolveContext(xaml, "", offset);
Assert.AreEqual(XamlContextDescription.InTag, context.Description);
}
[Test]
public void ElementNameWithDotTest1()
{

45
src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs

@ -8,19 +8,14 @@ @@ -8,19 +8,14 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Windows.Markup;
using System.Windows.Media;
using System.Xml.Linq;
using ICSharpCode.AvalonEdit.Xml;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
using ICSharpCode.XmlEditor;
namespace ICSharpCode.XamlBinding
{
@ -62,11 +57,17 @@ namespace ICSharpCode.XamlBinding @@ -62,11 +57,17 @@ namespace ICSharpCode.XamlBinding
public static XamlContext ResolveContext(string text, string fileName, int offset)
{
return ResolveContextInternal(new AXmlParser(text), fileName, offset);
}
static XamlContext ResolveContextInternal(AXmlParser parser, string fileName, int offset)
{
DebugTimer.Start();
ParseInformation info = string.IsNullOrEmpty(fileName) ? null : ParserService.GetParseInformation(fileName);
var parser = new AvalonEdit.Xml.AXmlParser(text);
var document = parser.Parse();
AXmlObject currentData = document.GetChildAtOffset(offset);
DebugTimer.Stop("Parse & GetChildAtOffset");
string attribute = string.Empty, attributeValue = string.Empty;
bool inAttributeValue = false;
@ -84,7 +85,7 @@ namespace ICSharpCode.XamlBinding @@ -84,7 +85,7 @@ namespace ICSharpCode.XamlBinding
if (item is AXmlElement) {
AXmlElement element = item as AXmlElement;
ancestors.Add(element);
foreach (AXmlAttribute attr in element.StartTag.Children.OfType<AXmlAttribute>()) {
foreach (var attr in element.Attributes) {
if (attr.IsNamespaceDeclaration) {
string prefix = (attr.Name == "xmlns") ? "" : attr.LocalName;
if (!xmlns.ContainsKey(prefix))
@ -106,7 +107,7 @@ namespace ICSharpCode.XamlBinding @@ -106,7 +107,7 @@ namespace ICSharpCode.XamlBinding
if (currentData.Parent is AXmlTag) {
AXmlTag tag = currentData.Parent as AXmlTag;
if (tag.IsStartTag)
if (tag.IsStartOrEmptyTag)
description = XamlContextDescription.InTag;
else if (tag.IsComment)
description = XamlContextDescription.InComment;
@ -132,12 +133,13 @@ namespace ICSharpCode.XamlBinding @@ -132,12 +133,13 @@ namespace ICSharpCode.XamlBinding
description = XamlContextDescription.InMarkupExtension;
if (attributeValue.StartsWith("{}", StringComparison.Ordinal) && attributeValue.Length > 2)
description = XamlContextDescription.InAttributeValue;
}
} else
description = XamlContextDescription.InTag;
}
if (currentData is AXmlTag) {
AXmlTag tag = currentData as AXmlTag;
if (tag.IsStartTag)
if (tag.IsStartOrEmptyTag)
description = XamlContextDescription.AtTag;
else if (tag.IsComment)
description = XamlContextDescription.InComment;
@ -168,13 +170,18 @@ namespace ICSharpCode.XamlBinding @@ -168,13 +170,18 @@ namespace ICSharpCode.XamlBinding
ParseInformation = info,
IgnoredXmlns = ignored.AsReadOnly()
};
return context;
}
public static XamlCompletionContext ResolveCompletionContext(ITextEditor editor, char typedValue)
{
var context = new XamlCompletionContext(ResolveContext(editor.Document.Text, editor.FileName, editor.Caret.Offset)) {
var binding = editor.GetService(typeof(XamlLanguageBinding)) as XamlLanguageBinding;
if (binding == null)
throw new InvalidOperationException("Can only use ResolveCompletionContext with a XamlLanguageBinding.");
var context = new XamlCompletionContext(ResolveContextInternal(binding.Parser, editor.FileName, editor.Caret.Offset)) {
PressedKey = typedValue,
Editor = editor
};
@ -363,15 +370,17 @@ namespace ICSharpCode.XamlBinding @@ -363,15 +370,17 @@ namespace ICSharpCode.XamlBinding
XamlCodeCompletionItem item = new XamlCodeCompletionItem(c, ns.Key);
if (item.Text == last.Name)
parentAdded = true;
parentAdded = parentAdded || (last != null && item.Text == last.Name);
result.Add(new XamlCodeCompletionItem(c, ns.Key));
}
}
if (!parentAdded && !last.Name.Contains("."))
result.Add(new XamlCodeCompletionItem(cu.CreateType(last.Namespace, last.LocalName.Trim('.')).GetUnderlyingClass(), last.Prefix));
if (!parentAdded && last != null && !last.Name.Contains(".")) {
IClass itemClass = cu.CreateType(last.Namespace, last.LocalName.Trim('.')).GetUnderlyingClass();
if (itemClass != null)
result.Add(new XamlCodeCompletionItem(itemClass, last.Prefix));
}
string xamlPrefix = Utils.GetXamlNamespacePrefix(context);
@ -439,6 +448,8 @@ namespace ICSharpCode.XamlBinding @@ -439,6 +448,8 @@ namespace ICSharpCode.XamlBinding
}
break;
case XamlContextDescription.InTag:
DebugTimer.Start();
string word = context.Editor.GetWordBeforeCaretExtended();
if (context.PressedKey == '.' || word.Contains(".")) {
@ -464,6 +475,8 @@ namespace ICSharpCode.XamlBinding @@ -464,6 +475,8 @@ namespace ICSharpCode.XamlBinding
list.Items.AddRange(CreateAttributeList(context, true));
list.Items.AddRange(standardAttributes);
}
DebugTimer.Stop("CreateListForContext - InTag");
break;
case XamlContextDescription.InAttributeValue:
XamlCodeCompletionBinding.Instance.CtrlSpace(editor);

6
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs

@ -5,16 +5,12 @@ @@ -5,16 +5,12 @@
// <version>$Revision: 3731 $</version>
// </file>
using ICSharpCode.XmlEditor;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
using ICSharpCode.XmlEditor;
namespace ICSharpCode.XamlBinding
{

19
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlLanguageBinding.cs

@ -5,26 +5,28 @@ @@ -5,26 +5,28 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.AvalonEdit.Editing;
using System;
using System.Linq;
using System.Windows.Controls;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.AvalonEdit.Xml;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.XmlEditor;
namespace ICSharpCode.XamlBinding
{
/// <summary>
/// Description of XamlLanguageBinding.
/// </summary>
public class XamlLanguageBinding : XmlLanguageBinding
public class XamlLanguageBinding : XmlEditor.XmlLanguageBinding
{
XamlColorizer colorizer;
TextView textView;
AXmlParser parser;
public override void Attach(ITextEditor editor)
{
@ -34,14 +36,18 @@ namespace ICSharpCode.XamlBinding @@ -34,14 +36,18 @@ namespace ICSharpCode.XamlBinding
// of this ITextEditor
this.textView = editor.GetService(typeof(TextView)) as TextView;
this.parser = new AXmlParser(editor.Document.GetService(typeof(TextDocument)) as TextDocument);
// if editor is not an AvalonEdit.TextEditor
// GetService returns null
if (textView != null) {
colorizer = new XamlColorizer(editor, textView);
// attach the colorizer
textView.LineTransformers.Add(colorizer);
//textView.LineTransformers.Add(colorizer);
// add the XamlOutlineContentHost, which manages the tree view
textView.Services.AddService(typeof(IOutlineContentHost), new XamlOutlineContentHost(editor));
// add ILanguageBinding
textView.Services.AddService(typeof(XamlLanguageBinding), this);
}
}
@ -54,8 +60,13 @@ namespace ICSharpCode.XamlBinding @@ -54,8 +60,13 @@ namespace ICSharpCode.XamlBinding
// remove and dispose everything we added
textView.LineTransformers.Remove(colorizer);
textView.Services.RemoveService(typeof(IOutlineContentHost));
textView.Services.RemoveService(typeof(XamlLanguageBinding));
colorizer.Dispose();
}
}
public AXmlParser Parser {
get { return parser; }
}
}
}

1
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParser.cs

@ -84,7 +84,6 @@ namespace ICSharpCode.XamlBinding @@ -84,7 +84,6 @@ namespace ICSharpCode.XamlBinding
}
}
catch (XmlException ex) {
LoggingService.Debug("XamlParser exception: " + ex.ToString());
cu.ErrorsDuringCompile = true;
}
return cu;

1
src/AddIns/Misc/SharpRefactoring/Src/ExtractMethodCommand.cs

@ -42,7 +42,6 @@ namespace SharpRefactoring @@ -42,7 +42,6 @@ namespace SharpRefactoring
}
}
MethodExtractorBase GetCurrentExtractor(ITextEditor editor)
{
switch (ProjectBindingService.GetCodonPerCodeFileName(editor.FileName).Language) {

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit.Tests/XmlParser/SimpleTests.cs

@ -18,7 +18,7 @@ using NUnit.Framework; @@ -18,7 +18,7 @@ using NUnit.Framework;
namespace ICSharpCode.AvalonEdit.Xml
{
[TestFixture]
[Ignore("XmlParser API broken")]
[Ignore("XML parser API changes not complete")]
public class SimpleTests
{
string tmpPath;

Loading…
Cancel
Save