Browse Source

Fixed some keyword cc tests.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
63367b955b
  1. 16
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs
  2. 64
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/KeywordTests.cs

16
ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs

@ -431,12 +431,13 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
// Do not pop up completion on identifier identifier (should be handled by keyword completion). // Do not pop up completion on identifier identifier (should be handled by keyword completion).
tokenIndex = offset - 1; tokenIndex = offset - 1;
token = GetPreviousToken (ref tokenIndex, false); token = GetPreviousToken (ref tokenIndex, false);
if (identifierStart == null && !string.IsNullOrEmpty (token) && !(IsInsideComment (tokenIndex) || IsInsideString (tokenIndex))) { int prevTokenIndex = tokenIndex;
var prevToken2 = GetPreviousToken (ref prevTokenIndex, false);
if (identifierStart == null && !string.IsNullOrEmpty (token) && !(IsInsideComment (tokenIndex) || IsInsideString (tokenIndex)) && (prevToken2 == ";" || prevToken2 == "{" || prevToken2 == "}")) {
Console.WriteLine ("!");
char last = token [token.Length - 1]; char last = token [token.Length - 1];
if (char.IsLetterOrDigit (last) || last == '_' || token == ">") { if (char.IsLetterOrDigit (last) || last == '_' || token == ">") {
return HandleKeywordCompletion (tokenIndex, token); return HandleKeywordCompletion (tokenIndex, token);
//return controlSpace ? DefaultControlSpaceItems () : null;
} }
} }
if (identifierStart == null) if (identifierStart == null)
@ -622,6 +623,8 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
IEnumerable<ICompletionData> DefaultControlSpaceItems () IEnumerable<ICompletionData> DefaultControlSpaceItems ()
{ {
var wrapper = new CompletionDataWrapper (this); var wrapper = new CompletionDataWrapper (this);
if (offset >= document.TextLength)
offset = document.TextLength - 1;
while (offset > 1 && char.IsWhiteSpace (document.GetCharAt (offset))) { while (offset > 1 && char.IsWhiteSpace (document.GetCharAt (offset))) {
offset--; offset--;
} }
@ -674,10 +677,10 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
AddTypesAndNamespaces (wrapper, state, node, typePred); AddTypesAndNamespaces (wrapper, state, node, typePred);
wrapper.Result.Add (factory.CreateLiteralCompletionData ("global")); wrapper.Result.Add (factory.CreateLiteralCompletionData ("global"));
if (state.CurrentMember != null) { if (currentMember != null) {
AddKeywords (wrapper, statementStartKeywords); AddKeywords (wrapper, statementStartKeywords);
AddKeywords (wrapper, expressionLevelKeywords); AddKeywords (wrapper, expressionLevelKeywords);
} else if (state.CurrentTypeDefinition != null) { } else if (currentType != null) {
AddKeywords (wrapper, typeLevelKeywords); AddKeywords (wrapper, typeLevelKeywords);
} else { } else {
AddKeywords (wrapper, globalLevelKeywords); AddKeywords (wrapper, globalLevelKeywords);
@ -2082,7 +2085,8 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
"true", "false", "typeof", "checked", "unchecked", "from", "break", "checked", "true", "false", "typeof", "checked", "unchecked", "from", "break", "checked",
"unchecked", "const", "continue", "do", "finally", "fixed", "for", "foreach", "unchecked", "const", "continue", "do", "finally", "fixed", "for", "foreach",
"goto", "if", "lock", "return", "stackalloc", "switch", "throw", "try", "unsafe", "goto", "if", "lock", "return", "stackalloc", "switch", "throw", "try", "unsafe",
"using", "while", "yield", "dynamic", "var" }; "using", "while", "yield", "dynamic", "var", "dynamic"
};
static string[] globalLevelKeywords = new string [] { static string[] globalLevelKeywords = new string [] {
"namespace", "using", "extern", "public", "internal", "namespace", "using", "extern", "public", "internal",
"class", "interface", "struct", "enum", "delegate", "class", "interface", "struct", "enum", "delegate",

64
ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/KeywordTests.cs

@ -161,7 +161,6 @@ class Test
}); });
} }
[Ignore("needs to be fixed in parser.")]
[Test()] [Test()]
public void IsAsKeywordTest () public void IsAsKeywordTest ()
{ {
@ -196,7 +195,6 @@ provider => {
}); });
} }
[Ignore()]
[Test()] [Test()]
public void PublicClassContextTest2 () public void PublicClassContextTest2 ()
{ {
@ -209,7 +207,6 @@ provider => {
}); });
} }
[Ignore()]
[Test()] [Test()]
public void PublicClassContextTestContinuation1 () public void PublicClassContextTestContinuation1 ()
{ {
@ -220,7 +217,6 @@ provider => {
}); });
} }
[Ignore()]
[Test()] [Test()]
public void PublicClassContextTestContinuation2 () public void PublicClassContextTestContinuation2 ()
{ {
@ -231,6 +227,66 @@ provider => {
}); });
} }
[Test()]
public void StatementKeywordTests ()
{
CodeCompletionBugTests.CombinedProviderTest (
@"using System;
class Test
{
public void MyMethod ()
{
$s$
}
", (provider) => {
Assert.IsNotNull (provider.Find ("bool"), "keyword 'bool' not found.");
Assert.IsNotNull (provider.Find ("char"), "keyword 'char' not found.");
Assert.IsNotNull (provider.Find ("byte"), "keyword 'byte' not found.");
Assert.IsNotNull (provider.Find ("sbyte"), "keyword 'sbyte' not found.");
Assert.IsNotNull (provider.Find ("int"), "keyword 'int' not found.");
Assert.IsNotNull (provider.Find ("uint"), "keyword 'uint' not found.");
Assert.IsNotNull (provider.Find ("short"), "keyword 'short' not found.");
Assert.IsNotNull (provider.Find ("ushort"), "keyword 'ushort' not found.");
Assert.IsNotNull (provider.Find ("long"), "keyword 'long' not found.");
Assert.IsNotNull (provider.Find ("ulong"), "keyword 'ulong' not found.");
Assert.IsNotNull (provider.Find ("float"), "keyword 'float' not found.");
Assert.IsNotNull (provider.Find ("double"), "keyword 'double' not found.");
Assert.IsNotNull (provider.Find ("decimal"), "keyword 'decimal' not found.");
Assert.IsNotNull (provider.Find ("const"), "keyword 'const' not found.");
Assert.IsNotNull (provider.Find ("dynamic"), "keyword 'dynamic' not found.");
Assert.IsNotNull (provider.Find ("var"), "keyword 'var' not found.");
Assert.IsNotNull (provider.Find ("do"), "keyword 'do' not found.");
Assert.IsNotNull (provider.Find ("while"), "keyword 'while' not found.");
Assert.IsNotNull (provider.Find ("for"), "keyword 'for' not found.");
Assert.IsNotNull (provider.Find ("foreach"), "keyword 'foreach' not found.");
Assert.IsNotNull (provider.Find ("goto"), "keyword 'goto' not found.");
Assert.IsNotNull (provider.Find ("break"), "keyword 'break' not found.");
Assert.IsNotNull (provider.Find ("continue"), "keyword 'continue' not found.");
Assert.IsNotNull (provider.Find ("return"), "keyword 'return' not found.");
Assert.IsNotNull (provider.Find ("throw"), "keyword 'throw' not found.");
Assert.IsNotNull (provider.Find ("fixed"), "keyword 'fixed' not found.");
Assert.IsNotNull (provider.Find ("using"), "keyword 'using' not found.");
Assert.IsNotNull (provider.Find ("lock"), "keyword 'lock' not found.");
Assert.IsNotNull (provider.Find ("true"), "keyword 'true' not found.");
Assert.IsNotNull (provider.Find ("false"), "keyword 'false' not found.");
Assert.IsNotNull (provider.Find ("null"), "keyword 'null' not found.");
Assert.IsNotNull (provider.Find ("typeof"), "keyword 'typeof' not found.");
Assert.IsNotNull (provider.Find ("sizeof"), "keyword 'sizeof' not found.");
Assert.IsNotNull (provider.Find ("from"), "keyword 'from' not found.");
Assert.IsNotNull (provider.Find ("yield"), "keyword 'yield' not found.");
Assert.IsNotNull (provider.Find ("new"), "keyword 'new' not found.");
});
}
} }
} }

Loading…
Cancel
Save