Browse Source

Merge branch 'master' into originmaster

pull/15/head
mkonicek 15 years ago
parent
commit
e0afdc063d
  1. 27
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpCompletionBinding.cs
  2. 2
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  3. 73
      src/Main/Base/Project/Src/Editor/CodeCompletion/CodeCompletionItemProvider.cs
  4. 12
      src/Main/Base/Project/Src/Services/ParserService/ParserService.cs
  5. 0
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsHelper.cs
  6. 5
      src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/EditorContext.cs

27
src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpCompletionBinding.cs

@ -261,10 +261,10 @@ namespace CSharpBinding
new ClassFinder(ParserService.GetParseInformation(editor.FileName), editor.Caret.Line, editor.Caret.Column) new ClassFinder(ParserService.GetParseInformation(editor.FileName), editor.Caret.Line, editor.Caret.Column)
), ""); ), "");
if (suggestedClassName != c.Name) { if (suggestedClassName != c.Name) {
// create an IClass instance that includes the type arguments in its name // create a special code completion item that completes also the type arguments
context.SuggestedItem = new RenamedClass(c, suggestedClassName); context.SuggestedItem = new SuggestedCodeCompletionItem(c, suggestedClassName);
} else { } else {
context.SuggestedItem = c; context.SuggestedItem = new CodeCompletionItem(c);
} }
} }
return context; return context;
@ -273,27 +273,6 @@ namespace CSharpBinding
return null; return null;
} }
/// <summary>
/// A class that copies the properties important for the code completion display from another class,
/// but provides its own Name implementation.
/// Unlike the AbstractEntity.Name implementation, here 'Name' may include the namespace or type arguments.
/// </summary>
sealed class RenamedClass : DefaultClass, IClass
{
string newName;
public RenamedClass(IClass c, string newName) : base(c.CompilationUnit, c.ClassType, c.Modifiers, c.Region, c.DeclaringType)
{
this.newName = newName;
CopyDocumentationFrom(c);
this.FullyQualifiedName = c.FullyQualifiedName;
}
string ICompletionEntry.Name {
get { return newName; }
}
}
#region "case"-keyword completion #region "case"-keyword completion
bool DoCaseCompletion(ITextEditor editor) bool DoCaseCompletion(ITextEditor editor)
{ {

2
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -352,6 +352,7 @@
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsBulbViewModel.cs" /> <Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsBulbViewModel.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsHelper.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsPopupBase.cs" /> <Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsPopupBase.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsProvider.cs" /> <Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsProvider.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsService.cs" /> <Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsService.cs" />
@ -363,7 +364,6 @@
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsPopup.cs" /> <Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsPopup.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsViewModel.cs" /> <Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionsViewModel.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionViewModel.cs" /> <Compile Include="Src\Services\RefactoringService\ContextActions\ContextActionViewModel.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActionsHelper.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\IContextActionCache.cs" /> <Compile Include="Src\Services\RefactoringService\ContextActions\IContextActionCache.cs" />
<Compile Include="Src\Services\RefactoringService\ContextActions\IContextActionsProvider.cs" /> <Compile Include="Src\Services\RefactoringService\ContextActions\IContextActionsProvider.cs" />
<Compile Include="Src\Services\RefactoringService\ExtractInterfaceOptions.cs" /> <Compile Include="Src\Services\RefactoringService\ExtractInterfaceOptions.cs" />

73
src/Main/Base/Project/Src/Editor/CodeCompletion/CodeCompletionItemProvider.cs

@ -154,18 +154,13 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
if (method != null && codeItem != null) { if (method != null && codeItem != null) {
methodItems[method.Name] = codeItem; methodItems[method.Name] = codeItem;
} }
if (o.Equals(context.SuggestedItem))
result.SuggestedItem = item;
} }
} }
if (context.SuggestedItem != null) { // Suggested entry (List<int> a = new => suggest List<int>).
if (result.SuggestedItem == null) { if (context.SuggestedItem is SuggestedCodeCompletionItem) {
result.SuggestedItem = CreateCompletionItem(context.SuggestedItem, context); result.SuggestedItem = (SuggestedCodeCompletionItem)context.SuggestedItem;
if (result.SuggestedItem != null) { result.Items.Insert(0, result.SuggestedItem);
result.Items.Insert(0, result.SuggestedItem);
}
}
} }
return result; return result;
} }
@ -238,6 +233,7 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
description = ambience.Convert(entity); description = ambience.Convert(entity);
this.Image = ClassBrowserIconService.GetIcon(entity); this.Image = ClassBrowserIconService.GetIcon(entity);
this.Overloads = 1; this.Overloads = 1;
this.InsertGenericArguments = false;
this.Priority = CodeCompletionDataUsageCache.GetPriority(entity.DotNetName, true); this.Priority = CodeCompletionDataUsageCache.GetPriority(entity.DotNetName, true);
} }
@ -252,6 +248,12 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
public IImage Image { get; set; } public IImage Image { get; set; }
/// <summary>
/// If true, will insert Text including generic arguments (e.g. List&lt;T&gt; or List&lt;string&gt;).
/// Otherwise will insert Text without generic arguments (e.g. List).
/// </summary>
public bool InsertGenericArguments { get; set; }
protected void MarkAsUsed() protected void MarkAsUsed()
{ {
CodeCompletionDataUsageCache.IncrementUsage(entity.DotNetName); CodeCompletionDataUsageCache.IncrementUsage(entity.DotNetName);
@ -288,8 +290,7 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
addUsing = !IsKnownName(nameResult); addUsing = !IsKnownName(nameResult);
} }
//insertedText = StripGenericArgument(insertedText, context); InsertTextStripGenericArguments(context, insertedText, this.InsertGenericArguments);
InsertText(context, insertedText);
if (addUsing && nameResult != null && nameResult.CallingClass != null) { if (addUsing && nameResult != null && nameResult.CallingClass != null) {
var cu = nameResult.CallingClass.CompilationUnit; var cu = nameResult.CallingClass.CompilationUnit;
@ -298,15 +299,28 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
} }
} else { } else {
// Something else than a class or Extension method is being inserted - just insert text // Something else than a class or Extension method is being inserted - just insert text
//insertedText = StripGenericArgument(insertedText, context); InsertTextStripGenericArguments(context, insertedText, this.InsertGenericArguments);
InsertText(context, insertedText); }
}
/// <summary>
/// Inserts the given text. Strips generic arguments from it if specified.
/// </summary>
static void InsertTextStripGenericArguments(CompletionContext context, string insertedText, bool stringGenericArguments)
{
if (!stringGenericArguments) {
// FIXME CodeCompletionItem should contain IReturnType and decide whether to INCLUDE generic arguments
// or not, not strip them.
insertedText = StripGenericArguments(insertedText, context);
} }
context.Editor.Document.Replace(context.StartOffset, context.Length, insertedText);
context.EndOffset = context.StartOffset + insertedText.Length;
} }
/// <summary> /// <summary>
/// Turns e.g. "List&lt;T&gt;" into "List&lt;" /// Turns e.g. "List&lt;T&gt;" into "List&lt;"
/// </summary> /// </summary>
string StripGenericArgument(string itemText, CompletionContext context) static string StripGenericArguments(string itemText, CompletionContext context)
{ {
if (context == null || context.Editor == null || context.Editor.Language == null || if (context == null || context.Editor == null || context.Editor.Language == null ||
context.Editor.Language.Properties != LanguageProperties.CSharp) context.Editor.Language.Properties != LanguageProperties.CSharp)
@ -325,23 +339,6 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
return itemText; return itemText;
} }
bool IsReferenceTo(ResolveResult nameResult, IClass selectedClass)
{
// CC list contains RenamedClass instances which are kind of hacky:
// their name is e.g. "List<string>" or "int[]", but they do not have any generic arguments,
// so IsReferenceTo fails bc it compares generic argument count.
// This compares just name and ignores generic arguments.
return nameResult.IsReferenceTo(selectedClass) ||
(nameResult.ResolvedType.IsConstructedReturnType &&
nameResult.ResolvedType.FullyQualifiedName == selectedClass.FullyQualifiedName);
}
void InsertText(CompletionContext context, string insertedText)
{
context.Editor.Document.Replace(context.StartOffset, context.Length, insertedText);
context.EndOffset = context.StartOffset + insertedText.Length;
}
IClass GetClassOrExtensionMethodClass(IEntity selectedEntity) IClass GetClassOrExtensionMethodClass(IEntity selectedEntity)
{ {
var selectedClass = selectedEntity as IClass; var selectedClass = selectedEntity as IClass;
@ -514,4 +511,18 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
} }
#endregion #endregion
} }
/// <summary>
/// CodeCompletionItem that inserts also generic arguments.
/// Used only when suggesting items in CC (e.g. List&lt;int&gt; a = new => suggest List&lt;int&gt;).
/// </summary>
public class SuggestedCodeCompletionItem : CodeCompletionItem
{
public SuggestedCodeCompletionItem(IEntity entity, string nameWithSpecifiedGenericArguments)
: base(entity)
{
this.Text = nameWithSpecifiedGenericArguments;
this.InsertGenericArguments = true;
}
}
} }

