Browse Source

fix bugs in GetOffsetFromFilePos and XamlResolver

pull/18/head
Siegfried Pammer 14 years ago
parent
commit
3a949f7aab
  1. 17
      src/AddIns/BackendBindings/XamlBinding/XamlBinding.Tests/ResolveContextTests.cs
  2. 4
      src/AddIns/BackendBindings/XamlBinding/XamlBinding.Tests/UtilsTests.cs
  3. 19
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs
  4. 13
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlResolver.cs

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

@ -180,7 +180,7 @@ namespace ICSharpCode.XamlBinding.Tests @@ -180,7 +180,7 @@ namespace ICSharpCode.XamlBinding.Tests
}
[Test]
public void ContextInMarkupExtensionTest2()
public void ContextInAttributeValueTest()
{
string xaml = "<Test attr=\"Test\" />";
int offset = "<Test attr=\"Te".Length;
@ -191,7 +191,7 @@ namespace ICSharpCode.XamlBinding.Tests @@ -191,7 +191,7 @@ namespace ICSharpCode.XamlBinding.Tests
}
[Test]
public void ContextInMarkupExtensionTest3()
public void ContextInMarkupExtensionTest2()
{
string xaml = "<Test attr=\"{}{Test}\" />";
int offset = "<Test attr=\"{}{Te".Length;
@ -202,7 +202,7 @@ namespace ICSharpCode.XamlBinding.Tests @@ -202,7 +202,7 @@ namespace ICSharpCode.XamlBinding.Tests
}
[Test]
public void ContextInMarkupExtensionTest4()
public void ContextInAttributeValueTest2()
{
string xaml = "<Test attr=\"Test />";
int offset = "<Test attr=\"Te".Length;
@ -212,6 +212,17 @@ namespace ICSharpCode.XamlBinding.Tests @@ -212,6 +212,17 @@ namespace ICSharpCode.XamlBinding.Tests
Assert.AreEqual(XamlContextDescription.InAttributeValue, context.Description);
}
[Test]
public void ContextInAttributeValueTest3()
{
string xaml = "<Test attr=\"Test />";
int offset = "<Test attr=\"".Length;
XamlContext context = CompletionDataHelper.ResolveContext(xaml, "", offset);
Assert.AreEqual(XamlContextDescription.InAttributeValue, context.Description);
}
[Test]
public void ParentElementTestSimple1()
{

4
src/AddIns/BackendBindings/XamlBinding/XamlBinding.Tests/UtilsTests.cs

@ -73,7 +73,7 @@ inside SharpDevelop, there's more going on than a @@ -73,7 +73,7 @@ inside SharpDevelop, there's more going on than a
simple call to MSBuild.";
int expected = @"SharpDevelop uses the MSBuild
libraries".Length - 1;
libraries".Length;
int line = 2;
int col = 10;
@ -110,7 +110,7 @@ simple call to MSBuild."; @@ -110,7 +110,7 @@ simple call to MSBuild.";
int expected = @"SharpDevelop uses the MSBuild
libraries for compilation. But when you compile a project
inside SharpDevelop, there's more going on than a
simple".Length - 1;
simple".Length;
int line = 4;
int col = 7;

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

@ -25,7 +25,8 @@ namespace ICSharpCode.XamlBinding @@ -25,7 +25,8 @@ namespace ICSharpCode.XamlBinding
return Math.Min(Math.Max(value, lower), upper);
}
static char[] whitespace = new char[] {' ', '\t', '\n', '\r'};
static readonly char[] whitespace = new[] {' ', '\t', '\n', '\r'};
static readonly char[] newline = new[] {'\n', '\r'};
public static string GetNamespacePrefix(string namespaceUri, XamlContext context)
{
@ -36,6 +37,13 @@ namespace ICSharpCode.XamlBinding @@ -36,6 +37,13 @@ namespace ICSharpCode.XamlBinding
return string.Empty;
}
/// <summary>
/// Returns the offset for a given line, column position in a file.
/// If the given position is not within the string it returns the first or the last offset respectively.
/// </summary>
/// <remarks>
/// <paramref name="line"/> and <paramref name="col"/> are 1-based!
/// </remarks>
public static int GetOffsetFromFilePos(string content, int line, int col)
{
if (line < 1)
@ -46,16 +54,19 @@ namespace ICSharpCode.XamlBinding @@ -46,16 +54,19 @@ namespace ICSharpCode.XamlBinding
int offset = -1;
while (line > 1) {
int tmp = content.IndexOf('\n', offset + 1);
int tmp = content.IndexOfAny(newline, offset + 1);
if (tmp > -1) {
offset = tmp;
if (content[tmp] == '\r' && content.Length > tmp + 1 && content[tmp + 1] == '\n')
offset = tmp + 1;
else
offset = tmp;
line--;
} else {
return content.Length;
}
}
return offset + col - 1;
return offset + col;
}
public static Location GetLocationInfoFromOffset(string text, int offset)

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

@ -218,14 +218,13 @@ namespace ICSharpCode.XamlBinding @@ -218,14 +218,13 @@ namespace ICSharpCode.XamlBinding
if (propertyOrEvent is IEvent && callingClass != null) {
return new MethodGroupResolveResult(callingClass, null, callingClass.DefaultReturnType, expression);
} else if (propertyOrEvent is IProperty && callingClass != null) {
return ResolveElementName(expression);
}
if (propertyOrEvent.Name == "Name" && callingClass != null) {
foreach (IField f in callingClass.Fields) {
if (f.Name == expression)
return new MemberResolveResult(callingClass, null, f);
if (propertyOrEvent.Name == "Name") {
foreach (IField f in callingClass.Fields) {
if (f.Name == expression)
return new MemberResolveResult(callingClass, null, f);
}
}
return ResolveElementName(expression);
}
IReturnType type = propertyOrEvent.ReturnType;

Loading…
Cancel
Save