Browse Source

Fixed code completion in WithStatements.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@798 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
e88d9dd139
  1. 2
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs
  2. 7
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/Parser/ExpressionFinder.cs
  3. 33
      src/Libraries/NRefactory/Project/Src/Parser/Visitors/LookupTableVisitor.cs
  4. 63
      src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryResolver.cs
  5. 3
      src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/CodeCompletionDataProvider.cs

2
src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs

@ -52,7 +52,7 @@ namespace VBNetBinding.FormattingStrategy
statements.Add(new VBStatement("\\bfor .*?$", "^next( \\w+)?$", "Next", 1)); statements.Add(new VBStatement("\\bfor .*?$", "^next( \\w+)?$", "Next", 1));
statements.Add(new VBStatement("^synclock .*?$", "^end synclock$", "End SyncLock", 1)); statements.Add(new VBStatement("^synclock .*?$", "^end synclock$", "End SyncLock", 1));
statements.Add(new VBStatement("^get$", "^end get$", "End Get", 1)); statements.Add(new VBStatement("^get$", "^end get$", "End Get", 1));
statements.Add(new VBStatement("^with \\w+$", "^end with$", "End With", 1)); statements.Add(new VBStatement("^with .*?$", "^end with$", "End With", 1));
statements.Add(new VBStatement("^set(\\s*\\(.*?\\))?$", "^end set$", "End Set", 1)); statements.Add(new VBStatement("^set(\\s*\\(.*?\\))?$", "^end set$", "End Set", 1));
statements.Add(new VBStatement("^try$", "^end try$", "End Try", 1)); statements.Add(new VBStatement("^try$", "^end try$", "End Try", 1));
statements.Add(new VBStatement("^do .+?$", "^loop$", "Loop", 1)); statements.Add(new VBStatement("^do .+?$", "^loop$", "Loop", 1));

7
src/AddIns/BackendBindings/VBNetBinding/Project/Src/Parser/ExpressionFinder.cs

@ -43,6 +43,7 @@ namespace VBNetBinding.Parser
{ {
return null; return null;
} }
//Console.WriteLine("---------------");
while (state != ERROR) while (state != ERROR)
{ {
ReadNextToken(); ReadNextToken();
@ -368,7 +369,7 @@ namespace VBNetBinding.Parser
string ident = ReadIdentifier(ch); string ident = ReadIdentifier(ch);
if (ident != null) if (ident != null)
{ {
switch (ident.ToLower()) switch (ident.ToLowerInvariant())
{ {
case "new": case "new":
curTokenType = New; curTokenType = New;
@ -515,9 +516,9 @@ namespace VBNetBinding.Parser
/*CURLY*/ { ERROR, ERROR, ERROR, ERROR, ERROR, CURLY2, ERROR, ERROR, ERROR}, /*CURLY*/ { ERROR, ERROR, ERROR, ERROR, ERROR, CURLY2, ERROR, ERROR, ERROR},
/*CURLY2*/ { ERROR, ERROR, ERROR, CURLY3, ERROR, ERROR, ERROR, ERROR, ERROR}, /*CURLY2*/ { ERROR, ERROR, ERROR, CURLY3, ERROR, ERROR, ERROR, ERROR, ERROR},
/*CURLY3*/ { ERROR, ERROR, ERROR, ERROR, ACCEPTNOMORE, ERROR, ERROR, ERROR, ERROR}, /*CURLY3*/ { ERROR, ERROR, ERROR, ERROR, ACCEPTNOMORE, ERROR, ERROR, ERROR, ERROR},
/*ACCEPT*/ { ERROR, MORE, ERROR, ERROR, ACCEPT, ERROR, ERROR, ERROR, ACCEPTNOMORE}, /*ACCEPT*/ { ERROR, ACCEPT2, ERROR, ERROR, ACCEPT, ERROR, ERROR, ERROR, ACCEPTNOMORE},
/*ACCEPTNOMORE*/ { ERROR, ERROR, ERROR, ERROR, ERROR, ERROR, ERROR, ERROR, ERROR}, /*ACCEPTNOMORE*/ { ERROR, ERROR, ERROR, ERROR, ERROR, ERROR, ERROR, ERROR, ERROR},
/*ACCEPT2*/ { ERROR, MORE, ERROR, ACCEPT, ACCEPT, ERROR, ERROR, ERROR, ERROR}, /*ACCEPT2*/ { ERROR, ACCEPT2, ERROR, ACCEPT, ACCEPT, ERROR, ERROR, ERROR, ERROR},
}; };
#endregion #endregion
} }

33
src/Libraries/NRefactory/Project/Src/Parser/Visitors/LookupTableVisitor.cs

@ -61,6 +61,14 @@ namespace ICSharpCode.NRefactory.Parser
} }
} }
List<WithStatement> withStatements = new List<WithStatement>();
public List<WithStatement> WithStatements {
get {
return withStatements;
}
}
public LookupTableVisitor(StringComparer nameComparer) public LookupTableVisitor(StringComparer nameComparer)
{ {
variables = new Dictionary<string, List<LocalLookupVariable>>(nameComparer); variables = new Dictionary<string, List<LocalLookupVariable>>(nameComparer);
@ -80,29 +88,10 @@ namespace ICSharpCode.NRefactory.Parser
list.Add(new LocalLookupVariable(typeRef, startPos, endPos, isConst)); list.Add(new LocalLookupVariable(typeRef, startPos, endPos, isConst));
} }
// todo: move this method to a better place. public override object Visit(WithStatement withStatement, object data)
bool IsInside(Point between, Point start, Point end)
{ {
if (between.Y < start.Y || between.Y > end.Y) { withStatements.Add(withStatement);
// Console.WriteLine("Y = {0} not between {1} and {2}", between.Y, start.Y, end.Y); return base.Visit(withStatement, data);
return false;
}
if (between.Y > start.Y) {
if (between.Y < end.Y) {
return true;
}
// between.Y == end.Y
// Console.WriteLine("between.Y = {0} == end.Y = {1}", between.Y, end.Y);
// Console.WriteLine("returning {0}:, between.X = {1} <= end.X = {2}", between.X <= end.X, between.X, end.X);
return between.X <= end.X;
}
// between.Y == start.Y
// Console.WriteLine("between.Y = {0} == start.Y = {1}", between.Y, start.Y);
if (between.X < start.X) {
return false;
}
// start is OK and between.Y <= end.Y
return between.Y < end.Y || between.X <= end.X;
} }
public override object Visit(LocalVariableDeclaration localVariableDeclaration, object data) public override object Visit(LocalVariableDeclaration localVariableDeclaration, object data)

