Browse Source

IronPython method insight window no longer stays open after method's closing parenthesis typed in.

pull/2/head
mrward 15 years ago
parent
commit
c995ead347
  1. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj
  2. 5
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeCompletionBinding.cs
  3. 77
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonInsightWindowHandler.cs
  4. 29
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Completion/PythonCodeCompletionBindingTests.cs
  5. 126
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Completion/PythonInsightWindowHandlerTests.cs
  6. 3
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
  7. 87
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/FakeInsightWindow.cs
  8. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/TestablePythonCodeCompletionBinding.cs
  9. 13
      src/AddIns/BackendBindings/Scripting/Test/Utils/FakeCaret.cs
  10. 2
      src/AddIns/BackendBindings/Scripting/Test/Utils/FakeDocument.cs

1
src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj

@ -103,6 +103,7 @@ @@ -103,6 +103,7 @@
<Compile Include="Src\PythonDotNetMethodResolver.cs" />
<Compile Include="Src\PythonFromImport.cs" />
<Compile Include="Src\PythonImport.cs" />
<Compile Include="Src\PythonInsightWindowHandler.cs" />
<Compile Include="Src\PythonLanguageBinding.cs" />
<Compile Include="Src\PythonLineIndenter.cs" />
<Compile Include="Src\PythonLocalVariableResolver.cs" />

5
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonCodeCompletionBinding.cs

