Exemplo n.º 1
0
        // 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,
                                               GroupedItemsCollector 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
                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);
        }
        private IdentifierMatcher GetIdentifierMatcher(CodeCompletionContext context, TextLookupRanges ranges)
        {
            var text = context.Document.GetText(ranges.InsertRange.TextRange);

            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }
            return(LookupUtil.CreateMatcher(text, context.IdentifierMatchingStyle));
        }
Exemplo n.º 3
0
        private bool TryAddMatchingItemsForMatchedAbbreviation(string prefix, HtmlCodeCompletionContext context,
                                                               GroupedItemsCollector 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);
        }
Exemplo n.º 5
0
        protected override bool AddLookupItems(ISpecificCodeCompletionContext context, IItemsCollector collector)
        {
            var languageCaseProvider = LanguageManager.Instance.TryGetService <LanguageCaseProvider>(language);
            var templateNames        = new JetHashSet <string>(languageCaseProvider.IfNotNull(cp => cp.IsCaseSensitive()
                ? StringComparer.Ordinal
                : StringComparer.OrdinalIgnoreCase));
            IEnumerable <TemplateLookupItem> templateItems = TemplateActionsUtil.GetLookupItems(context.BasicContext.TextControl, context.BasicContext.CompletionManager.Solution, false, false);

            var prefix = LiveTemplatesManager.GetPrefix(context.BasicContext.CaretDocumentOffset, JsAllowedPrefixes.Chars);

            if (collector.Ranges == null)
            {
                var caretOffset = context.BasicContext.CaretDocumentOffset;
                var prefixRange = new DocumentRange(caretOffset - prefix.Length, caretOffset);
                collector.AddRanges(new TextLookupRanges(prefixRange, prefixRange));
            }

            if (!string.IsNullOrEmpty(prefix))
            {
                var identifierMatcher = LookupUtil.CreateMatcher(prefix, context.BasicContext.IdentifierMatchingStyle);
                templateItems = templateItems.Where(item => identifierMatcher.Matches(item.Template.Shortcut));
            }

            foreach (var templateItem in templateItems)
            {
                templateNames.Add(templateItem.DisplayName.Text);
            }

            if (templateItems.IsEmpty())
            {
                return(false);
            }

            context.BasicContext.PutData(TemplateNamesKey, templateNames);

            foreach (var templateItem in templateItems)
            {
                collector.Add(templateItem);
            }

            return(true);
        }