63
src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryResolver.cs

@ -148,10 +148,8 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
Expression expr = null; Expression expr = null;
if (language == SupportedLanguage.VBNet) { if (language == SupportedLanguage.VBNet) {
if (expression == "") { if (expression.Length == 0 || expression[0] == '.') {
if ((expr = WithResolve()) == null) { return WithResolve(expression, fileContent);
return null;
}
} else if ("global".Equals(expression, StringComparison.InvariantCultureIgnoreCase)) { } else if ("global".Equals(expression, StringComparison.InvariantCultureIgnoreCase)) {
return new NamespaceResolveResult(null, null, ""); return new NamespaceResolveResult(null, null, "");
} }
@ -172,6 +170,46 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return ResolveInternal(expr, expressionResult.Context); return ResolveInternal(expr, expressionResult.Context);
} }
ResolveResult WithResolve(string expression, string fileContent)
{
RunLookupTableVisitor(fileContent);
WithStatement innermost = null;
if (lookupTableVisitor.WithStatements != null) {
foreach (WithStatement with in lookupTableVisitor.WithStatements) {
if (IsInside(new Point(caretColumn, caretLine), with.StartLocation, with.EndLocation)) {
innermost = with;
}
}
}
if (innermost != null) {
if (expression.Length > 1) {
Expression expr = ParseExpression(DummyFindVisitor.dummyName + expression);
if (expr == null) return null;
DummyFindVisitor v = new DummyFindVisitor();
expr.AcceptVisitor(v, null);
if (v.result == null) return null;
v.result.TargetObject = innermost.Expression;
return ResolveInternal(v.result, ExpressionContext.Default);
} else {
return ResolveInternal(innermost.Expression, ExpressionContext.Default);
}
} else {
return null;
}
}
private class DummyFindVisitor : AbstractASTVisitor {
internal const string dummyName = "___withStatementExpressionDummy";
internal FieldReferenceExpression result;
public override object Visit(FieldReferenceExpression fieldReferenceExpression, object data)
{
IdentifierExpression ie = fieldReferenceExpression.TargetObject as IdentifierExpression;
if (ie != null && ie.Identifier == dummyName)
result = fieldReferenceExpression;
return base.Visit(fieldReferenceExpression, data);
}
}
void RunLookupTableVisitor(string fileContent) void RunLookupTableVisitor(string fileContent)
{ {
lookupTableVisitor = new LookupTableVisitor(languageProperties.NameComparer); lookupTableVisitor = new LookupTableVisitor(languageProperties.NameComparer);
@ -607,23 +645,6 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
} }
#endregion #endregion
Expression WithResolve()
{
if (language != SupportedLanguage.VBNet) {
return null;
}
Expression expr = null;
// TODO :
// if (lookupTableVisitor.WithStatements != null) {
// foreach (WithStatement with in lookupTableVisitor.WithStatements) {
// if (IsInside(new Point(caretColumn, caretLine), with.StartLocation, with.EndLocation)) {
// expr = with.WithExpression;
// }
// }
// }
return expr;
}
Expression SpecialConstructs(string expression) Expression SpecialConstructs(string expression)
{ {
if (language == SupportedLanguage.VBNet) { if (language == SupportedLanguage.VBNet) {

3
src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/CodeCompletionDataProvider.cs

@ -53,7 +53,8 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
protected void GenerateCompletionData(TextArea textArea, ExpressionResult expressionResult) protected void GenerateCompletionData(TextArea textArea, ExpressionResult expressionResult)
{ {
if (expressionResult.Expression == null || expressionResult.Expression.Length == 0) { // allow empty string as expression (for VB 'With' statements)
if (expressionResult.Expression == null) {
return; return;
} }
if (LoggingService.IsDebugEnabled) { if (LoggingService.IsDebugEnabled) {

Loading…
Cancel
Save