Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorMike Krüger <mkrueger@xamarin.com>2017-07-31 12:45:18 +0300
committerGitHub <noreply@github.com>2017-07-31 12:45:18 +0300
commit4c4d81697f46711ed33e78d319aaa713d84fff8b (patch)
treebd6127a6511a6f8f8c4f15598db49b8ee0b0c721 /main
parenta5d260c0df0afbfb75c5cafd0740b27aa696cca2 (diff)
parent9bdf0e1bef87aa48db2afb16662f11d019e29f40 (diff)
Merge pull request #2839 from mono/master-fix58473
Fixed 'Bug 58473 - [VSFeedback Ticket] #460850 - Complete Word hotkey
Diffstat (limited to 'main')
-rw-r--r--main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/CSharpCompletionTextEditorExtension.cs704
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor.Extension/CompletionTextEditorExtension.cs3
-rw-r--r--main/tests/UnitTests/MonoDevelop.CSharpBinding/CSharpCompletionTextEditorTests.cs95
-rw-r--r--main/tests/UnitTests/UnitTests.csproj1
4 files changed, 448 insertions, 355 deletions
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/CSharpCompletionTextEditorExtension.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/CSharpCompletionTextEditorExtension.cs
index 8bdb0f963d..538b8b4acd 100644
--- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/CSharpCompletionTextEditorExtension.cs
+++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/CSharpCompletionTextEditorExtension.cs
@@ -241,10 +241,6 @@ namespace MonoDevelop.CSharp.Completion
public override Task<ICompletionDataList> HandleCodeCompletionAsync (CodeCompletionContext completionContext, CompletionTriggerInfo triggerInfo, CancellationToken token = default (CancellationToken))
{
- // if (!EnableCodeCompletion)
- // return null;
- if (!IdeApp.Preferences.EnableAutoCodeCompletion)
- return null;
int triggerWordLength = 0;
switch (triggerInfo.CompletionTriggerReason) {
case CompletionTriggerReason.CharTyped:
@@ -718,425 +714,425 @@ namespace MonoDevelop.CSharp.Completion
return result.ParameterIndex;
}
-/*
- #region ICompletionDataFactory implementation
- internal class CompletionDataFactory : ICompletionDataFactory
- {
- internal readonly CSharpCompletionTextEditorExtension ext;
-// readonly CSharpResolver state;
- readonly TypeSystemAstBuilder builder;
+ /*
+ #region ICompletionDataFactory implementation
+ internal class CompletionDataFactory : ICompletionDataFactory
+ {
+ internal readonly CSharpCompletionTextEditorExtension ext;
+ // readonly CSharpResolver state;
+ readonly TypeSystemAstBuilder builder;
- public CSharpCompletionEngine Engine {
- get;
- set;
- }
+ public CSharpCompletionEngine Engine {
+ get;
+ set;
+ }
- public CompletionDataFactory (CSharpCompletionTextEditorExtension ext, CSharpResolver state)
- {
-// this.state = state;
- if (state != null)
- builder = new TypeSystemAstBuilder(state);
- this.ext = ext;
- }
-
- ICompletionData ICompletionDataFactory.CreateEntityCompletionData (IEntity entity)
- {
- return new MemberCompletionData (this, entity, OutputFlags.IncludeGenerics | OutputFlags.HideArrayBrackets | OutputFlags.IncludeParameterName) {
- HideExtensionParameter = true
- };
- }
+ public CompletionDataFactory (CSharpCompletionTextEditorExtension ext, CSharpResolver state)
+ {
+ // this.state = state;
+ if (state != null)
+ builder = new TypeSystemAstBuilder(state);
+ this.ext = ext;
+ }
+
+ ICompletionData ICompletionDataFactory.CreateEntityCompletionData (IEntity entity)
+ {
+ return new MemberCompletionData (this, entity, OutputFlags.IncludeGenerics | OutputFlags.HideArrayBrackets | OutputFlags.IncludeParameterName) {
+ HideExtensionParameter = true
+ };
+ }
- class GenericTooltipCompletionData : CompletionData, IListData
- {
- readonly Func<CSharpCompletionDataList, bool, TooltipInformation> tooltipFunc;
+ class GenericTooltipCompletionData : CompletionData, IListData
+ {
+ readonly Func<CSharpCompletionDataList, bool, TooltipInformation> tooltipFunc;
- #region IListData implementation
+ #region IListData implementation
- CSharpCompletionDataList list;
- public CSharpCompletionDataList List {
- get {
- return list;
- }
- set {
- list = value;
- if (overloads != null) {
- foreach (var overload in overloads.Skip (1)) {
- var ld = overload as IListData;
- if (ld != null)
- ld.List = list;
+ CSharpCompletionDataList list;
+ public CSharpCompletionDataList List {
+ get {
+ return list;
+ }
+ set {
+ list = value;
+ if (overloads != null) {
+ foreach (var overload in overloads.Skip (1)) {
+ var ld = overload as IListData;
+ if (ld != null)
+ ld.List = list;
+ }
+ }
}
}
- }
- }
- #endregion
+ #endregion
- public GenericTooltipCompletionData (Func<CSharpCompletionDataList, bool, TooltipInformation> tooltipFunc, string text, string icon) : base (text, icon)
- {
- this.tooltipFunc = tooltipFunc;
- }
+ public GenericTooltipCompletionData (Func<CSharpCompletionDataList, bool, TooltipInformation> tooltipFunc, string text, string icon) : base (text, icon)
+ {
+ this.tooltipFunc = tooltipFunc;
+ }
- public GenericTooltipCompletionData (Func<CSharpCompletionDataList, bool, TooltipInformation> tooltipFunc, string text, string icon, string description, string completionText) : base (text, icon, description, completionText)
- {
- this.tooltipFunc = tooltipFunc;
- }
+ public GenericTooltipCompletionData (Func<CSharpCompletionDataList, bool, TooltipInformation> tooltipFunc, string text, string icon, string description, string completionText) : base (text, icon, description, completionText)
+ {
+ this.tooltipFunc = tooltipFunc;
+ }
- public override TooltipInformation CreateTooltipInformation (bool smartWrap)
- {
- return tooltipFunc != null ? tooltipFunc (List, smartWrap) : new TooltipInformation ();
- }
+ public override TooltipInformation CreateTooltipInformation (bool smartWrap)
+ {
+ return tooltipFunc != null ? tooltipFunc (List, smartWrap) : new TooltipInformation ();
+ }
- protected List<ICompletionData> overloads;
- public override bool HasOverloads {
- get { return overloads != null && overloads.Count > 0; }
- }
+ protected List<ICompletionData> overloads;
+ public override bool HasOverloads {
+ get { return overloads != null && overloads.Count > 0; }
+ }
- public override IEnumerable<ICompletionData> OverloadedData {
- get {
- return overloads;
- }
- }
+ public override IEnumerable<ICompletionData> OverloadedData {
+ get {
+ return overloads;
+ }
+ }
- public override void AddOverload (ICSharpCode.NRefactory.Completion.ICompletionData data)
- {
- if (overloads == null) {
- overloads = new List<ICompletionData> ();
- overloads.Add (this);
- }
- overloads.Add (data);
- }
+ public override void AddOverload (ICSharpCode.NRefactory.Completion.ICompletionData data)
+ {
+ if (overloads == null) {
+ overloads = new List<ICompletionData> ();
+ overloads.Add (this);
+ }
+ overloads.Add (data);
+ }
+
+ public override void InsertCompletionText (CompletionListWindow window, ref KeyActions ka, KeyDescriptor descriptor)
+ {
+ var currentWord = GetCurrentWord (window);
+ if (CompletionText == "new()" && descriptor.KeyChar == '(') {
+ window.CompletionWidget.SetCompletionText (window.CodeCompletionContext, currentWord, "new");
+ } else {
+ window.CompletionWidget.SetCompletionText (window.CodeCompletionContext, currentWord, CompletionText);
+ }
+ }
- public override void InsertCompletionText (CompletionListWindow window, ref KeyActions ka, KeyDescriptor descriptor)
- {
- var currentWord = GetCurrentWord (window);
- if (CompletionText == "new()" && descriptor.KeyChar == '(') {
- window.CompletionWidget.SetCompletionText (window.CodeCompletionContext, currentWord, "new");
- } else {
- window.CompletionWidget.SetCompletionText (window.CodeCompletionContext, currentWord, CompletionText);
}
- }
- }
+ class LazyGenericTooltipCompletionData : GenericTooltipCompletionData
+ {
+ Lazy<string> displayText;
+ public override string DisplayText {
+ get {
+ return displayText.Value;
+ }
+ }
- class LazyGenericTooltipCompletionData : GenericTooltipCompletionData
- {
- Lazy<string> displayText;
- public override string DisplayText {
- get {
- return displayText.Value;
- }
- }
+ public override string CompletionText {
+ get {
+ return displayText.Value;
+ }
+ }
- public override string CompletionText {
- get {
- return displayText.Value;
+ public LazyGenericTooltipCompletionData (Func<CSharpCompletionDataList, bool, TooltipInformation> tooltipFunc, Lazy<string> displayText, string icon) : base (tooltipFunc, null, icon)
+ {
+ this.displayText = displayText;
+ }
}
- }
- public LazyGenericTooltipCompletionData (Func<CSharpCompletionDataList, bool, TooltipInformation> tooltipFunc, Lazy<string> displayText, string icon) : base (tooltipFunc, null, icon)
- {
- this.displayText = displayText;
- }
- }
+ class TypeCompletionData : LazyGenericTooltipCompletionData, IListData
+ {
+ IType type;
+ CSharpCompletionTextEditorExtension ext;
+ CSharpUnresolvedFile file;
+ ICompilation compilation;
+ // CSharpResolver resolver;
+
+ string IdString {
+ get {
+ return DisplayText + type.TypeParameterCount;
+ }
+ }
- class TypeCompletionData : LazyGenericTooltipCompletionData, IListData
- {
- IType type;
- CSharpCompletionTextEditorExtension ext;
- CSharpUnresolvedFile file;
- ICompilation compilation;
-// CSharpResolver resolver;
-
- string IdString {
- get {
- return DisplayText + type.TypeParameterCount;
- }
- }
+ public override string CompletionText {
+ get {
+ if (type.TypeParameterCount > 0 && !type.IsParameterized)
+ return type.Name;
+ return base.CompletionText;
+ }
+ }
- public override string CompletionText {
- get {
- if (type.TypeParameterCount > 0 && !type.IsParameterized)
- return type.Name;
- return base.CompletionText;
- }
- }
+ public override TooltipInformation CreateTooltipInformation (bool smartWrap)
+ {
+ var def = type.GetDefinition ();
+ var result = def != null ? MemberCompletionData.CreateTooltipInformation (compilation, file, List.Resolver, ext.Editor, ext.FormattingPolicy, def, smartWrap) : new TooltipInformation ();
+ if (ConflictingTypes != null) {
+ var conflicts = new StringBuilder ();
+ var sig = new SignatureMarkupCreator (List.Resolver, ext.FormattingPolicy.CreateOptions ());
+ for (int i = 0; i < ConflictingTypes.Count; i++) {
+ var ct = ConflictingTypes[i];
+ if (i > 0)
+ conflicts.AppendLine (",");
+ // if ((i + 1) % 5 == 0)
+ // conflicts.Append (Environment.NewLine + "\t");
+ conflicts.Append (sig.GetTypeReferenceString (((TypeCompletionData)ct).type));
+ }
+ result.AddCategory ("Type Conflicts", conflicts.ToString ());
+ }
+ return result;
+ }
+
+ public TypeCompletionData (IType type, CSharpCompletionTextEditorExtension ext, Lazy<string> displayText, string icon, bool addConstructors) : base (null, displayText, icon)
+ {
+ this.type = type;
+ this.ext = ext;
+ this.file = ext.CSharpUnresolvedFile;
+ this.compilation = ext.UnresolvedFileCompilation;
- public override TooltipInformation CreateTooltipInformation (bool smartWrap)
- {
- var def = type.GetDefinition ();
- var result = def != null ? MemberCompletionData.CreateTooltipInformation (compilation, file, List.Resolver, ext.Editor, ext.FormattingPolicy, def, smartWrap) : new TooltipInformation ();
- if (ConflictingTypes != null) {
- var conflicts = new StringBuilder ();
- var sig = new SignatureMarkupCreator (List.Resolver, ext.FormattingPolicy.CreateOptions ());
- for (int i = 0; i < ConflictingTypes.Count; i++) {
- var ct = ConflictingTypes[i];
- if (i > 0)
- conflicts.AppendLine (",");
-// if ((i + 1) % 5 == 0)
-// conflicts.Append (Environment.NewLine + "\t");
- conflicts.Append (sig.GetTypeReferenceString (((TypeCompletionData)ct).type));
}
- result.AddCategory ("Type Conflicts", conflicts.ToString ());
- }
- return result;
- }
- public TypeCompletionData (IType type, CSharpCompletionTextEditorExtension ext, Lazy<string> displayText, string icon, bool addConstructors) : base (null, displayText, icon)
- {
- this.type = type;
- this.ext = ext;
- this.file = ext.CSharpUnresolvedFile;
- this.compilation = ext.UnresolvedFileCompilation;
+ Dictionary<string, ICSharpCode.NRefactory.Completion.ICompletionData> addedDatas = new Dictionary<string, ICSharpCode.NRefactory.Completion.ICompletionData> ();
- }
+ List<ICompletionData> ConflictingTypes = null;
- Dictionary<string, ICSharpCode.NRefactory.Completion.ICompletionData> addedDatas = new Dictionary<string, ICSharpCode.NRefactory.Completion.ICompletionData> ();
+ public override void AddOverload (ICSharpCode.NRefactory.Completion.ICompletionData data)
+ {
+ if (overloads == null)
+ addedDatas [IdString] = this;
- List<ICompletionData> ConflictingTypes = null;
+ if (data is TypeCompletionData) {
+ string id = ((TypeCompletionData)data).IdString;
+ ICompletionData oldData;
+ if (addedDatas.TryGetValue (id, out oldData)) {
+ var old = (TypeCompletionData)oldData;
+ if (old.ConflictingTypes == null)
+ old.ConflictingTypes = new List<ICompletionData> ();
+ old.ConflictingTypes.Add (data);
+ return;
+ }
+ addedDatas [id] = data;
+ }
- public override void AddOverload (ICSharpCode.NRefactory.Completion.ICompletionData data)
- {
- if (overloads == null)
- addedDatas [IdString] = this;
-
- if (data is TypeCompletionData) {
- string id = ((TypeCompletionData)data).IdString;
- ICompletionData oldData;
- if (addedDatas.TryGetValue (id, out oldData)) {
- var old = (TypeCompletionData)oldData;
- if (old.ConflictingTypes == null)
- old.ConflictingTypes = new List<ICompletionData> ();
- old.ConflictingTypes.Add (data);
- return;
+ base.AddOverload (data);
}
- addedDatas [id] = data;
+
}
- base.AddOverload (data);
- }
+ ICompletionData ICompletionDataFactory.CreateEntityCompletionData (IEntity entity, string text)
+ {
+ return new GenericTooltipCompletionData ((list, sw) => MemberCompletionData.CreateTooltipInformation (ext, list.Resolver, entity, sw), text, entity.GetStockIcon ());
+ }
- }
+ ICompletionData ICompletionDataFactory.CreateTypeCompletionData (IType type, bool showFullName, bool isInAttributeContext, bool addConstructors)
+ {
+ if (addConstructors) {
+ ICompletionData constructorResult = null;
+ foreach (var ctor in type.GetConstructors ()) {
+ if (constructorResult != null) {
+ constructorResult.AddOverload (((ICompletionDataFactory)this).CreateEntityCompletionData (ctor));
+ } else {
+ constructorResult = ((ICompletionDataFactory)this).CreateEntityCompletionData (ctor);
+ }
+ }
+ return constructorResult;
+ }
- ICompletionData ICompletionDataFactory.CreateEntityCompletionData (IEntity entity, string text)
- {
- return new GenericTooltipCompletionData ((list, sw) => MemberCompletionData.CreateTooltipInformation (ext, list.Resolver, entity, sw), text, entity.GetStockIcon ());
- }
+ Lazy<string> displayText = new Lazy<string> (delegate {
+ string name = showFullName ? builder.ConvertType(type).ToString() : type.Name;
+ if (isInAttributeContext && name.EndsWith("Attribute") && name.Length > "Attribute".Length) {
+ name = name.Substring(0, name.Length - "Attribute".Length);
+ }
+ return name;
+ });
- ICompletionData ICompletionDataFactory.CreateTypeCompletionData (IType type, bool showFullName, bool isInAttributeContext, bool addConstructors)
- {
- if (addConstructors) {
- ICompletionData constructorResult = null;
- foreach (var ctor in type.GetConstructors ()) {
- if (constructorResult != null) {
- constructorResult.AddOverload (((ICompletionDataFactory)this).CreateEntityCompletionData (ctor));
- } else {
- constructorResult = ((ICompletionDataFactory)this).CreateEntityCompletionData (ctor);
- }
+ var result = new TypeCompletionData (type, ext,
+ displayText,
+ type.GetStockIcon (),
+ addConstructors);
+ return result;
}
- return constructorResult;
- }
- Lazy<string> displayText = new Lazy<string> (delegate {
- string name = showFullName ? builder.ConvertType(type).ToString() : type.Name;
- if (isInAttributeContext && name.EndsWith("Attribute") && name.Length > "Attribute".Length) {
- name = name.Substring(0, name.Length - "Attribute".Length);
- }
- return name;
- });
-
- var result = new TypeCompletionData (type, ext,
- displayText,
- type.GetStockIcon (),
- addConstructors);
- return result;
- }
+ ICompletionData ICompletionDataFactory.CreateMemberCompletionData(IType type, IEntity member)
+ {
+ Lazy<string> displayText = new Lazy<string> (delegate {
+ string name = builder.ConvertType(type).ToString();
+ return name + "."+ member.Name;
+ });
- ICompletionData ICompletionDataFactory.CreateMemberCompletionData(IType type, IEntity member)
- {
- Lazy<string> displayText = new Lazy<string> (delegate {
- string name = builder.ConvertType(type).ToString();
- return name + "."+ member.Name;
- });
-
- var result = new LazyGenericTooltipCompletionData (
- (List, sw) => new TooltipInformation (),
- displayText,
- member.GetStockIcon ());
- return result;
- }
+ var result = new LazyGenericTooltipCompletionData (
+ (List, sw) => new TooltipInformation (),
+ displayText,
+ member.GetStockIcon ());
+ return result;
+ }
- ICompletionData ICompletionDataFactory.CreateLiteralCompletionData (string title, string description, string insertText)
- {
- return new GenericTooltipCompletionData ((list, smartWrap) => {
- var sig = new SignatureMarkupCreator (list.Resolver, ext.FormattingPolicy.CreateOptions ());
- sig.BreakLineAfterReturnType = smartWrap;
- return sig.GetKeywordTooltip (title, null);
- }, title, "md-keyword", description, insertText ?? title);
- }
+ ICompletionData ICompletionDataFactory.CreateLiteralCompletionData (string title, string description, string insertText)
+ {
+ return new GenericTooltipCompletionData ((list, smartWrap) => {
+ var sig = new SignatureMarkupCreator (list.Resolver, ext.FormattingPolicy.CreateOptions ());
+ sig.BreakLineAfterReturnType = smartWrap;
+ return sig.GetKeywordTooltip (title, null);
+ }, title, "md-keyword", description, insertText ?? title);
+ }
- class XmlDocCompletionData : CompletionData, IListData
- {
- readonly CSharpCompletionTextEditorExtension ext;
- readonly string title;
+ class XmlDocCompletionData : CompletionData, IListData
+ {
+ readonly CSharpCompletionTextEditorExtension ext;
+ readonly string title;
- #region IListData implementation
+ #region IListData implementation
- CSharpCompletionDataList list;
- public CSharpCompletionDataList List {
- get {
- return list;
- }
- set {
- list = value;
- }
- }
+ CSharpCompletionDataList list;
+ public CSharpCompletionDataList List {
+ get {
+ return list;
+ }
+ set {
+ list = value;
+ }
+ }
- #endregion
+ #endregion
- public XmlDocCompletionData (CSharpCompletionTextEditorExtension ext, string title, string description, string insertText) : base (title, "md-keyword", description, insertText ?? title)
- {
- this.ext = ext;
- this.title = title;
- }
+ public XmlDocCompletionData (CSharpCompletionTextEditorExtension ext, string title, string description, string insertText) : base (title, "md-keyword", description, insertText ?? title)
+ {
+ this.ext = ext;
+ this.title = title;
+ }
- public override TooltipInformation CreateTooltipInformation (bool smartWrap)
- {
- var sig = new SignatureMarkupCreator (List.Resolver, ext.FormattingPolicy.CreateOptions ());
- sig.BreakLineAfterReturnType = smartWrap;
- return sig.GetKeywordTooltip (title, null);
- }
+ public override TooltipInformation CreateTooltipInformation (bool smartWrap)
+ {
+ var sig = new SignatureMarkupCreator (List.Resolver, ext.FormattingPolicy.CreateOptions ());
+ sig.BreakLineAfterReturnType = smartWrap;
+ return sig.GetKeywordTooltip (title, null);
+ }
- public override void InsertCompletionText (CompletionListWindow window, ref KeyActions ka, KeyDescriptor descriptor)
- {
- var currentWord = GetCurrentWord (window);
- var text = CompletionText;
- if (descriptor.KeyChar != '>')
- text += ">";
- window.CompletionWidget.SetCompletionText (window.CodeCompletionContext, currentWord, text);
- }
- }
+ public override void InsertCompletionText (CompletionListWindow window, ref KeyActions ka, KeyDescriptor descriptor)
+ {
+ var currentWord = GetCurrentWord (window);
+ var text = CompletionText;
+ if (descriptor.KeyChar != '>')
+ text += ">";
+ window.CompletionWidget.SetCompletionText (window.CodeCompletionContext, currentWord, text);
+ }
+ }
- ICompletionData ICompletionDataFactory.CreateXmlDocCompletionData (string title, string description, string insertText)
- {
- return new XmlDocCompletionData (ext, title, description, insertText);
- }
+ ICompletionData ICompletionDataFactory.CreateXmlDocCompletionData (string title, string description, string insertText)
+ {
+ return new XmlDocCompletionData (ext, title, description, insertText);
+ }
- ICompletionData ICompletionDataFactory.CreateNamespaceCompletionData (INamespace name)
- {
- return new CompletionData (name.Name, AstStockIcons.Namespace, "", CSharpAmbience.FilterName (name.Name));
- }
+ ICompletionData ICompletionDataFactory.CreateNamespaceCompletionData (INamespace name)
+ {
+ return new CompletionData (name.Name, AstStockIcons.Namespace, "", CSharpAmbience.FilterName (name.Name));
+ }
- ICompletionData ICompletionDataFactory.CreateVariableCompletionData (IVariable variable)
- {
- return new VariableCompletionData (ext, variable);
- }
+ ICompletionData ICompletionDataFactory.CreateVariableCompletionData (IVariable variable)
+ {
+ return new VariableCompletionData (ext, variable);
+ }
- ICompletionData ICompletionDataFactory.CreateVariableCompletionData (ITypeParameter parameter)
- {
- return new CompletionData (parameter.Name, parameter.GetStockIcon ());
- }
+ ICompletionData ICompletionDataFactory.CreateVariableCompletionData (ITypeParameter parameter)
+ {
+ return new CompletionData (parameter.Name, parameter.GetStockIcon ());
+ }
- ICompletionData ICompletionDataFactory.CreateEventCreationCompletionData (string varName, IType delegateType, IEvent evt, string parameterDefinition, IUnresolvedMember currentMember, IUnresolvedTypeDefinition currentType)
- {
- return new EventCreationCompletionData (ext, varName, delegateType, evt, parameterDefinition, currentMember, currentType);
- }
-
- ICompletionData ICompletionDataFactory.CreateNewOverrideCompletionData (int declarationBegin, IUnresolvedTypeDefinition type, IMember m)
- {
- return new NewOverrideCompletionData (ext, declarationBegin, type, m);
- }
- ICompletionData ICompletionDataFactory.CreateNewPartialCompletionData (int declarationBegin, IUnresolvedTypeDefinition type, IUnresolvedMember m)
- {
- var ctx = ext.CSharpUnresolvedFile.GetTypeResolveContext (ext.UnresolvedFileCompilation, ext.Editor.CaretLocation);
- return new NewOverrideCompletionData (ext, declarationBegin, type, m.CreateResolved (ctx));
- }
- IEnumerable<ICompletionData> ICompletionDataFactory.CreateCodeTemplateCompletionData ()
- {
- var result = new CompletionDataList ();
- if (EnableAutoCodeCompletion || IncludeCodeSnippetsInCompletionList.Value) {
- CodeTemplateService.AddCompletionDataForMime ("text/x-csharp", result);
- }
- return result;
- }
-
- IEnumerable<ICompletionData> ICompletionDataFactory.CreatePreProcessorDefinesCompletionData ()
- {
- var project = ext.DocumentContext.Project;
- if (project == null)
- yield break;
- var configuration = project.GetConfiguration (MonoDevelop.Ide.IdeApp.Workspace.ActiveConfiguration) as DotNetProjectConfiguration;
- if (configuration == null)
- yield break;
- foreach (var define in configuration.GetDefineSymbols ())
- yield return new CompletionData (define, "md-keyword");
-
- }
+ ICompletionData ICompletionDataFactory.CreateEventCreationCompletionData (string varName, IType delegateType, IEvent evt, string parameterDefinition, IUnresolvedMember currentMember, IUnresolvedTypeDefinition currentType)
+ {
+ return new EventCreationCompletionData (ext, varName, delegateType, evt, parameterDefinition, currentMember, currentType);
+ }
- class FormatItemCompletionData : CompletionData
- {
- string format;
- string description;
- object example;
+ ICompletionData ICompletionDataFactory.CreateNewOverrideCompletionData (int declarationBegin, IUnresolvedTypeDefinition type, IMember m)
+ {
+ return new NewOverrideCompletionData (ext, declarationBegin, type, m);
+ }
+ ICompletionData ICompletionDataFactory.CreateNewPartialCompletionData (int declarationBegin, IUnresolvedTypeDefinition type, IUnresolvedMember m)
+ {
+ var ctx = ext.CSharpUnresolvedFile.GetTypeResolveContext (ext.UnresolvedFileCompilation, ext.Editor.CaretLocation);
+ return new NewOverrideCompletionData (ext, declarationBegin, type, m.CreateResolved (ctx));
+ }
+ IEnumerable<ICompletionData> ICompletionDataFactory.CreateCodeTemplateCompletionData ()
+ {
+ var result = new CompletionDataList ();
+ if (EnableAutoCodeCompletion || IncludeCodeSnippetsInCompletionList.Value) {
+ CodeTemplateService.AddCompletionDataForMime ("text/x-csharp", result);
+ }
+ return result;
+ }
- public FormatItemCompletionData (string format, string description, object example)
- {
- this.format = format;
- this.description = description;
- this.example = example;
- }
+ IEnumerable<ICompletionData> ICompletionDataFactory.CreatePreProcessorDefinesCompletionData ()
+ {
+ var project = ext.DocumentContext.Project;
+ if (project == null)
+ yield break;
+ var configuration = project.GetConfiguration (MonoDevelop.Ide.IdeApp.Workspace.ActiveConfiguration) as DotNetProjectConfiguration;
+ if (configuration == null)
+ yield break;
+ foreach (var define in configuration.GetDefineSymbols ())
+ yield return new CompletionData (define, "md-keyword");
-
- public override string DisplayText {
- get {
- return format;
}
- }
- public override string GetDisplayDescription (bool isSelected)
- {
- return "- <span foreground=\"darkgray\" size='small'>" + description + "</span>";
- }
+ class FormatItemCompletionData : CompletionData
+ {
+ string format;
+ string description;
+ object example;
+
+ public FormatItemCompletionData (string format, string description, object example)
+ {
+ this.format = format;
+ this.description = description;
+ this.example = example;
+ }
- string rightSideDescription = null;
- public override string GetRightSideDescription (bool isSelected)
- {
- if (rightSideDescription == null) {
- try {
- rightSideDescription = "<span size='small'>" + string.Format ("{0:" +format +"}", example) +"</span>";
- } catch (Exception e) {
- rightSideDescription = "";
- LoggingService.LogError ("Format error.", e);
+
+ public override string DisplayText {
+ get {
+ return format;
+ }
+ }
+ public override string GetDisplayDescription (bool isSelected)
+ {
+ return "- <span foreground=\"darkgray\" size='small'>" + description + "</span>";
}
- }
- return rightSideDescription;
- }
- public override string CompletionText {
- get {
- return format;
+
+ string rightSideDescription = null;
+ public override string GetRightSideDescription (bool isSelected)
+ {
+ if (rightSideDescription == null) {
+ try {
+ rightSideDescription = "<span size='small'>" + string.Format ("{0:" +format +"}", example) +"</span>";
+ } catch (Exception e) {
+ rightSideDescription = "";
+ LoggingService.LogError ("Format error.", e);
+ }
+ }
+ return rightSideDescription;
+ }
+
+ public override string CompletionText {
+ get {
+ return format;
+ }
+ }
+
+ public override int CompareTo (object obj)
+ {
+ return 0;
+ }
}
- }
- public override int CompareTo (object obj)
- {
- return 0;
- }
- }
+ ICompletionData ICompletionDataFactory.CreateFormatItemCompletionData(string format, string description, object example)
+ {
+ return new FormatItemCompletionData (format, description, example);
+ }
- ICompletionData ICompletionDataFactory.CreateFormatItemCompletionData(string format, string description, object example)
- {
- return new FormatItemCompletionData (format, description, example);
- }
-
- #endregion
-*/
-
+ #endregion
+ */
+
#region IDebuggerExpressionResolver implementation
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor.Extension/CompletionTextEditorExtension.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor.Extension/CompletionTextEditorExtension.cs
index 6e53da2cfb..ead731077b 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor.Extension/CompletionTextEditorExtension.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor.Extension/CompletionTextEditorExtension.cs
@@ -150,8 +150,9 @@ namespace MonoDevelop.Ide.Editor.Extension
return res;
// don't complete on block selection
- if (/*!EnableCodeCompletion ||*/ Editor.SelectionMode == MonoDevelop.Ide.Editor.SelectionMode.Block)
+ if (!IdeApp.Preferences.EnableAutoCodeCompletion || Editor.SelectionMode == MonoDevelop.Ide.Editor.SelectionMode.Block)
return res;
+
// Handle code completion
if (descriptor.KeyChar != '\0' && CompletionWidget != null && !CompletionWindowManager.IsVisible) {
completionTokenSrc.Cancel ();
diff --git a/main/tests/UnitTests/MonoDevelop.CSharpBinding/CSharpCompletionTextEditorTests.cs b/main/tests/UnitTests/MonoDevelop.CSharpBinding/CSharpCompletionTextEditorTests.cs
new file mode 100644
index 0000000000..df6488933c
--- /dev/null
+++ b/main/tests/UnitTests/MonoDevelop.CSharpBinding/CSharpCompletionTextEditorTests.cs
@@ -0,0 +1,95 @@
+//
+// CSharpCompletionTextEditorTests.cs
+//
+// Author:
+// Mike Krüger <mikkrg@microsoft.com>
+//
+// Copyright (c) 2017 Microsoft Corporation
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+using System.Threading.Tasks;
+using MonoDevelop.Core;
+using MonoDevelop.CSharp.Completion;
+using MonoDevelop.CSharpBinding.Tests;
+using MonoDevelop.Ide;
+using MonoDevelop.Ide.CodeCompletion;
+using MonoDevelop.Ide.TypeSystem;
+using MonoDevelop.Projects;
+using NUnit.Framework;
+
+namespace MonoDevelop.CSharpBinding
+{
+ [TestFixture]
+ public class CSharpCompletionTextEditorTests : UnitTests.TestBase
+ {
+ [Test]
+ public async Task TestBug58473 ()
+ {
+ var text = @"$";
+ int endPos = text.IndexOf ('$');
+ if (endPos >= 0)
+ text = text.Substring (0, endPos) + text.Substring (endPos + 1);
+
+ var project = Ide.Services.ProjectService.CreateDotNetProject ("C#");
+ project.Name = "test";
+ project.References.Add (MonoDevelop.Projects.ProjectReference.CreateAssemblyReference ("mscorlib"));
+ project.References.Add (MonoDevelop.Projects.ProjectReference.CreateAssemblyReference ("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
+ project.References.Add (MonoDevelop.Projects.ProjectReference.CreateAssemblyReference ("System.Core"));
+
+ project.FileName = "test.csproj";
+ project.Files.Add (new ProjectFile ("/a.cs", BuildAction.Compile));
+
+ var solution = new MonoDevelop.Projects.Solution ();
+ solution.AddConfiguration ("", true);
+ solution.DefaultSolutionFolder.AddItem (project);
+ using (var monitor = new ProgressMonitor ())
+ await TypeSystemService.Load (solution, monitor);
+
+ var tww = new TestWorkbenchWindow ();
+ var content = new TestViewContent ();
+ tww.ViewContent = content;
+ content.ContentName = "/a.cs";
+ content.Data.MimeType = "text/x-csharp";
+ content.Project = project;
+
+
+ content.Text = text;
+ content.CursorPosition = Math.Max (0, endPos);
+ var doc = new MonoDevelop.Ide.Gui.Document (tww);
+ doc.SetProject (project);
+
+ var compExt = new CSharpCompletionTextEditorExtension ();
+ compExt.Initialize (doc.Editor, doc);
+ content.Contents.Add (compExt);
+
+ await doc.UpdateParseDocument ();
+
+ var ctx = new CodeCompletionContext ();
+
+ var tmp = IdeApp.Preferences.EnableAutoCodeCompletion;
+ IdeApp.Preferences.EnableAutoCodeCompletion.Set (false);
+ var list = await compExt.HandleCodeCompletionAsync (ctx, CompletionTriggerInfo.CodeCompletionCommand);
+ Assert.IsNotNull (list);
+ IdeApp.Preferences.EnableAutoCodeCompletion.Set (tmp);
+ project.Dispose ();
+ }
+
+ }
+}
diff --git a/main/tests/UnitTests/UnitTests.csproj b/main/tests/UnitTests/UnitTests.csproj
index fced567dbc..bb41741660 100644
--- a/main/tests/UnitTests/UnitTests.csproj
+++ b/main/tests/UnitTests/UnitTests.csproj
@@ -309,6 +309,7 @@
<Compile Include="MonoDevelop.Core.Assemblies\SystemAssemblyServiceTests.cs" />
<Compile Include="MonoDevelop.Core\StringParserServiceTests.cs" />
<Compile Include="MonoDevelop.CSharpBinding.Refactoring\CSharpFindReferencesProviderTests.cs" />
+ <Compile Include="MonoDevelop.CSharpBinding\CSharpCompletionTextEditorTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Makefile.am" />