@ -12,6 +12,11 @@ namespace ICSharpCode.PythonBinding @@ -12,6 +12,11 @@ namespace ICSharpCode.PythonBinding
{
public class PythonCodeCompletionBinding : DefaultCodeCompletionBinding
{
public PythonCodeCompletionBinding()
{
base.insightHandler = new PythonInsightWindowHandler();
}
/// <summary>
/// Shows the code completion window if the keyword is handled.
/// </summary>

77
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonInsightWindowHandler.cs

@ -0,0 +1,77 @@ @@ -0,0 +1,77 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
namespace ICSharpCode.PythonBinding
{
public class PythonInsightWindowHandler : IInsightWindowHandler
{
ITextEditor editor;
IInsightWindow insightWindow;
public void InitializeOpenedInsightWindow(ITextEditor editor, IInsightWindow insightWindow)
{
this.editor = editor;
this.insightWindow = insightWindow;
int offset = insightWindow.StartOffset;
insightWindow.DocumentChanged += DocumentChanged;
}
void DocumentChanged(object sender, TextChangeEventArgs e)
{
if (IsOutsideMethodCall()) {
insightWindow.Close();
}
}
bool IsOutsideMethodCall()
{
string text = GetTextInsideMethodCallUpToCursor();
return TextContainsClosingBracketForMethod(text);
}
string GetTextInsideMethodCallUpToCursor()
{
int insightStartOffset = insightWindow.StartOffset;
int currentOffset = editor.Caret.Offset;
int length = currentOffset - insightStartOffset;
if (length < 0) {
// Force completion window to close by returning the close bracket.
return ")";
}
return editor.Document.GetText(insightStartOffset, length);
}
bool TextContainsClosingBracketForMethod(string text)
{
int bracketCount = 1;
foreach (char ch in text) {
switch (ch) {
case '(':
bracketCount++;
break;
case ')':
bracketCount--;
if (bracketCount == 0) {
return true;
}
break;
}
}
return false;
}
public bool InsightRefreshOnComma(ITextEditor editor, char ch, out IInsightWindow insightWindow)
{
insightWindow = null;
return false;
}
public void HighlightParameter(IInsightWindow window, int index)
{
}
}
}

29
src/AddIns/BackendBindings/Python/PythonBinding/Test/Completion/PythonCodeCompletionBindingTests.cs

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Completion
{
[TestFixture]
public class PythonCodeCompletionBindingTests
{
TestablePythonCodeCompletionBinding completionBinding;
void CreatePythonCodeCompletionBinding()
{
completionBinding = new TestablePythonCodeCompletionBinding();
}
[Test]
public void InsightHandler_CreateNewCodecompletionBindingInstance_IsSetToPythonInsightWindowHandlerInstance()
{
CreatePythonCodeCompletionBinding();
PythonInsightWindowHandler handler = completionBinding.PythonInsightWindowHandler;
Assert.IsNotNull(handler);
}
}
}

126
src/AddIns/BackendBindings/Python/PythonBinding/Test/Completion/PythonInsightWindowHandlerTests.cs

@ -0,0 +1,126 @@ @@ -0,0 +1,126 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.PythonBinding;
using ICSharpCode.Scripting.Tests.Utils;
using ICSharpCode.SharpDevelop.Editor;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests.Completion
{
[TestFixture]
public class PythonInsightWindowHandlerTests
{
PythonInsightWindowHandler handler;
MockTextEditor fakeTextEditor;
FakeInsightWindow fakeInsightWindow;
void CreatePythonInsightWindowHandler()
{
fakeTextEditor = new MockTextEditor();
fakeInsightWindow = new FakeInsightWindow();
handler = new PythonInsightWindowHandler();
}
void InitializePythonInsightWindowHandler()
{
handler.InitializeOpenedInsightWindow(fakeTextEditor, fakeInsightWindow);
}
TextChangeEventArgs CreateInsertedTextChangeEventArgs(int offset, string insertedText)
{
return new TextChangeEventArgs(offset, String.Empty, insertedText);
}
[Test]
public void InitializeOpenedInsightWindow_CloseParenthesisCharacterAddedToDocument_InsightWindowClosed()
{
CreatePythonInsightWindowHandler();
fakeTextEditor.FakeDocument.Text = "method(";
fakeTextEditor.FakeCaret.Offset = 7;
fakeInsightWindow.StartOffset = 7;
InitializePythonInsightWindowHandler();
int newCaretOffset = 8;
fakeTextEditor.FakeCaret.Offset = newCaretOffset;
fakeTextEditor.FakeDocument.Text = "method()";
TextChangeEventArgs e = CreateInsertedTextChangeEventArgs(newCaretOffset, ")");
fakeInsightWindow.FireDocumentChangedEvent(e);
bool closed = fakeInsightWindow.IsClosed;
Assert.IsTrue(closed);
}
[Test]
public void InitializeOpenedInsightWindow_MethodCallWithCursorAtOpenBracket_InsightWindowIsClosedBeforeDocumentIsChanged()
{
CreatePythonInsightWindowHandler();
fakeTextEditor.FakeDocument.Text = "method(";
fakeTextEditor.FakeCaret.Offset = 7;
fakeInsightWindow.StartOffset = 7;
InitializePythonInsightWindowHandler();
bool closed = fakeInsightWindow.IsClosed;
Assert.IsFalse(closed);
}
[Test]
public void InitializeOpenedInsightWindow_SingleCharacterAddedToDocumentAfterOpenParenthesis_InsightWindowIsNotClosed()
{
CreatePythonInsightWindowHandler();
fakeTextEditor.FakeDocument.Text = "method(";
fakeTextEditor.FakeCaret.Offset = 7;
fakeInsightWindow.StartOffset = 7;
InitializePythonInsightWindowHandler();
int newCaretOffset = 8;
fakeTextEditor.FakeCaret.Offset = newCaretOffset;
fakeTextEditor.FakeDocument.Text = "method(a";
TextChangeEventArgs e = CreateInsertedTextChangeEventArgs(newCaretOffset, "a");
fakeInsightWindow.FireDocumentChangedEvent(e);
bool closed = fakeInsightWindow.IsClosed;
Assert.IsFalse(closed);
}
[Test]
public void InitializeOpenedInsightWindow_MethodCallInsideMethodCallAndCloseParenthesisCharacterAddedToDocument_InsightWindowIsNotClosed()
{
CreatePythonInsightWindowHandler();
fakeTextEditor.FakeDocument.Text = "method(a(";
fakeTextEditor.FakeCaret.Offset = 9;
fakeInsightWindow.StartOffset = 7;
InitializePythonInsightWindowHandler();
int newCaretOffset = 10;
fakeTextEditor.FakeCaret.Offset = newCaretOffset;
fakeTextEditor.FakeDocument.Text = "method(a()";
TextChangeEventArgs e = CreateInsertedTextChangeEventArgs(newCaretOffset, ")");
fakeInsightWindow.FireDocumentChangedEvent(e);
bool closed = fakeInsightWindow.IsClosed;
Assert.IsFalse(closed);
}
[Test]
public void InitializeOpenedInsightWindow_CharacterAddedToDocumentBeforeStartOfInsightWindow_InsightWindowClosed()
{
CreatePythonInsightWindowHandler();
fakeTextEditor.FakeDocument.Text = "method(";
fakeTextEditor.FakeCaret.Offset = 7;
fakeInsightWindow.StartOffset = 7;
InitializePythonInsightWindowHandler();
int newCaretOffset = 1;
fakeTextEditor.FakeCaret.Offset = newCaretOffset;
fakeTextEditor.FakeDocument.Text = "aethod(";
TextChangeEventArgs e = CreateInsertedTextChangeEventArgs(newCaretOffset, "a");
fakeInsightWindow.FireDocumentChangedEvent(e);
bool closed = fakeInsightWindow.IsClosed;
Assert.IsTrue(closed);
}
}
}

3
src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

@ -97,9 +97,11 @@ @@ -97,9 +97,11 @@
<Compile Include="Completion\ImportSubNamespaceCompletionTestFixture.cs" />
<Compile Include="Completion\MathModuleMembersInPythonContextTestFixture.cs" />
<Compile Include="Completion\NamespaceContentsAddedToCtrlSpaceTestFixture.cs" />
<Compile Include="Completion\PythonCodeCompletionBindingTests.cs" />
<Compile Include="Completion\PythonCodeCompletionItemProviderTests.cs" />
<Compile Include="Completion\PythonCompletionItemListTests.cs" />
<Compile Include="Completion\PythonImportExpressionContextTests.cs" />
<Compile Include="Completion\PythonInsightWindowHandlerTests.cs" />
<Compile Include="Completion\PythonSocketLibraryDocumentationTestFixture.cs" />
<Compile Include="Completion\SysModuleMembersInPythonContextTestFixture.cs" />
<Compile Include="Configuration\AddInOptionsTestFixture.cs" />
@ -417,6 +419,7 @@ @@ -417,6 +419,7 @@
<Compile Include="Utils\DerivedPythonDesignerGenerator.cs" />
<Compile Include="Utils\DerivedPythonFormsDesignerDisplayBinding.cs" />
<Compile Include="Utils\FakeCompletionItemProvider.cs" />
<Compile Include="Utils\FakeInsightWindow.cs" />
<Compile Include="Utils\PythonCodeDomSerializerHelper.cs" />
<Compile Include="Utils\PythonComponentWalkerHelper.cs" />
<Compile Include="Utils\PythonMSBuildEngineHelper.cs" />

87
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/FakeInsightWindow.cs

@ -0,0 +1,87 @@ @@ -0,0 +1,87 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
namespace PythonBinding.Tests.Utils
{
public class FakeInsightWindow : IInsightWindow
{
#pragma warning disable 67
public event EventHandler<TextChangeEventArgs> DocumentChanged;
public event EventHandler SelectedItemChanged;
public event EventHandler CaretPositionChanged;
public event EventHandler Closed;
#pragma warning restore 67
public bool IsClosed;
public IList<IInsightItem> Items {
get {
throw new NotImplementedException();
}
}
public IInsightItem SelectedItem {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
public double Width {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
public double Height {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
public bool CloseAutomatically {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
public int StartOffset { get; set; }
public int EndOffset {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
public void Close()
{
IsClosed = true;
}
public void FireDocumentChangedEvent(TextChangeEventArgs e)
{
if (DocumentChanged != null) {
DocumentChanged(this, e);
}
}
}
}

4
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/TestablePythonCodeCompletionBinding.cs

@ -47,5 +47,9 @@ namespace PythonBinding.Tests.Utils @@ -47,5 +47,9 @@ namespace PythonBinding.Tests.Utils
IsCodeCompletionWindowDisplayed = true;
CompletionItemProviderUsedWhenDisplayingCodeCompletionWindow = completionItemProvider;
}
public PythonInsightWindowHandler PythonInsightWindowHandler {
get { return base.insightHandler as PythonInsightWindowHandler; }
}
}
}

13
src/AddIns/BackendBindings/Scripting/Test/Utils/FakeCaret.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.NRefactory;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.Scripting.Tests.Utils
@ -17,15 +18,7 @@ namespace ICSharpCode.Scripting.Tests.Utils @@ -17,15 +18,7 @@ namespace ICSharpCode.Scripting.Tests.Utils
}
}
public int Offset {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
public int Offset { get; set; }
public int Line { get; set; }
public int Column {
@ -37,7 +30,7 @@ namespace ICSharpCode.Scripting.Tests.Utils @@ -37,7 +30,7 @@ namespace ICSharpCode.Scripting.Tests.Utils
}
}
public ICSharpCode.NRefactory.Location Position {
public Location Position {
get {
throw new NotImplementedException();
}

2
src/AddIns/BackendBindings/Scripting/Test/Utils/FakeDocument.cs

@ -124,7 +124,7 @@ namespace ICSharpCode.Scripting.Tests.Utils @@ -124,7 +124,7 @@ namespace ICSharpCode.Scripting.Tests.Utils
public string GetText(int offset, int length)
{
throw new NotImplementedException();
return Text.Substring(offset, length);
}
public object GetService(Type serviceType)

Loading…
Cancel
Save