diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2011-11-01 12:40:36 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2011-11-01 12:40:36 +0400 |
commit | 546cf4f516aaf55c6622fba0aacdd141a8f20b4c (patch) | |
tree | 2e3319df6160516f98904525566c70a3c2b19ea4 /main/src/addins/CSharpBinding | |
parent | 9228ceb68e45b90ff0a8bed3bd176facb129b8df (diff) |
Fixed "Bug 1760 - [New Resolver] Parameter tooltip not shown for
indexers ".
Diffstat (limited to 'main/src/addins/CSharpBinding')
-rw-r--r-- | main/src/addins/CSharpBinding/CSharpBinding.csproj | 2 | ||||
-rw-r--r-- | main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/CSharpCompletionTextEditorExtension.cs | 7 | ||||
-rw-r--r-- | main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/IndexerParameterDataProvider.cs (renamed from main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/NRefactoryIndexerParameterDataProvider.cs) | 54 |
3 files changed, 35 insertions, 28 deletions
diff --git a/main/src/addins/CSharpBinding/CSharpBinding.csproj b/main/src/addins/CSharpBinding/CSharpBinding.csproj index b9c3dbe282..0f613a275f 100644 --- a/main/src/addins/CSharpBinding/CSharpBinding.csproj +++ b/main/src/addins/CSharpBinding/CSharpBinding.csproj @@ -240,6 +240,7 @@ <Compile Include="MonoDevelop.CSharp.Refactoring\ExtractMethod\VariableLookupVisitor.cs" /> <Compile Include="gtk-gui\MonoDevelop.CSharp.Refactoring.ExtractMethod.ExtractMethodDialog.cs" /> <Compile Include="MonoDevelop.CSharp.Completion\VariableCompletionData.cs" /> + <Compile Include="MonoDevelop.CSharp.Completion\IndexerParameterDataProvider.cs" /> </ItemGroup> <ItemGroup> <None Include="ChangeLog" /> @@ -247,7 +248,6 @@ <None Include="MonoDevelop.CSharp.Refactoring\CSharpRefactorer.cs" /> <None Include="MonoDevelop.CSharp.Completion\NRefactoryTemplateParameterDataProvider.cs" /> <None Include="MonoDevelop.CSharp.Completion\CSharpTextEditorCompletion.cs" /> - <None Include="MonoDevelop.CSharp.Completion\NRefactoryIndexerParameterDataProvider.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/CSharpCompletionTextEditorExtension.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/CSharpCompletionTextEditorExtension.cs index 878c6307c9..99b549ea24 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/CSharpCompletionTextEditorExtension.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/CSharpCompletionTextEditorExtension.cs @@ -473,7 +473,6 @@ namespace MonoDevelop.CSharp.Completion return new EventCreationCompletionData (this, varName, delegateType, evt, parameterDefinition, currentMember, currentType); } - ICompletionData ICompletionDataFactory.CreateNewOverrideCompletionData (int declarationBegin, ITypeDefinition type, IMember m) { return new NewOverrideCompletionData (this, declarationBegin, type, m); @@ -508,6 +507,12 @@ namespace MonoDevelop.CSharp.Completion { return new DelegateDataProvider (this, type); } + + IParameterDataProvider IParameterCompletionDataFactory.CreateIndexerParameterDataProvider (IType type, AstNode resolvedNode) + { + return new IndexerParameterDataProvider (this, type, resolvedNode); + } + #endregion } } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/NRefactoryIndexerParameterDataProvider.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/IndexerParameterDataProvider.cs index 0b9a4db528..2294db2099 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/NRefactoryIndexerParameterDataProvider.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/IndexerParameterDataProvider.cs @@ -39,35 +39,32 @@ using System.Text.RegularExpressions; using ICSharpCode.NRefactory.CSharp; using Mono.TextEditor; using ICSharpCode.NRefactory.TypeSystem; +using ICSharpCode.NRefactory.Completion; +using MonoDevelop.TypeSystem; namespace MonoDevelop.CSharp.Completion { - public class NRefactoryIndexerParameterDataProvider : IParameterDataProvider + public class IndexerParameterDataProvider : IParameterDataProvider { -// IType type; - string resolvedExpression; + AstNode resolvedExpression; static CSharpAmbience ambience = new CSharpAmbience (); + CSharpCompletionTextEditorExtension ext; List<IProperty> indexers; - public NRefactoryIndexerParameterDataProvider (TextEditorData editor, IType type, string resolvedExpression) + public IndexerParameterDataProvider (CSharpCompletionTextEditorExtension ext, IType type, AstNode resolvedExpression) { -// this.editor = editor; -// this.type = type; + this.ext = ext; + this.resolvedExpression = resolvedExpression; - indexers = new List<IProperty> (type.Properties.Where (p => p.IsIndexer && !p.Name.Contains ('.'))); + indexers = new List<IProperty> (type.GetProperties (ext.ctx, p => p.IsIndexer)); } #region IParameterDataProvider implementation - public int GetCurrentParameterIndex (ICompletionWidget widget, CodeCompletionContext ctx) - { - return NRefactoryParameterDataProvider.GetCurrentParameterIndex (widget, ctx.TriggerOffset, 0); - } - public string GetMethodMarkup (int overload, string[] parameterMarkup, int currentParameter) { StringBuilder result = new StringBuilder (); // int curLen = 0; - result.Append (ambience.GetString (indexers[overload].ReturnType, OutputFlags.ClassBrowserEntries)); + result.Append (ambience.GetString (ext.ctx, indexers[overload].ReturnType, OutputFlags.ClassBrowserEntries)); result.Append (' '); result.Append ("<b>"); result.Append (resolvedExpression); @@ -81,12 +78,12 @@ namespace MonoDevelop.CSharp.Completion parameterCount++; } result.Append (']'); - IParameter curParameter = currentParameter >= 0 && currentParameter < indexers[overload].Parameters.Count ? indexers[overload].Parameters[currentParameter] : null; + var curParameter = currentParameter >= 0 && currentParameter < indexers[overload].Parameters.Count ? indexers[overload].Parameters[currentParameter] : null; if (curParameter != null) { string docText = AmbienceService.GetDocumentation (indexers[overload]); if (!string.IsNullOrEmpty (docText)) { - Regex paramRegex = new Regex ("(\\<param\\s+name\\s*=\\s*\"" + curParameter.Name + "\"\\s*\\>.*?\\</param\\>)", RegexOptions.Compiled); - Match match = paramRegex.Match (docText); + var paramRegex = new Regex ("(\\<param\\s+name\\s*=\\s*\"" + curParameter.Name + "\"\\s*\\>.*?\\</param\\>)", RegexOptions.Compiled); + var match = paramRegex.Match (docText); if (match.Success) { result.AppendLine (); string text = match.Groups[1].Value; @@ -99,24 +96,29 @@ namespace MonoDevelop.CSharp.Completion } } - return result.ToString (); - } - + return result.ToString (); } + public string GetParameterMarkup (int overload, int paramIndex) { - return ambience.GetString (indexers[overload].Parameters[paramIndex], OutputFlags.IncludeParameters | OutputFlags.IncludeParameterName | OutputFlags.IncludeReturnType | OutputFlags.IncludeModifiers | OutputFlags.HighlightName); + var indexer = indexers[overload]; + + if (paramIndex < 0 || paramIndex >= indexer.Parameters.Count) + return ""; + + return ambience.GetString (ext.ctx, indexer, indexer.Parameters [paramIndex], OutputFlags.AssemblyBrowserDescription | OutputFlags.HideExtensionsParameter | OutputFlags.IncludeGenerics | OutputFlags.IncludeModifiers | OutputFlags.IncludeParameterName | OutputFlags.HighlightName); } - + public int GetParameterCount (int overload) { - if (overload < 0 || overload >= OverloadCount) - return 0; - return indexers[overload].Parameters.Count; + if (overload >= OverloadCount) + return -1; + var indexer = indexers[overload]; + return indexer != null && indexer.Parameters != null ? indexer.Parameters.Count : 0; } - + public int OverloadCount { get { - return indexers.Count; + return indexers != null ? indexers.Count : 0; } } #endregion |