Browse Source

Code completion in the Python binding was not working due to a change in the AbstractCompletionDataProvider's GetExpression method where the expression offset is now after the end of the text.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3034 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 18 years ago
parent
commit
7db58ef39d
  1. 12
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonExpressionFinder.cs
  2. 15
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Expressions/FindImportExpressionTestFixture.cs
  3. 26
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Expressions/FindSystemConsoleExpressionTestFixture.cs

12
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonExpressionFinder.cs

@ -37,7 +37,7 @@ namespace ICSharpCode.PythonBinding @@ -37,7 +37,7 @@ namespace ICSharpCode.PythonBinding
if (text != null && IsValidOffset(text, offset)) {
bool found = false;
ExpressionContext expressionContext = ExpressionContext.Default;
int currentOffset = offset;
int currentOffset = offset - 1;
while (!found && currentOffset >= 0) {
char currentChar = text[currentOffset];
switch (currentChar) {
@ -62,7 +62,7 @@ namespace ICSharpCode.PythonBinding @@ -62,7 +62,7 @@ namespace ICSharpCode.PythonBinding
}
// Create expression result.
string expression = Substring(text, currentOffset + 1, offset);
string expression = Substring(text, currentOffset + 1, offset - 1);
return new ExpressionResult(expression, expressionContext);
}
return new ExpressionResult(null);
@ -111,14 +111,18 @@ namespace ICSharpCode.PythonBinding @@ -111,14 +111,18 @@ namespace ICSharpCode.PythonBinding
}
/// <summary>
/// This checks that the offset passed to the FindExpression method is valid. Usually the offset is
/// just after the last character in the text.
///
/// The offset must be:
///
/// 1) Greater or equal to zero.
/// 1) Greater than zero.
/// 2) Be inside the string.
/// 3) Be just after the end of the text.
/// </summary>
static bool IsValidOffset(string text, int offset)
{
return (offset >= 0) && (offset < text.Length);
return (offset > 0) && (offset <= text.Length);
}
/// <summary>

15
src/AddIns/BackendBindings/Python/PythonBinding/Test/Expressions/FindImportExpressionTestFixture.cs

@ -30,9 +30,8 @@ namespace PythonBinding.Tests.Expressions @@ -30,9 +30,8 @@ namespace PythonBinding.Tests.Expressions
public void ImportOnly()
{
string text = "import";
ExpressionResult result = expressionFinder.FindExpression(text, text.Length - 1);
Assert.AreEqual("import", result.Expression);
ExpressionResult result = expressionFinder.FindExpression(text, text.Length);
Assert.AreEqual("import", result.Expression);
}
/// <summary>
@ -43,7 +42,7 @@ namespace PythonBinding.Tests.Expressions @@ -43,7 +42,7 @@ namespace PythonBinding.Tests.Expressions
public void ImportWithNamespace()
{
string text = "import System";
ExpressionResult result = expressionFinder.FindExpression(text, text.Length - 1);
ExpressionResult result = expressionFinder.FindExpression(text, text.Length);
Assert.AreEqual("import System", result.Expression);
Assert.AreEqual(ExpressionContext.Importable, result.Context);
}
@ -52,7 +51,7 @@ namespace PythonBinding.Tests.Expressions @@ -52,7 +51,7 @@ namespace PythonBinding.Tests.Expressions
public void MultipleLinesWithImportAndNamespace()
{
string text = "# Line to ignore\r\nimport System";
ExpressionResult result = expressionFinder.FindExpression(text, text.Length - 1);
ExpressionResult result = expressionFinder.FindExpression(text, text.Length);
Assert.AreEqual("import System", result.Expression);
Assert.AreEqual(ExpressionContext.Importable, result.Context);
}
@ -61,7 +60,7 @@ namespace PythonBinding.Tests.Expressions @@ -61,7 +60,7 @@ namespace PythonBinding.Tests.Expressions
public void ImportWithExtraWhitespaceBeforeNamespace()
{
string text = "import System";
ExpressionResult result = expressionFinder.FindExpression(text, text.Length - 1);
ExpressionResult result = expressionFinder.FindExpression(text, text.Length);
Assert.AreEqual(text, result.Expression);
Assert.AreEqual(ExpressionContext.Importable, result.Context);
}
@ -70,7 +69,7 @@ namespace PythonBinding.Tests.Expressions @@ -70,7 +69,7 @@ namespace PythonBinding.Tests.Expressions
public void FromStatementBeforeImport()
{
string text = "from System import Test";
ExpressionResult result = expressionFinder.FindExpression(text, text.Length - 1);
ExpressionResult result = expressionFinder.FindExpression(text, text.Length);
Assert.AreEqual(text, result.Expression);
Assert.AreEqual(ExpressionContext.Importable, result.Context);
}
@ -82,7 +81,7 @@ namespace PythonBinding.Tests.Expressions @@ -82,7 +81,7 @@ namespace PythonBinding.Tests.Expressions
public void UppercaseImportWithNamespace()
{
string text = "IMPORT Test";
ExpressionResult result = expressionFinder.FindExpression(text, text.Length - 1);
ExpressionResult result = expressionFinder.FindExpression(text, text.Length);
Assert.AreEqual("Test", result.Expression);
}
}

