protected override bool AddLookupItems(CSharpCodeCompletionContext context, IItemsCollector collector) { var nodeInFile = context.NodeInFile; var tokenType = nodeInFile.GetTokenType(); if (tokenType == null || !tokenType.IsIdentifier) { return(false); } var project = context.BasicContext.SourceFile.GetProject(); if (project == null || !project.IsNukeProject()) { return(false); } var psiService = context.PsiModule.GetPsiServices(); var symbolScope = psiService.Symbols.GetSymbolScope(LibrarySymbolScope.REFERENCED, caseSensitive: false); foreach (var taskMethod in GetTaskMethods(symbolScope)) { collector.Add(CreateLookoutItem(context, taskMethod.Key, taskMethod.Value, skipGenericArguments: true)); } return(true); }
protected override bool AddLookupItems(CSharpCodeCompletionContext context, IItemsCollector collector) { var rangeMarker = context.BasicContext.CaretDocumentOffset.CreateRangeMarker(); foreach (var kc in KeyUtilities.EnumerateKeyContainers("Microsoft Strong Cryptographic Provider")) { var cspParameters = new CspParameters { KeyContainerName = kc, Flags = CspProviderFlags.UseMachineKeyStore }; using (var prov = new RSACryptoServiceProvider(cspParameters)) { if (!prov.CspKeyContainerInfo.Exportable) { continue; } var kp = new StrongNameKeyPair(prov.ExportCspBlob(true)); if (kp.PublicKey.Length != 160) { continue; } var lookupItem = new SimpleTextLookupItem($"\"{kc}\"", rangeMarker); lookupItem.InitializeRanges(context.EvaluateRanges(), context.BasicContext); collector.Add(lookupItem); } } return(true); }
// So, the behaviour we want is this: // 1. Hide all existing *ng-* attributes from the default list // 2. Get prefix // 3. For single completion: // If no prefix, just display abbreviations // else if prefix is one of the abbreviations (exact match), add all items for that abbreviation // (e.g. "ng-" should show all "ng-*" items) // else if prefix pattern matches an abbreviation (inc. last char), add all items for that abbreviation // (e.g. "dng-" should show all "data-ng-*" items) // else if prefix pattern matches an abrreviation, add those abbreviations // (e.g. "dng" should match "data-ng-" abbreviation. "ng" should match "data-ng-", "ng-" and "x-ng-") // else if prefix pattern matches an item minus abbreviation, add those items for all abbreviations // (e.g. "controller" should match "data-ng-controller", "ng-controller", "x-ng-controller") // else if prefix pattern matches item with abrbeviation, add just those items // (e.g. "ngc" matches "ng-controller" but not "data-ng-controller". "dnc" matches "data-ng-controller") // 4. Double completion... protected override bool AddLookupItems(HtmlCodeCompletionContext context, IItemsCollector collector) { var completionPrefix = GetCompletionPrefix(context); var matcher = string.IsNullOrEmpty(completionPrefix) ? null : LookupUtil.CreateMatcher(completionPrefix, context.BasicContext.IdentifierMatchingStyle); if (IsSingleCompletion(context)) { // Return value is ignored. Just a cute way of calling each of these in turn without loads of if statements // ReSharper disable once UnusedVariable var ignored = TryAddAllAbbreviations(completionPrefix, context, collector) || TryAddAllItemsForExactAbbreviation(completionPrefix, context, collector) || TryAddAllItemsForMatchedAbbreviation(matcher, context, collector) || TryAddMatchingAbbreviations(matcher, context, collector) || TryAddMatchingUnprefixedItems(completionPrefix, context, collector) || TryAddMatchingItemsForMatchedAbbreviation(completionPrefix, context, collector); } else if (IsDoubleCompletion(context)) { foreach (var abbreviation in Abbreviations) { AddAllItemsForSpecificAbbreviation(abbreviation, context, collector); } } // Return true so ReSharper knows we're dynamic return(true); }
protected override bool AddLookupItems(HtmlCodeCompletionContext context, IItemsCollector collector) { var elementProvider = context.BasicContext.Solution.GetComponent <AngularJsHtmlElementsProvider>(); var matcher = GetIdentifierMatcher(context.BasicContext, context.Ranges); var symbolTable = elementProvider.GetAllTagsSymbolTable(); symbolTable.ForAllSymbolInfos(info => { var declaredElement = info.GetDeclaredElement(); if (declaredElement.IsSynthetic() || !(declaredElement is IAngularJsDeclaredElement) && !matcher.Matches(context.GetDisplayNameByDeclaredElement(declaredElement))) { return; } var lookupItem = context.CreateDeclaredElementLookupItem(info.ShortName, declaredElement); if (lookupItem.IsObsolete) { lookupItem.Placement.Relevance |= (long)HtmlLookupItemRelevance.ObsoleteItem; collector.Add(lookupItem.WithLowSelectionPriority()); } else { lookupItem.Placement.Relevance |= (long)HtmlLookupItemRelevance.Item; collector.Add(lookupItem); } }); return(true); }
protected override bool AddLookupItems(T4CodeCompletionContext context, IItemsCollector collector) { ITreeNode node = context.BasicContext.File.FindNodeAt(context.BasicContext.SelectedTreeRange); Assertion.AssertNotNull(node, "node == null"); var ranges = context.BasicContext.GetRanges(node); collector.AddRanges(ranges); var attribute = node.GetContainingNode <IT4DirectiveAttribute>(); Assertion.AssertNotNull(attribute, "attribute != null"); var directive = attribute.GetContainingNode <IT4Directive>(); Assertion.AssertNotNull(directive, "directive != null"); DirectiveInfo directiveInfo = _directiveInfoManager.GetDirectiveByName(directive.GetName()); DirectiveAttributeInfo attributeInfo = directiveInfo?.GetAttributeByName(attribute.GetName()); if (attributeInfo == null) { return(false); } foreach (string intellisenseValue in attributeInfo.IntelliSenseValues) { var item = new TextLookupItem(intellisenseValue); item.InitializeRanges(ranges, context.BasicContext); collector.Add(item); } return(true); }
private static void AddAllAbbreviations(HtmlCodeCompletionContext context, IItemsCollector collector) { foreach (var abbreviation in Abbreviations) { AddAbbreviation(context, collector, abbreviation); } }
private static void WrapExistingItems(IItemsCollector collector, CoReProposal[] proposals) { // ToList is necessary to avoid ConcurrentModificationExceptions foreach (var candidate in collector.Items.ToList()) { ConditionallyAddWrappedLookupItem(collector, proposals, candidate); } }
protected override bool AddLookupItems(CSharpCodeCompletionContext context, IItemsCollector collector) { var ranges = context.CompletionRanges; IEnumerable <string> completionItems = null; ICSharpLiteralExpression argumentLiteral = null; // scene completion if (IsSpecificArgumentInSpecificMethod(context, out argumentLiteral, IsLoadSceneMethod, IsCorrespondingArgument("sceneName"))) { var cache = context.NodeInFile.GetSolution().TryGetComponent <UnityProjectSettingsCache>(); completionItems = cache.GetAllPossibleSceneNames(); } // tag completion, tag == "..." else if (IsTagEquality(context, out argumentLiteral)) { var cache = context.NodeInFile.GetSolution().TryGetComponent <UnityProjectSettingsCache>(); completionItems = cache.GetAllTags(); } //// tag completion, CompareTag("...") else if (IsSpecificArgumentInSpecificMethod(context, out argumentLiteral, IsCompareTagMethod, IsCorrespondingArgument("tag"))) { var cache = context.NodeInFile.GetSolution().TryGetComponent <UnityProjectSettingsCache>(); completionItems = cache.GetAllTags(); } // layer completion else if (IsSpecificArgumentInSpecificMethod(context, out argumentLiteral, IsLayerMaskNameToLayer, IsCorrespondingArgument("layerName")) || IsSpecificArgumentInSpecificMethod(context, out argumentLiteral, IsLayerMaskGetMask, (_, __) => true)) { var cache = context.NodeInFile.GetSolution().TryGetComponent <UnityProjectSettingsCache>(); completionItems = cache.GetAllLayers(); } // input completion else if (IsSpecificArgumentInSpecificMethod(context, out argumentLiteral, IsInputButtonMethod, IsCorrespondingArgument("buttonName")) || IsSpecificArgumentInSpecificMethod(context, out argumentLiteral, IsInputAxisMethod, IsCorrespondingArgument("axisName"))) { var cache = context.NodeInFile.GetSolution().TryGetComponent <UnityProjectSettingsCache>(); completionItems = cache.GetAllInput(); } var any = false; if (argumentLiteral != null) { var offset = argumentLiteral.GetDocumentRange().EndOffset; ranges = ranges.WithInsertRange(ranges.InsertRange.SetEndTo(offset)).WithReplaceRange(ranges.ReplaceRange.SetEndTo(offset)); } if (completionItems != null) { foreach (var sceneName in completionItems) { any = true; var item = new StringLiteralItem($"\"{sceneName}\""); item.InitializeRanges(ranges, context.BasicContext); collector.Add(item); } } return(any); }
private bool TryAddAllAbbreviations(string prefix, HtmlCodeCompletionContext context, IItemsCollector collector) { if (HasNoPrefix(prefix)) { AddAllAbbreviations(context, collector); return(true); } return(false); }
protected override bool AddLookupItems(ContextInDocComment context, IItemsCollector collector) { foreach (var lookupItem in myLookupItems) { lookupItem.InitializeRanges(context.TextLookupRanges, context.BasicContext); collector.Add(lookupItem); } return(true); }
protected override bool AddLookupItems(CSharpCodeCompletionContext context, IItemsCollector collector) { ContextAnalysis.Analyse( context.NodeInFile, null, _logger, OnSuccess, delegate { }, delegate { }); return(false); }
protected override bool AddLookupItems(CSharpCodeCompletionContext context, IItemsCollector collector) { var ranges = context.CompletionRanges; IEnumerable <string> completionItems = null; // scene completion if (IsSpecificArgumentInSpecificMethod(context, out var argumentLiteral, IsLoadSceneMethod, IsCorrespondingArgument("sceneName"))) { var cache = context.NodeInFile.GetSolution().GetComponent <UnityProjectSettingsCache>(); completionItems = cache.GetAllPossibleSceneNames(); } // tag completion, tag == "..."
private static void AddLookup(CSharpCodeCompletionContext context, IItemsCollector collector, string proposedCompletion, int?offset = null) { var textLookupItem = CSharpLookupItemFactory.Instance.CreateKeywordLookupItem(context, proposedCompletion, TailType.None, PsiSymbolsThemedIcons.Method.Id); if (offset != null) { textLookupItem.SetInsertCaretOffset(offset.Value); textLookupItem.SetReplaceCaretOffset(offset.Value); } textLookupItem.SetTopPriority(); collector.Add(textLookupItem); }
protected override bool AddLookupItems(CSharpCodeCompletionContext context, IItemsCollector collector) { var candidateExistingElements = new List <ISymbolInfo>(); var table = GetSymbolTable(context); table?.ForAllSymbolInfos(info => { var declaredElement = info.GetDeclaredElement(); var type = declaredElement.Type(); if (type != null) { if (type.GetClassType().ConvertToString() == "Class:Moq.Mock`1") { IType typeParameter = TypesUtil.GetTypeArgumentValue(type, 0); if (typeParameter != null && context.ExpectedTypesContext != null && context.ExpectedTypesContext.ExpectedITypes != null && context.ExpectedTypesContext.ExpectedITypes.Select(x => x.Type).Where(x => x != null).Any(x => typeParameter.IsExplicitlyConvertibleTo(x, ClrPredefinedTypeConversionRule.INSTANCE))) { candidateExistingElements.Add(info); } } } }); foreach (var candidateExistingElement in candidateExistingElements) { var proposedCompletion = candidateExistingElement.ShortName + ".Object"; var lookupItem = GetLookupItem(context, proposedCompletion); collector.Add(lookupItem); } if (context.ExpectedTypesContext != null) { foreach (var expectedType in context.ExpectedTypesContext.ExpectedITypes) { if (expectedType.Type == null) { continue; } if (expectedType.Type.IsInterfaceType()) { string typeName = expectedType.Type.GetPresentableName(CSharpLanguage.Instance); var proposedCompletion = "new Mock<" + typeName + ">().Object"; var lookupItem = GetLookupItem(context, proposedCompletion); collector.Add(lookupItem); } } } return(true); }
public static void PutMoqCompleteAtTop(IItemsCollector collector) { var moqComplete = collector.Items.Where(x => x.Placement.OrderString == LookupItemExtensions.MoqCompleteOrderString).ToList(); var otherItems = collector.Items.Where(x => x.Placement.OrderString != LookupItemExtensions.MoqCompleteOrderString).ToList(); if (moqComplete.Any()) { otherItems.ForEach(x => { var rank = (byte)(x.Placement.Rank == 255 ? 255 : x.Placement.Rank + 1); x.WithLowSelectionPriority(); x.Placement.Rank = rank; }); } }
private static void AddToCollector(CSharpCodeCompletionContext context, IItemsCollector collector, IReferenceName referenceName, NamedElementKinds elementKinds, ScopeKind localSelfScoped) { var referenceNameResolveResult = referenceName.Reference.Resolve(); var referencedElementAsString = referenceNameResolveResult.DeclaredElement.ConvertToString(); if (referencedElementAsString == "Class:Moq.Mock`1") { var typeArgumentList = referenceName.TypeArgumentList; var typeArguments = typeArgumentList.TypeArguments; if (typeArguments.Count == 1) { var typeArgument = typeArguments[0]; var scalarType = typeArgument.GetScalarType(); if (scalarType == null) { return; } var genericTypeResolveResult = scalarType.Resolve(); var namingManager = typeArgument.GetPsiServices().Naming; var suggestionOptions = new SuggestionOptions(); string proposedName; if (genericTypeResolveResult.IsEmpty) { proposedName = namingManager.Suggestion.GetDerivedName(typeArgument.GetPresentableName(CSharpLanguage.Instance), elementKinds, localSelfScoped, CSharpLanguage.Instance, suggestionOptions, referenceName.GetSourceFile()); } else { proposedName = namingManager.Suggestion.GetDerivedName(genericTypeResolveResult.DeclaredElement, elementKinds, localSelfScoped, CSharpLanguage.Instance, suggestionOptions, referenceName.GetSourceFile()); } var textLookupItem = new TextLookupItem(proposedName); textLookupItem.InitializeRanges(context.CompletionRanges, context.BasicContext); textLookupItem.SetTopPriority(); collector.Add(textLookupItem); var textLookupItem2 = new TextLookupItem(proposedName + "Mock"); textLookupItem2.InitializeRanges(context.CompletionRanges, context.BasicContext); textLookupItem2.SetTopPriority(); collector.Add(textLookupItem2); } } }
protected override bool AddLookupItems(CSharpCodeCompletionContext context, IItemsCollector collector) { Action <Context> onSuccess = kaveContext => { // TODO NameUpdate: untested addition (try/catch) try { _currentQuery = _queryGen.Extract(kaveContext); } catch (Exception e) { _logger.Error(e, "error while extracting query"); _currentQuery = null; } if (_currentQuery != null && IsAvailable()) { var rec = LoadIfAvailable(); if (rec != null) { try { var proposals = rec.Query(_currentQuery); WrapExistingItems(collector, proposals); } catch (AssertException e) { _logger.Error(e); } } else { _logger.Info("no recommender model found for {0}", _currentQuery.type); } } }; ContextAnalysis.Analyse( context.NodeInFile, null, _logger, onSuccess, delegate { }, delegate { }); return(base.AddLookupItems(context, collector)); }
protected override bool AddLookupItems(CSharpCodeCompletionContext context, IItemsCollector collector) { var lookupItems = _settingsProvider.GetJsonSettingsLookupItems(context, JsonSettingType.All); if (!lookupItems.Any()) { return(false); } foreach (var lookupItem in lookupItems) { collector.Add(lookupItem); } return(true); }
private static void RemoveItemsToAbbreviate(IItemsCollector collector) { // Remove all items that begin with a prefix that we're abbreviating, unless they've // got our key to say they've been explicitly added var toRemove = from item in collector.Items let unwrappedItem = GetDeclaredElementLookupItem(item) where unwrappedItem != null && unwrappedItem.GetData(ExplicitlyAddedKey) == null && StartsWithAbbreviation(unwrappedItem.PreferredDeclaredElement.Element.ShortName) select unwrappedItem; foreach (var item in toRemove.ToList()) { collector.Remove(item); } }
protected override bool AddLookupItems(T4CodeCompletionContext context, IItemsCollector collector) { ITreeNode node = context.BasicContext.File.FindNodeAt(context.BasicContext.SelectedTreeRange); Assertion.AssertNotNull(node, "node == null"); var ranges = context.BasicContext.GetRanges(node); foreach (string directiveName in T4DirectiveInfoManager.AllDirectives.Select(di => di.Name)) { var item = new TextLookupItem(directiveName, T4Entity.Id); item.InitializeRanges(ranges, context.BasicContext); collector.Add(item); } return(true); }
protected override bool AddLookupItems(CSharpCodeCompletionContext context, IItemsCollector collector) { var identifier = context.TerminatedContext.TreeNode as IIdentifier; var expression = identifier.GetParentSafe <IReferenceExpression>(); if (expression == null) { return(false); } if (!(expression.ConditionalQualifier is IInvocationExpression invocation)) { return(false); } var solution = context.BasicContext.Solution; var methodIdentifier = solution.GetComponent <IMoqMethodIdentifier>(); if (methodIdentifier.IsMoqCallbackMethod(invocation)) { invocation = invocation.InvokedExpression?.FirstChild as IInvocationExpression; } var mockedMethod = GetMockedMethodFromSetupMethod(solution, invocation); if (mockedMethod == null || mockedMethod.Parameters.Count == 0 || mockedMethod.ReturnType.IsVoid()) { return(false); } var types = GetMockedMethodParameterTypes(solution, invocation); var variablesName = mockedMethod.Parameters.Select(p => p.ShortName); var proposedCallback = $"Returns<{string.Join(",", types)}>(({string.Join(",", variablesName)}) => )"; var item = CSharpLookupItemFactory.Instance.CreateKeywordLookupItem(context, proposedCallback, TailType.None, PsiSymbolsThemedIcons.Method.Id); item.SetInsertCaretOffset(-1); item.SetReplaceCaretOffset(-1); item.WithInitializedRanges(context.CompletionRanges, context.BasicContext); item.SetTopPriority(); collector.Add(item); return(true); }
protected override bool AddLookupItems(CSharpCodeCompletionContext context, IItemsCollector collector) { LastException = null; var analysisResult = ContextAnalysis.Analyze(context.NodeInFile, null, MockLogger()); LastContext = analysisResult.Context; LastEntryPoints = analysisResult.EntryPoints; LastCompletionMarker = analysisResult.CompletionMarker; if (IsPrintingType) { PrintType(context, LastCompletionMarker); } LastSST = LastContext.SST; return(base.AddLookupItems(context, collector)); }
protected override void TransformItems(HtmlCodeCompletionContext context, IItemsCollector collector) { var angularItems = (from item in collector.Items let unwrappedItem = GetDeclaredElementLookupItem(item) where unwrappedItem != null && unwrappedItem.GetPreferredDeclaredElement().Element is IAngularJsDeclaredElement select item).ToJetHashSet(); var angularItemNames = angularItems.ToJetHashSet(i => i.DisplayName.Text); var toRemove = from item in collector.Items where !angularItems.Contains(item) && angularItemNames.Contains(item.DisplayName.Text) select item; foreach (var item in toRemove.ToList()) { collector.Remove(item); } }
private bool TryAddMatchingItemsForMatchedAbbreviation(string prefix, HtmlCodeCompletionContext context, IItemsCollector collector) { if (string.IsNullOrEmpty(prefix)) { return(false); } var matcher = LookupUtil.CreateMatcher(prefix, IdentifierMatchingStyle.BeginingOfIdentifier); var added = false; foreach (var abbreviation in Abbreviations) { added |= AddItems(abbreviation, context, collector, matcher.Matches); } return(added); }
private bool TryAddMatchingUnprefixedItems(string prefix, HtmlCodeCompletionContext context, IItemsCollector collector) { if (string.IsNullOrEmpty(prefix)) { return(false); } var added = false; foreach (var abbreviation in Abbreviations) { var matcher = LookupUtil.CreateMatcher(abbreviation + prefix, context.BasicContext.IdentifierMatchingStyle); added |= AddItems(abbreviation, context, collector, matcher.Matches); } return(added); }
protected override bool AddLookupItems(CSharpCodeCompletionContext context, IItemsCollector collector) { Log.Info("Add lookupitems"); var solution = context.PsiModule.GetSolution(); var ltgConfig = Shell.Instance.GetComponent <LtgConfigWatcher>(); var iconManager = solution.GetComponent <PsiIconManager>(); var provider = solution.GetComponent <CSharpExtendedScopeProvider>(); var textControl = context.BasicContext.TextControl; var offset = textControl.Caret.Offset(); var templateContext = new TemplateAcceptanceContext( solution, new DocumentOffset(textControl.Document, offset), new DocumentRange(textControl.Document, offset)); var scopePoints = provider.ProvideScopePoints(templateContext); if (ltgConfig.Tree != null) { var template = new Template("", "", "", true, true, false, new[] { TemplateApplicability.Live }) { UID = Guid.NewGuid() }; var scopes = scopePoints.ToList(); Log.Trace("Current scopes: {0}", string.Join(",", scopes)); if (scopes.Any(scopename => ltgConfig.Tree.IsScopeExist(scopename))) { var iconId = iconManager.ExtendToTypicalSize(ServicesThemedIcons.LiveTemplate.Id); collector.Add(new ZenSharpLookupItem(template, ltgConfig.Tree, scopes, iconId)); return(true); } else { return(false); } } Log.Warn("Lookup item for completion is not added, because ZenSharp expand tree is not loaded."); return(false); }
private static void ConditionallyAddWrappedLookupItem(IItemsCollector collector, CoReProposal[] proposals, ILookupItem candidate) { if (candidate is PBNProposalWrappedLookupItem) { return; } var candidateWithInfo = candidate as LookupItem <MethodsInfo>; var wrappedLookupItem = candidateWithInfo != null ? GetWrappedLookupItemForMethods(candidateWithInfo, proposals) : GetWrappedLookupItem(candidate, proposals); if (wrappedLookupItem != null) { collector.Add(wrappedLookupItem); } }
private bool TryAddMatchingAbbreviations(IdentifierMatcher matcher, HtmlCodeCompletionContext context, IItemsCollector collector) { if (matcher == null) { return(false); } var added = false; foreach (var abbreviation in Abbreviations) { if (matcher.Matches(abbreviation)) { added |= AddAbbreviation(context, collector, abbreviation); } } return(added); }
protected override bool AddLookupItems(CSharpCodeCompletionContext context, IItemsCollector collector) { if (context.ExpectedTypesContext == null) { return(false); } foreach (var expectedType in context.ExpectedTypesContext.ExpectedITypes) { if (expectedType.Type.IsInterfaceType()) { var typeName = expectedType.Type.GetPresentableName(CSharpLanguage.Instance); var newMock = GetLookupItem(context, "new Mock<" + typeName + ">().Object"); var mockOf = GetLookupItem(context, $"Mock.Of<{typeName}>()"); collector.Add(newMock); collector.Add(mockOf); } } return(context.ExpectedTypesContext.ExpectedITypes.Count > 0); }
protected override bool AddLookupItems(CSharpCodeCompletionContext context, IItemsCollector collector) { var lookupItems = _genericSettingsProvider.GetXmlSettingsLookupItems( context, SettingsConstants.AppSettingsTagName, SettingsConstants.AppSettingsKeyAttribute, SettingsConstants.AppSettingsValueAttribute); if (!lookupItems.Any()) { return(false); } foreach (var lookupItem in lookupItems) { collector.Add(lookupItem); } return(true); }