Browse Source

improved XAML highlighting and code completion

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4434 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 17 years ago
parent
commit
cb3417ae90
  1. 8
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs
  2. 9
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs
  3. 23
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs
  4. 7
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlResolver.cs

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

@ -35,11 +35,11 @@ namespace ICSharpCode.XamlBinding @@ -35,11 +35,11 @@ namespace ICSharpCode.XamlBinding
new SpecialCompletionItem("xmlns:")
};
static readonly List<string> xamlNamespaceAttributes = new List<string> {
public static readonly List<string> XamlNamespaceAttributes = new List<string> {
"Class", "ClassModifier", "FieldModifier", "Name", "Subclass", "TypeArguments", "Uid", "Key"
};
static readonly List<string> rootOnlyElements = new List<string> {
public static readonly List<string> RootOnlyElements = new List<string> {
"Class", "ClassModifier", "Subclass"
};
@ -160,7 +160,7 @@ namespace ICSharpCode.XamlBinding @@ -160,7 +160,7 @@ namespace ICSharpCode.XamlBinding
list.Add(new XamlCompletionItem(xamlPrefix, XamlNamespace, "Uid"));
return list;
} else {
foreach (string item in xamlNamespaceAttributes.Where(item => AllowedInElement(context.InRoot, item))) {
foreach (string item in XamlNamespaceAttributes.Where(item => AllowedInElement(context.InRoot, item))) {
if (!existingItems.Contains(xamlPrefix + ":" + item)) {
list.Add(new XamlCompletionItem(xamlPrefix, XamlNamespace, item));
}
@ -194,7 +194,7 @@ namespace ICSharpCode.XamlBinding @@ -194,7 +194,7 @@ namespace ICSharpCode.XamlBinding
static bool AllowedInElement(bool inRoot, string item)
{
return inRoot || !rootOnlyElements.Contains(item);
return inRoot || !RootOnlyElements.Contains(item);
}
public static IEnumerable<ICompletionItem> CreateListForXmlnsCompletion(IProjectContent projectContent)

9
src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs

@ -95,6 +95,11 @@ namespace ICSharpCode.XamlBinding @@ -95,6 +95,11 @@ namespace ICSharpCode.XamlBinding
return thisValue.LastIndexOfAny(anyOf);
}
public static int IndexOfAny(this string thisValue, int startIndex, params char[] anyOf)
{
return thisValue.IndexOfAny(anyOf, startIndex);
}
public static string GetWordBeforeOffset(this string text, int startIndex)
{
if (string.IsNullOrEmpty(text))
@ -120,10 +125,10 @@ namespace ICSharpCode.XamlBinding @@ -120,10 +125,10 @@ namespace ICSharpCode.XamlBinding
int offset = startIndex = Math.Max(startIndex, 0);
while (offset < text.Length && char.IsWhiteSpace(text[offset]))
while (offset < text.Length && (char.IsWhiteSpace(text[offset]) || Extensions.Is(text[offset], '>', '<')))
offset++;
while (offset < text.Length && !char.IsWhiteSpace(text[offset]))
while (offset < text.Length && !(char.IsWhiteSpace(text[offset]) || Extensions.Is(text[offset], '>', '<')))
offset++;
offset = Math.Min(offset, text.Length - 1);

23
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs

@ -107,12 +107,25 @@ namespace ICSharpCode.XamlBinding @@ -107,12 +107,25 @@ namespace ICSharpCode.XamlBinding
List<HighlightingInfo> infos = new List<HighlightingInfo>();
do {
index = LineText.IndexOf('=', index + 1);
if (index + 1 >= LineText.Length)
break;
index = LineText.IndexOfAny(index + 1, '=', '.');
if (index > -1) {
context = CompletionDataHelper.ResolveContext(FileContent, FileName, LineNumber, index + 1);
if (!string.IsNullOrEmpty(context.AttributeName)) {
int startIndex = LineText.Substring(0, index).LastIndexOf(context.AttributeName);
infos.Add(new HighlightingInfo(context.AttributeName, startIndex, startIndex + context.AttributeName.Length, Offset, context));
context = CompletionDataHelper.ResolveContext(FileContent, FileName, LineNumber, index - 1);
string elementName = context.ActiveElement.Name;
int propertyNameIndex = elementName.IndexOf('.');
string attribute = context.AttributeName;
if (string.IsNullOrEmpty(attribute) && elementName.Contains(".")) {
attribute = elementName;
index += attribute.Substring(propertyNameIndex).Length;
}
if (context.Description != XamlContextDescription.InComment && !string.IsNullOrEmpty(attribute)) {
int startIndex = LineText.Substring(0, index).LastIndexOf(attribute);
if (propertyNameIndex > -1)
infos.Add(new HighlightingInfo(attribute.TrimStart('/'), startIndex + propertyNameIndex + 1, startIndex + attribute.Length, Offset, context));
else
infos.Add(new HighlightingInfo(attribute, startIndex, startIndex + attribute.Length, Offset, context));
}
}
} while (index > -1);

7
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlResolver.cs

@ -165,7 +165,10 @@ namespace ICSharpCode.XamlBinding @@ -165,7 +165,10 @@ namespace ICSharpCode.XamlBinding
IProjectContent pc = context.ParseInformation.BestCompilationUnit.ProjectContent;
IReturnType resolvedType = XamlCompilationUnit.FindType(pc, xmlNamespace, className);
if (resolvedType != null && resolvedType.GetUnderlyingClass() != null) {
return ResolvePropertyName(resolvedType, propertyName, allowAttached);
var result = ResolvePropertyName(resolvedType, propertyName, allowAttached);
if (result == null && CompletionDataHelper.XamlNamespaceAttributes.Contains(propertyName))
return new MemberResolveResult(null, null, new DefaultProperty(null, propertyName));
return result;
}
return null;
}
@ -176,6 +179,8 @@ namespace ICSharpCode.XamlBinding @@ -176,6 +179,8 @@ namespace ICSharpCode.XamlBinding
if (member == null) {
member = resolvedType.GetEvents().Find(delegate(IEvent p) { return p.Name == propertyName; });
}
// if (!allowAttached)
// Debug.Assert(member != null);
if (member == null && allowAttached) {
IMethod method = resolvedType.GetMethods().Find(
delegate(IMethod p) {

Loading…
Cancel
Save