26
src/AddIns/BackendBindings/Python/PythonBinding/Test/Expressions/FindSystemConsoleExpressionTestFixture.cs

@ -43,34 +43,32 @@ namespace PythonBinding.Tests.Expressions @@ -43,34 +43,32 @@ namespace PythonBinding.Tests.Expressions
public void SystemConsoleOnly()
{
string text = "System.Console";
AssertSystemConsoleExpressionFound(text, text.Length - 1);
AssertSystemConsoleExpressionFound(text, text.Length);
}
[Test]
public void MultipleLinesContainingCarriageReturnAndNewLine()
{
string text = "\r\nSystem.Console";
AssertSystemConsoleExpressionFound(text, text.Length - 1);
AssertSystemConsoleExpressionFound(text, text.Length);
}
[Test]
public void MultipleLinesContainingCarriageReturn()
{
string text = "\rSystem.Console";
AssertSystemConsoleExpressionFound(text, text.Length - 1);
AssertSystemConsoleExpressionFound(text, text.Length);
}
/// <summary>
/// Should find an empty string since the offset points
/// to the carriage return character.
/// Should find an empty string since the offset is after the carriage return character.
/// </summary>
[Test]
public void CarriageReturnAfterLastCharacter()
{
string text = "System.Console\r";
int offset = text.IndexOf('\r');
ExpressionResult result = expressionFinder.FindExpression(text, offset);
ExpressionResult result = expressionFinder.FindExpression(text, text.Length);
Assert.AreEqual(String.Empty, result.Expression);
}
@ -78,14 +76,14 @@ namespace PythonBinding.Tests.Expressions @@ -78,14 +76,14 @@ namespace PythonBinding.Tests.Expressions
public void SpaceBeforeSystemConsoleText()
{
string text = " System.Console";
AssertSystemConsoleExpressionFound(text, text.Length - 1);
AssertSystemConsoleExpressionFound(text, text.Length);
}
[Test]
public void TabBeforeSystemConsoleText()
{
string text = "\tSystem.Console";
AssertSystemConsoleExpressionFound(text, text.Length - 1);
AssertSystemConsoleExpressionFound(text, text.Length);
}
[Test]
@ -95,12 +93,20 @@ namespace PythonBinding.Tests.Expressions @@ -95,12 +93,20 @@ namespace PythonBinding.Tests.Expressions
ExpressionResult result = expressionFinder.FindExpression(text, 0);
Assert.IsNull(result.Expression);
}
[Test]
public void OffsetTooSmall()
{
string text = "a";
ExpressionResult result = expressionFinder.FindExpression(text, 0);
Assert.IsNull(result.Expression);
}
[Test]
public void OffsetTooLarge()
{
string text = "a";
ExpressionResult result = expressionFinder.FindExpression(text, text.Length);
ExpressionResult result = expressionFinder.FindExpression(text, text.Length + 1);
Assert.IsNull(result.Expression);
}

Loading…
Cancel
Save