From 5f53fa24ab86b8124b7e4a88034c5169f1e387fd Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 12 Nov 2010 08:01:10 +0100 Subject: [PATCH] fixed http://community.sharpdevelop.net/forums/t/12216.aspx --- .../Project/Src/CompletionDataHelper.cs | 8 +-- .../Project/Src/VBNetCompletionBinding.cs | 9 ++-- .../VBNetBinding/Test/CodeCompletionTests.cs | 50 +++++++++++++++++-- .../VBNetBinding/Test/TextEditorBasedTests.cs | 37 ++++++++++---- 4 files changed, 82 insertions(+), 22 deletions(-) diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/CompletionDataHelper.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/CompletionDataHelper.cs index 105ffdaacb..e56429d219 100644 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/CompletionDataHelper.cs +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/CompletionDataHelper.cs @@ -65,10 +65,10 @@ namespace ICSharpCode.VBNetBinding rr = new MemberResolveResult(rr.CallingClass, rr.CallingMember, singleMethod); } - data = rr.GetCompletionData(info.CompilationUnit.ProjectContent, ((NRefactoryCompletionItemList)result).ContainsItemsFromAllNamespaces) - ?? new NRefactoryResolver(LanguageProperties.VBNet) - .CtrlSpace(editor.Caret.Line, editor.Caret.Column, info, editor.Document.Text, - expressionResult.Context, ((NRefactoryCompletionItemList)result).ContainsItemsFromAllNamespaces); + if (rr is IntegerLiteralResolveResult && pressedKey == '.') + return result; + + data = rr.GetCompletionData(info.CompilationUnit.ProjectContent, ((NRefactoryCompletionItemList)result).ContainsItemsFromAllNamespaces) ?? new List(); resolvedType = rr.ResolvedType; } diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetCompletionBinding.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetCompletionBinding.cs index dbc2f3fcc8..62530b86c3 100644 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetCompletionBinding.cs +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/VBNetCompletionBinding.cs @@ -93,8 +93,10 @@ namespace ICSharpCode.VBNetBinding result = ef.FindExpression(editor.Document.Text, index); LoggingService.Debug("CC: After dot, result=" + result + ", context=" + result.Context); - ShowCompletion(result, editor, ch); - return CodeCompletionKeyPressResult.Completed; + if (ShowCompletion(result, editor, ch)) + return CodeCompletionKeyPressResult.Completed; + else + return CodeCompletionKeyPressResult.None; case '@': if (editor.Caret.Offset > 0 && editor.Document.GetCharAt(editor.Caret.Offset - 1) == '.') return CodeCompletionKeyPressResult.None; @@ -172,11 +174,12 @@ namespace ICSharpCode.VBNetBinding return false; } - static void ShowCompletion(ExpressionResult result, ITextEditor editor, char ch) + static bool ShowCompletion(ExpressionResult result, ITextEditor editor, char ch) { VBNetCompletionItemList list = CompletionDataHelper.GenerateCompletionData(result, editor, ch); list.Editor = editor; list.Window = editor.ShowCompletionWindow(list); + return list.Items.Any(); } #region Helpers diff --git a/src/AddIns/BackendBindings/VBNetBinding/Test/CodeCompletionTests.cs b/src/AddIns/BackendBindings/VBNetBinding/Test/CodeCompletionTests.cs index f1f4b451f9..97bc88d0b6 100644 --- a/src/AddIns/BackendBindings/VBNetBinding/Test/CodeCompletionTests.cs +++ b/src/AddIns/BackendBindings/VBNetBinding/Test/CodeCompletionTests.cs @@ -17,7 +17,7 @@ namespace ICSharpCode.VBNetBinding.Tests [Test] public void TestEmptyFile() { - TestKeyPress("", "", 'o', CodeCompletionKeyPressResult.CompletedIncludeKeyInCompletion, + TestKeyPress("|", 'o', CodeCompletionKeyPressResult.CompletedIncludeKeyInCompletion, list => { Assert.IsTrue(list.Items.Any()); Assert.IsTrue(list.Items.All(item => item.Image == ClassBrowserIconService.Keyword)); @@ -32,7 +32,7 @@ namespace ICSharpCode.VBNetBinding.Tests [Test] public void TestOptions() { - TestKeyPress("Option", "\n", ' ', CodeCompletionKeyPressResult.EatKey, + TestKeyPress("Option|\n", ' ', CodeCompletionKeyPressResult.EatKey, list => { Assert.IsTrue(list.Items.Any()); Assert.IsTrue(list.Items.All(item => item.Image == ClassBrowserIconService.Keyword)); @@ -45,7 +45,7 @@ namespace ICSharpCode.VBNetBinding.Tests [Test] public void TestOptionCompare() { - TestKeyPress("Option Compare", "\n", ' ', CodeCompletionKeyPressResult.EatKey, + TestKeyPress("Option Compare|\n", ' ', CodeCompletionKeyPressResult.EatKey, list => { Assert.IsTrue(list.Items.Any()); Assert.IsTrue(list.Items.All(item => item.Image == ClassBrowserIconService.Keyword)); @@ -59,7 +59,7 @@ namespace ICSharpCode.VBNetBinding.Tests public void TestOnOffOptions() { foreach (string option in new[] { "Infer", "Strict", "Explicit" }) { - TestKeyPress(string.Format("Option {0} ", option), "\n", 'o', CodeCompletionKeyPressResult.CompletedIncludeKeyInCompletion, + TestKeyPress(string.Format("Option {0} |\n", option), 'o', CodeCompletionKeyPressResult.CompletedIncludeKeyInCompletion, list => { Assert.IsTrue(list.Items.Any()); Assert.IsTrue(list.Items.All(item => item.Image == ClassBrowserIconService.Keyword)); @@ -77,5 +77,47 @@ namespace ICSharpCode.VBNetBinding.Tests foreach (string element in expected) Assert.Contains(element, items); } + + [Test] + public void TestDotAfterDigit() + { + string text = @"Module Test + Public Function fn() As Double + Dim f As Double + f = 1| + End Function +End Module"; + + TestKeyPress(text, '.', CodeCompletionKeyPressResult.None, list => Assert.IsFalse(list.Items.Any())); + } + + [Test] + public void TestDotAfterIdentifier() + { + string text = @"Module Test + Public Function fn(x As Double) As Double + Dim f As Double + f = x| + End Function +End Module"; + + TestKeyPress(text, '.', CodeCompletionKeyPressResult.Completed, list => Assert.IsTrue(list.Items.Any())); + } + + [Test] + public void TestWithBlockCtrlSpace() + { + string text = @"Module Test + Sub Test2(a As Exception) + With a + | + End With + End Sub +End Module"; + + // TODO seems to be wrong! + + TestCtrlSpace(text, true, list => Assert.IsFalse(list.Items.Any(i => i.Text == "InnerException"))); + } } } diff --git a/src/AddIns/BackendBindings/VBNetBinding/Test/TextEditorBasedTests.cs b/src/AddIns/BackendBindings/VBNetBinding/Test/TextEditorBasedTests.cs index a47d0574b6..d7d0ba1966 100644 --- a/src/AddIns/BackendBindings/VBNetBinding/Test/TextEditorBasedTests.cs +++ b/src/AddIns/BackendBindings/VBNetBinding/Test/TextEditorBasedTests.cs @@ -18,10 +18,15 @@ namespace ICSharpCode.VBNetBinding.Tests this.textEditor = new MockTextEditor(); } - protected void TestCtrlSpace(string fileHeader, string fileFooter, bool expected, Action constraint) + protected void TestCtrlSpace(string file, bool expected, Action constraint) { - this.textEditor.Document.Text = fileHeader + fileFooter; - this.textEditor.Caret.Offset = fileHeader.Length; + int insertionPoint = file.IndexOf('|'); + + if (insertionPoint < 0) + Assert.Fail("insertionPoint not found in text!"); + + this.textEditor.Document.Text = file.Replace("|", ""); + this.textEditor.Caret.Offset = insertionPoint; this.textEditor.CreateParseInformation(); bool invoked = new VBNetCompletionBinding().CtrlSpace(textEditor); @@ -33,10 +38,15 @@ namespace ICSharpCode.VBNetBinding.Tests constraint(list); } - protected void TestKeyPress(string fileHeader, string fileFooter, char keyPressed, CodeCompletionKeyPressResult keyPressResult, Action constraint) + protected void TestKeyPress(string file, char keyPressed, CodeCompletionKeyPressResult keyPressResult, Action constraint) { - this.textEditor.Document.Text = fileHeader + fileFooter; - this.textEditor.Caret.Offset = fileHeader.Length; + int insertionPoint = file.IndexOf('|'); + + if (insertionPoint < 0) + Assert.Fail("insertionPoint not found in text!"); + + this.textEditor.Document.Text = file.Replace("|", ""); + this.textEditor.Caret.Offset = insertionPoint; this.textEditor.CreateParseInformation(); CodeCompletionKeyPressResult result = new VBNetCompletionBinding().HandleKeyPress(textEditor, keyPressed); @@ -48,10 +58,15 @@ namespace ICSharpCode.VBNetBinding.Tests constraint(list); } - protected void TestTextInsert(string fileHeader, string fileFooter, char completionChar, ICompletionItemList list, ICompletionItem item, string expectedOutput, int expectedOffset) + protected void TestTextInsert(string file, char completionChar, ICompletionItemList list, ICompletionItem item, string expectedOutput, int expectedOffset) { - this.textEditor.Document.Text = fileHeader + fileFooter; - this.textEditor.Caret.Offset = fileHeader.Length; + int insertionPoint = file.IndexOf('|'); + + if (insertionPoint < 0) + Assert.Fail("insertionPoint not found in text!"); + + this.textEditor.Document.Text = file.Replace("|", ""); + this.textEditor.Caret.Offset = insertionPoint; this.textEditor.CreateParseInformation(); CompletionContext context = new CompletionContext() { @@ -66,10 +81,10 @@ namespace ICSharpCode.VBNetBinding.Tests if (!context.CompletionCharHandled && context.CompletionChar != '\n') this.textEditor.Document.Insert(this.textEditor.Caret.Offset, completionChar + ""); - string insertedText = this.textEditor.Document.GetText(fileHeader.Length, this.textEditor.Document.TextLength - fileHeader.Length - fileFooter.Length); + string insertedText = this.textEditor.Document.GetText(insertionPoint, this.textEditor.Document.TextLength - file.Length + 1); Assert.AreEqual(expectedOutput, insertedText); - Assert.AreEqual(fileHeader.Length + expectedOffset, textEditor.Caret.Offset); + Assert.AreEqual(insertionPoint + expectedOffset, textEditor.Caret.Offset); } } }