Browse Source

CodeCompletion inserts Attributes without the "Attribute" suffix (correctly - only in attribute contexts, that is [*expr*] class *expr*).

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5881 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Martin Koníček 15 years ago
parent
commit
10c5aadd92
  1. 21
      src/Main/Base/Project/Src/Editor/CodeCompletion/CodeCompletionItemProvider.cs
  2. 31
      src/Main/Base/Project/Src/Util/ExtensionMethods.cs

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

@ -11,8 +11,8 @@ using System.Collections.Generic; @@ -11,8 +11,8 @@ using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using ICSharpCode.Core;
using ICSharpCode.NRefactory;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project.Converter;
using ICSharpCode.SharpDevelop.Refactoring;
@ -286,6 +286,11 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion @@ -286,6 +286,11 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
addUsing = true;
}
// Special case for Attributes
if (insertedText.EndsWith("Attribute") && IsInAttributeContext(editor, context.StartOffset)) {
insertedText = insertedText.RemoveEnd("Attribute");
}
// Insert the text
context.Editor.Document.Replace(context.StartOffset, context.Length, insertedText);
context.EndOffset = context.StartOffset + insertedText.Length;
@ -302,6 +307,20 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion @@ -302,6 +307,20 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
}
}
/// <summary>
/// Returns true if the offset where we are inserting is in Attibute context, that is [*expr*
/// </summary>
bool IsInAttributeContext(ITextEditor editor, int offset)
{
if (editor == null || editor.Document == null)
return false;
var expressionFinder = ParserService.GetExpressionFinder(editor.FileName);
if (expressionFinder == null)
return false;
var resolvedExpression = expressionFinder.FindFullExpression(editor.Document.Text, offset);
return resolvedExpression.Context == ExpressionContext.Attribute;
}
#region Description
string description;
bool descriptionCreated;

31
src/Main/Base/Project/Src/Util/ExtensionMethods.cs

@ -17,7 +17,6 @@ using System.Windows.Controls; @@ -17,7 +17,6 @@ using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Documents;
using System.Windows.Forms;
using ICSharpCode.Core.Presentation;
using ICSharpCode.SharpDevelop.Gui;
using WinForms = System.Windows.Forms;
@ -319,6 +318,36 @@ namespace ICSharpCode.SharpDevelop @@ -319,6 +318,36 @@ namespace ICSharpCode.SharpDevelop
}
#endregion
/// <summary>
/// Removes <param name="stringToRemove" /> from the start of this string.
/// Throws ArgumentException if this string does not start with <param name="stringToRemove" />.
/// </summary>
public static string RemoveStart(this string s, string stringToRemove)
{
if (s == null)
return null;
if (string.IsNullOrEmpty(stringToRemove))
return s;
if (!s.StartsWith(stringToRemove))
throw new ArgumentException(string.Format("{0} does not start with {1}", s, stringToRemove));
return s.Substring(stringToRemove.Length);
}
/// <summary>
/// Removes <param name="stringToRemove" /> from the end of this string.
/// Throws ArgumentException if this string does not end with <param name="stringToRemove" />.
/// </summary>
public static string RemoveEnd(this string s, string stringToRemove)
{
if (s == null)
return null;
if (string.IsNullOrEmpty(stringToRemove))
return s;
if (!s.EndsWith(stringToRemove))
throw new ArgumentException(string.Format("{0} does not end with {1}", s, stringToRemove));
return s.Substring(0, s.Length - stringToRemove.Length);
}
public static string Replace(this string original, string pattern, string replacement, StringComparison comparisonType)
{
if (original == null)

Loading…
Cancel
Save