Browse Source

When typing a variable declaration like "List<string> list = new ***", the new-completion popup preselects "List<string>".

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@250 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 21 years ago
parent
commit
0e75a514cf
  1. 21
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/ExpressionFinder.cs
  2. 10
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionListView.cs
  3. 86
      src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/AbstractCompletionDataProvider.cs

21
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/ExpressionFinder.cs

@ -60,17 +60,28 @@ namespace CSharpBinding.Parser
if (typeStart >= 0) { if (typeStart >= 0) {
string className = text.Substring(typeStart, typeEnd - typeStart); string className = text.Substring(typeStart, typeEnd - typeStart);
int pos = className.IndexOf('<'); int pos = className.IndexOf('<');
string nonGenericClassName; string nonGenericClassName, genericPart;
if (pos > 0) if (pos > 0) {
nonGenericClassName = className.Substring(0, pos); nonGenericClassName = className.Substring(0, pos);
else genericPart = className.Substring(pos);
} else {
nonGenericClassName = className; nonGenericClassName = className;
genericPart = null;
}
ClassFinder finder = new ClassFinder(fileName, text, typeStart); ClassFinder finder = new ClassFinder(fileName, text, typeStart);
IClass c = finder.SearchClass(nonGenericClassName); IClass c = finder.SearchClass(nonGenericClassName);
if (c != null) { if (c != null) {
ExpressionContext context = ExpressionContext.TypeDerivingFrom(c, true); ExpressionContext context = ExpressionContext.TypeDerivingFrom(c, true);
if (context.ShowEntry(c)) if (context.ShowEntry(c)) {
context.SuggestedItem = c; if (genericPart != null) {
DefaultClass genericClass = new DefaultClass(c.CompilationUnit, c.ClassType, c.Modifiers, c.Region, c.DeclaringType);
genericClass.FullyQualifiedName = c.FullyQualifiedName + genericPart;
genericClass.Documentation = c.Documentation;
context.SuggestedItem = genericClass;
} else {
context.SuggestedItem = c;
}
}
return context; return context;
} }
} }

10
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionListView.cs

@ -153,8 +153,6 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
string itemText = completionData[i].Text; string itemText = completionData[i].Text;
string lowerText = itemText.ToLower(); string lowerText = itemText.ToLower();
if (lowerText.StartsWith(startText)) { if (lowerText.StartsWith(startText)) {
if (i == selectedItem)
return;
double priority = completionData[i].Priority; double priority = completionData[i].Priority;
int quality; int quality;
if (lowerText == startText) { if (lowerText == startText) {
@ -171,9 +169,13 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
if (bestQuality < quality) { if (bestQuality < quality) {
useThisItem = true; useThisItem = true;
} else { } else {
useThisItem = bestQuality == quality && bestPriority < priority; if (bestIndex == selectedItem) {
if (useThisItem && bestIndex == i)
useThisItem = false; useThisItem = false;
} else if (i == selectedItem) {
useThisItem = bestQuality == quality;
} else {
useThisItem = bestQuality == quality && bestPriority < priority;
}
} }
if (useThisItem) { if (useThisItem) {
bestIndex = i; bestIndex = i;

86
src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/AbstractCompletionDataProvider.cs

@ -30,9 +30,11 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
} }
} }
int defaultIndex;
public int DefaultIndex { public int DefaultIndex {
get { get {
return -1; return defaultIndex;
} }
} }
@ -85,42 +87,68 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
if (list == null) { if (list == null) {
return; return;
} }
System.Diagnostics.Debugger.Break();
completionData.Capacity += list.Count; completionData.Capacity += list.Count;
CodeCompletionData suggestedData = null;
foreach (object o in list) { foreach (object o in list) {
if (context != null && !context.ShowEntry(o)) if (context != null && !context.ShowEntry(o))
continue; continue;
if (o is string) { CodeCompletionData ccd = CreateItem(o, context);
completionData.Add(new CodeCompletionData(o.ToString(), ClassBrowserIconService.NamespaceIndex)); if (object.Equals(o, context.SuggestedItem))
} else if (o is IClass) { suggestedData = ccd;
completionData.Add(new CodeCompletionData((IClass)o)); if (ccd != null)
} else if (o is IProperty) { completionData.Add(ccd);
IProperty property = (IProperty)o; }
if (property.Name != null && insertedPropertiesElements[property.Name] == null) { if (context.SuggestedItem != null) {
completionData.Add(new CodeCompletionData(property)); if (suggestedData == null) {
insertedPropertiesElements[property.Name] = property; suggestedData = CreateItem(context.SuggestedItem, context);
} if (suggestedData != null) {
} else if (o is IMethod) { completionData.Add(suggestedData);
IMethod method = (IMethod)o;
if (method.Name != null &&!method.IsConstructor) {
CodeCompletionData ccd = new CodeCompletionData(method);
if (insertedElements[method.Name] == null) {
completionData.Add(ccd);
insertedElements[method.Name] = ccd;
} else {
CodeCompletionData oldMethod = (CodeCompletionData)insertedElements[method.Name];
++oldMethod.Overloads;
}
} }
} else if (o is IField) { }
completionData.Add(new CodeCompletionData((IField)o)); if (suggestedData != null) {
} else if (o is IEvent) { completionData.Sort();
IEvent e = (IEvent)o; defaultIndex = completionData.IndexOf(suggestedData);
if (e.Name != null && insertedEventElements[e.Name] == null) { }
completionData.Add(new CodeCompletionData(e)); }
insertedEventElements[e.Name] = e; }
CodeCompletionData CreateItem(object o, ExpressionContext context)
{
if (o is string) {
return new CodeCompletionData(o.ToString(), ClassBrowserIconService.NamespaceIndex);
} else if (o is IClass) {
return new CodeCompletionData((IClass)o);
} else if (o is IProperty) {
IProperty property = (IProperty)o;
if (property.Name != null && insertedPropertiesElements[property.Name] == null) {
insertedPropertiesElements[property.Name] = property;
return new CodeCompletionData(property);
}
} else if (o is IMethod) {
IMethod method = (IMethod)o;
if (method.Name != null &&!method.IsConstructor) {
CodeCompletionData ccd = new CodeCompletionData(method);
if (insertedElements[method.Name] == null) {
insertedElements[method.Name] = ccd;
return ccd;
} else {
CodeCompletionData oldMethod = (CodeCompletionData)insertedElements[method.Name];
++oldMethod.Overloads;
} }
} }
} else if (o is IField) {
return new CodeCompletionData((IField)o);
} else if (o is IEvent) {
IEvent e = (IEvent)o;
if (e.Name != null && insertedEventElements[e.Name] == null) {
insertedEventElements[e.Name] = e;
return new CodeCompletionData(e);
}
} else {
throw new ApplicationException("Unknown object: " + o);
} }
return null;
} }
protected void AddResolveResults(ResolveResult results, ExpressionContext context) protected void AddResolveResults(ResolveResult results, ExpressionContext context)

Loading…
Cancel
Save