12
src/Main/Base/Project/Src/Services/ParserService/ParserService.cs

@ -276,6 +276,12 @@ namespace ICSharpCode.SharpDevelop
return null; return null;
} }
public static ResolveResult Resolve(int offset, IDocument document, string fileName)
{
var position = document.OffsetToPosition(offset);
return Resolve(position.Line, position.Column, document, fileName);
}
public static ExpressionResult FindFullExpression(int caretLine, int caretColumn, IDocument document, string fileName) public static ExpressionResult FindFullExpression(int caretLine, int caretColumn, IDocument document, string fileName)
{ {
IExpressionFinder expressionFinder = GetExpressionFinder(fileName); IExpressionFinder expressionFinder = GetExpressionFinder(fileName);
@ -285,12 +291,6 @@ namespace ICSharpCode.SharpDevelop
return ExpressionResult.Empty; return ExpressionResult.Empty;
return expressionFinder.FindFullExpression(document.Text, document.PositionToOffset(caretLine, caretColumn)); return expressionFinder.FindFullExpression(document.Text, document.PositionToOffset(caretLine, caretColumn));
} }
public static ResolveResult Resolve(int offset, IDocument document, string fileName)
{
var position = document.OffsetToPosition(offset);
return Resolve(position.Line, position.Column, document, fileName);
}
#endregion #endregion
#region GetParseableFileContent #region GetParseableFileContent

0
src/Main/Base/Project/Src/Services/RefactoringService/ContextActionsHelper.cs → src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsHelper.cs

5
src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/EditorContext.cs

@ -181,11 +181,12 @@ namespace ICSharpCode.SharpDevelop.Refactoring
---------------------- ----------------------
CurrentLineAST: {2} CurrentLineAST: {2}
---------------------- ----------------------
AstNodeAtCaret: {3} CurrentASTNode: [{3}] {4}
---------------------- ----------------------
CurrentMemberAST: {4} CurrentMemberAST: {5}
----------------------", ----------------------",
CurrentExpression, CurrentSymbol, CurrentLineAST, CurrentExpression, CurrentSymbol, CurrentLineAST,
CurrentElement == null ? "" : CurrentElement.GetType().ToString(),
CurrentElement == null ? "" : CurrentElement.ToString().TakeStartEllipsis(400), CurrentElement == null ? "" : CurrentElement.ToString().TakeStartEllipsis(400),
CurrentMemberAST == null ? "" : CurrentMemberAST.ToString().TakeStartEllipsis(400))); CurrentMemberAST == null ? "" : CurrentMemberAST.ToString().TakeStartEllipsis(400)));
} }

Loading…
Cancel
Save