public virtual int GuessBestMethodOverload(ParameterHintingResult provider, int currentOverload) { int cparam = GetCurrentParameterIndex(provider.StartOffset, default(CancellationToken)).Result; var currentHintingData = provider [currentOverload]; if (cparam > currentHintingData.ParameterCount && !currentHintingData.IsParameterListAllowed) { // Look for an overload which has more parameters int bestOverload = -1; int bestParamCount = int.MaxValue; for (int n = 0; n < provider.Count; n++) { int pc = provider[n].ParameterCount; if (pc < bestParamCount && pc >= cparam) { bestOverload = n; bestParamCount = pc; } } if (bestOverload == -1) { for (int n = 0; n < provider.Count; n++) { if (provider[n].IsParameterListAllowed) { bestOverload = n; break; } } } return(bestOverload); } return(-1); }
public virtual async Task <int> GuessBestMethodOverload(ParameterHintingResult provider, int currentOverload, System.Threading.CancellationToken token) { var currentHintingData = provider [currentOverload]; int cparam = await GetCurrentParameterIndex(provider.StartOffset, token).ConfigureAwait(false); if (cparam > currentHintingData.ParameterCount && !currentHintingData.IsParameterListAllowed) { // Look for an overload which has more parameters int bestOverload = -1; int bestParamCount = int.MaxValue; for (int n = 0; n < provider.Count; n++) { int pc = provider[n].ParameterCount; if (pc < bestParamCount && pc >= cparam) { bestOverload = n; bestParamCount = pc; } } if (bestOverload == -1) { for (int n = 0; n < provider.Count; n++) { if (provider[n].IsParameterListAllowed) { bestOverload = n; break; } } } return(bestOverload); } return(-1); }
public override int GuessBestMethodOverload(ParameterHintingResult provider, int currentOverload) { var projectedExtension = GetCurrentExtension(); if (projectedExtension == null) { return(-1); } return(projectedExtension.GuessBestMethodOverload(provider, currentOverload)); }
public override Task <int> GuessBestMethodOverload(ParameterHintingResult provider, int currentOverload, System.Threading.CancellationToken token) { var projectedExtension = GetCurrentExtension(); if (projectedExtension == null) { return(Task.FromResult(-1)); } return(projectedExtension.GuessBestMethodOverload(provider, currentOverload, token)); }
public virtual async void RunParameterCompletionCommand() { if (Editor.SelectionMode == SelectionMode.Block || CompletionWidget == null) { return; } ParameterHintingResult cp = null; int cpos = Editor.CaretOffset; CodeCompletionContext ctx = CompletionWidget.CreateCodeCompletionContext(cpos); cp = await ParameterCompletionCommand(ctx); if (cp != null) { ParameterInformationWindowManager.ShowWindow(this, CompletionWidget, ctx, cp); ParameterInformationWindowManager.PostProcessKeyEvent(this, CompletionWidget, KeyDescriptor.FromGtk(Gdk.Key.F, 'f', Gdk.ModifierType.None)); } }
public async void ShowParameterInfo (ParameterHintingResult provider, int overload, int _currentParam, int maxSize) { if (provider == null) throw new ArgumentNullException ("provider"); int numParams = System.Math.Max (0, provider [overload].ParameterCount); var currentParam = System.Math.Min (_currentParam, numParams - 1); if (numParams > 0 && currentParam < 0) currentParam = 0; if (lastParam == currentParam && (currentTooltipInformation != null)) { return; } lastParam = currentParam; var parameterHintingData = (ParameterHintingData)provider [overload]; ResetTooltipInformation (); ClearDescriptions (); if (ext == null) { // ext == null means HideParameterInfo was called aka. we are not in valid context to display tooltip anymore lastParam = -2; return; } var ct = new CancellationTokenSource (); try { cancellationTokenSource = ct; currentTooltipInformation = await parameterHintingData.CreateTooltipInformation (ext.Editor, ext.DocumentContext, currentParam, false, ct.Token); } catch (Exception ex) { if (!(ex is TaskCanceledException)) LoggingService.LogError ("Error while getting tooltip information", ex); return; } if (ct.IsCancellationRequested) return; cancellationTokenSource = null; Theme.NumPages = provider.Count; Theme.CurrentPage = overload; if (provider.Count > 1) { Theme.DrawPager = true; Theme.PagerVertical = true; } ShowTooltipInfo (); }
public virtual async Task<int> GuessBestMethodOverload (ParameterHintingResult provider, int currentOverload, System.Threading.CancellationToken token) { var currentHintingData = provider [currentOverload]; int cparam = await GetCurrentParameterIndex (provider.StartOffset, token).ConfigureAwait (false); if (cparam > currentHintingData.ParameterCount && !currentHintingData.IsParameterListAllowed) { // Look for an overload which has more parameters int bestOverload = -1; int bestParamCount = int.MaxValue; for (int n=0; n<provider.Count; n++) { int pc = provider[n].ParameterCount; if (pc < bestParamCount && pc >= cparam) { bestOverload = n; bestParamCount = pc; } } if (bestOverload == -1) { for (int n=0; n<provider.Count; n++) { if (provider[n].IsParameterListAllowed) { bestOverload = n; break; } } } return bestOverload; } return -1; }
public override int GuessBestMethodOverload (ParameterHintingResult provider, int currentOverload) { var projectedExtension = GetCurrentExtension (); if (projectedExtension == null) return -1; return projectedExtension.GuessBestMethodOverload (provider, currentOverload); }
ParameterHintingResult HandleInvocationExpression(SemanticModel semanticModel, InvocationExpressionSyntax node, CancellationToken cancellationToken) { var info = semanticModel.GetSymbolInfo (node, cancellationToken); var result = new ParameterHintingResult(node.SpanStart); var targetTypeInfo = semanticModel.GetTypeInfo (node.Expression); if (targetTypeInfo.Type != null && targetTypeInfo.Type.TypeKind == TypeKind.Delegate) { result.AddData (factory.CreateMethodDataProvider (targetTypeInfo.Type.GetDelegateInvokeMethod ())); return result; } var within = semanticModel.GetEnclosingNamedTypeOrAssembly(node.SpanStart, cancellationToken); ITypeSymbol type; string name = null; bool staticLookup = false; var ma = node.Expression as MemberAccessExpressionSyntax; var mb = node.Expression as MemberBindingExpressionSyntax; if (mb != null) { info = semanticModel.GetSymbolInfo (mb, cancellationToken); type = (info.Symbol ?? info.CandidateSymbols.FirstOrDefault ())?.ContainingType; name = mb.Name.Identifier.ValueText; } else if (ma != null) { staticLookup = semanticModel.GetSymbolInfo (ma.Expression).Symbol is ITypeSymbol; type = semanticModel.GetTypeInfo (ma.Expression).Type; name = info.Symbol?.Name ?? ma.Name.Identifier.ValueText; } else { type = within as ITypeSymbol; name = info.Symbol?.Name ?? node.Expression.ToString (); var sym = semanticModel.GetEnclosingSymbol (node.SpanStart, cancellationToken); staticLookup = sym.IsStatic; } var addedMethods = new List<IMethodSymbol> (); var filterMethod = new HashSet<IMethodSymbol> (); for (;type != null; type = type.BaseType) { foreach (var method in type.GetMembers ().OfType<IMethodSymbol> ().Concat (GetExtensionMethods(semanticModel, type, node, cancellationToken)).Where (m => m.Name == name)) { if (staticLookup && !method.IsStatic) continue; if (method.OverriddenMethod != null) filterMethod.Add (method.OverriddenMethod); if (filterMethod.Contains (method)) continue; if (addedMethods.Any (added => SignatureComparer.HaveSameSignature (method, added, true))) continue; if (method.IsAccessibleWithin (within)) { if (info.Symbol != null) { var smethod = (IMethodSymbol)info.Symbol; if (smethod != null && smethod.OriginalDefinition == method) { continue; } } addedMethods.Add (method); result.AddData (factory.CreateMethodDataProvider (method)); } } } if (info.Symbol != null && !addedMethods.Contains (info.Symbol)) { if (!staticLookup || info.Symbol.IsStatic) result.AddData (factory.CreateMethodDataProvider ((IMethodSymbol)info.Symbol)); } return result; }
ParameterHintingResult HandleObjectCreationExpression (SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken) { // var info = semanticModel.GetSymbolInfo(node, cancellationToken); var result = new ParameterHintingResult(node.SpanStart); var within = semanticModel.GetEnclosingNamedTypeOrAssembly(node.SpanStart, cancellationToken); var targetTypeInfo = semanticModel.GetTypeInfo (node); if (targetTypeInfo.Type != null) { foreach (IMethodSymbol c in targetTypeInfo.Type.GetMembers().OfType<IMethodSymbol>().Where(m => m.MethodKind == MethodKind.Constructor)) { if (c.IsAccessibleWithin (within)) { result.AddData(factory.CreateConstructorProvider(c)); } } } return result; }
ParameterHintingResult HandleElementAccessExpression(SemanticModel semanticModel, ElementAccessExpressionSyntax node, CancellationToken cancellationToken) { var within = semanticModel.GetEnclosingNamedTypeOrAssembly(node.SpanStart, cancellationToken); var targetTypeInfo = semanticModel.GetTypeInfo (node.Expression); ITypeSymbol type = targetTypeInfo.Type; if (type == null) return ParameterHintingResult.Empty; var result = new ParameterHintingResult(node.SpanStart); if (type.TypeKind == TypeKind.Array) { result.AddData (factory.CreateArrayDataProvider ((IArrayTypeSymbol)type)); return result; } var addedProperties = new List<IPropertySymbol> (); for (;type != null; type = type.BaseType) { foreach (var indexer in type.GetMembers ().OfType<IPropertySymbol> ().Where (p => p.IsIndexer)) { if (addedProperties.Any (added => SignatureComparer.HaveSameSignature (indexer, added, true))) continue; if (indexer.IsAccessibleWithin (within)) { addedProperties.Add (indexer); result.AddData (factory.CreateIndexerParameterDataProvider (indexer, node)); } } } return result; }
ParameterHintingResult HandleConstructorInitializer(SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken) { var info = semanticModel.GetSymbolInfo(node, cancellationToken); var result = new ParameterHintingResult(node.SpanStart); var resolvedMethod = info.Symbol as IMethodSymbol; if (resolvedMethod != null) result.AddData(factory.CreateConstructorProvider(resolvedMethod)); result.AddRange(info.CandidateSymbols.OfType<IMethodSymbol>().Select (m => factory.CreateConstructorProvider(m))); return result; }
ParameterHintingResult HandleAttribute(SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken) { var info = semanticModel.GetSymbolInfo(node, cancellationToken); var result = new ParameterHintingResult(node.SpanStart); var resolvedMethod = info.Symbol as IMethodSymbol; if (resolvedMethod != null) { foreach (var c in resolvedMethod.ContainingType.GetMembers ().OfType<IMethodSymbol> ().Where (m => m.MethodKind == MethodKind.Constructor)) { result.AddData (factory.CreateConstructorProvider (c)); } } else { result.AddRange (info.CandidateSymbols.OfType<IMethodSymbol> ().Select (m => factory.CreateConstructorProvider (m))); } return result; }
ParameterHintingResult HandleTypeParameterCase(SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken) { var result = new ParameterHintingResult(node.SpanStart); string typeName; var gns = node as GenericNameSyntax; if (gns != null) { typeName = gns.Identifier.ToString (); } else { typeName = node.ToString (); } foreach (var cand in semanticModel.LookupSymbols (node.SpanStart).OfType<INamedTypeSymbol> ()) { if (cand.TypeParameters.Length == 0) continue; if (cand.Name == typeName || cand.GetFullName () == typeName) result.AddData(factory.CreateTypeParameterDataProvider(cand)); } if (result.Count == 0) { foreach (var cand in semanticModel.LookupSymbols (node.SpanStart).OfType<IMethodSymbol> ()) { if (cand.TypeParameters.Length == 0) continue; if (cand.Name == typeName) result.AddData (factory.CreateTypeParameterDataProvider (cand)); } } return result; }
internal static void ShowWindow (CompletionTextEditorExtension ext, ICompletionWidget widget, CodeCompletionContext ctx, ParameterHintingResult provider) { if (provider.Count == 0) return; // There can be several method parameter lists open at the same time, so // they have to be queued. The last one of queue is the one being shown // in the information window. MethodData md = new MethodData (); md.MethodProvider = provider; md.CurrentOverload = 0; md.CompletionContext = ctx; currentMethodGroup = md; UpdateOverload (ext, widget); UpdateWindow (ext, widget); }
public virtual int GuessBestMethodOverload (ParameterHintingResult provider, int currentOverload) { int cparam = GetCurrentParameterIndex (provider.StartOffset, default(CancellationToken)).Result; var currentHintingData = provider [currentOverload]; if (cparam > currentHintingData.ParameterCount && !currentHintingData.IsParameterListAllowed) { // Look for an overload which has more parameters int bestOverload = -1; int bestParamCount = int.MaxValue; for (int n=0; n<provider.Count; n++) { int pc = provider[n].ParameterCount; if (pc < bestParamCount && pc >= cparam) { bestOverload = n; bestParamCount = pc; } } if (bestOverload == -1) { for (int n=0; n<provider.Count; n++) { if (provider[n].IsParameterListAllowed) { bestOverload = n; break; } } } return bestOverload; } return -1; }
public override Task<int> GuessBestMethodOverload (ParameterHintingResult provider, int currentOverload, System.Threading.CancellationToken token) { var projectedExtension = GetCurrentExtension (); if (projectedExtension == null) return Task.FromResult (-1); return projectedExtension.GuessBestMethodOverload (provider, currentOverload, token); }