public FromImportCompletionAnalysis(IList<ClassificationSpan> tokens, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options)
            : base(span, textBuffer, options)
        {
            Debug.Assert(tokens[0].Span.GetText() == "from");

            int beforeImportToken = tokens
                .TakeWhile(tok => !(tok.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Keyword) && tok.Span.GetText() == "import"))
                .Count();

            bool lastIsDot = tokens.Last().ClassificationType.IsOfType(JPredefinedClassificationTypeNames.Dot);
            _modulesOnly = beforeImportToken == tokens.Count;
            _noCompletions = !_modulesOnly && lastIsDot;
            _includeStar = beforeImportToken == tokens.Count - 1;

            if (beforeImportToken >= 2) {
                // If there are at least two tokens ('from' <name>) before the
                // 'import' token, use completions from that package.
                if (beforeImportToken < tokens.Count || lastIsDot) {
                    _namespace = tokens
                        .Take(beforeImportToken)
                        .Where(tok => tok.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Identifier))
                        .Select(tok => tok.Span.GetText())
                        .ToArray();
                } else {
                    _importKeywordOnly = true;
                }
            }
        }
Exemple #2
0
        public static CompletionOptions GetOptions(this ICompletionSession session)
        {
            var options = new CompletionOptions {
                ConvertTabsToSpaces = session.TextView.Options.IsConvertTabsToSpacesEnabled(),
                IndentSize = session.TextView.Options.GetIndentSize(),
                TabSize = session.TextView.Options.GetTabSize()
            };

            if (JToolsPackage.Instance != null) {
                options.IntersectMembers = JToolsPackage.Instance.AdvancedEditorOptionsPage.IntersectMembers;
                options.HideAdvancedMembers = JToolsPackage.Instance.LangPrefs.HideAdvancedMembers;
                options.FilterCompletions = JToolsPackage.Instance.AdvancedEditorOptionsPage.FilterCompletions;
                options.SearchMode = JToolsPackage.Instance.AdvancedEditorOptionsPage.SearchMode;
            }
            return options;
        }
        internal ImportCompletionAnalysis(IList<ClassificationSpan> tokens, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options)
            : base(span, textBuffer, options)
        {
            Debug.Assert(tokens[0].Span.GetText() == "import");

            int beforeLastComma = tokens
                .Reverse()
                .SkipWhile(tok => !tok.ClassificationType.IsOfType(JPredefinedClassificationTypeNames.Comma))
                .Count();

            if (tokens.Count >= 2 && beforeLastComma < tokens.Count) {
                int spanEnd = Span.GetEndPoint(textBuffer.CurrentSnapshot).Position;
                var nameParts = new List<string>();
                bool removeLastPart = false, lastWasError = false;
                foreach(var tok in tokens.Skip(beforeLastComma > 0 ? beforeLastComma : 1)) {
                    if (tok.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Identifier)) {
                        nameParts.Add(tok.Span.GetText());
                        // Only remove the last part if the trigger point is
                        // not right at the end of it.
                        removeLastPart = (tok.Span.End.Position != spanEnd);
                    } else if (tok.ClassificationType.IsOfType(JPredefinedClassificationTypeNames.Dot)) {
                        removeLastPart = false;
                    } else {
                        lastWasError = true;
                        break;
                    }
                }

                if (!lastWasError) {
                    if (removeLastPart && nameParts.Count > 0) {
                        nameParts.RemoveAt(nameParts.Count - 1);
                    }
                    _namespace = nameParts.ToArray();
                }
            }
        }
 internal NormalCompletionAnalysis(VsProjectAnalyzer analyzer, ITextSnapshot snapshot, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options)
     : base(span, textBuffer, options)
 {
     _snapshot = snapshot;
     _analyzer = analyzer;
 }
Exemple #5
0
 internal CompletionAnalysis(ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options)
 {
     _span = span;
     _textBuffer = textBuffer;
     _options = (options == null) ? new CompletionOptions() : options.Clone();
 }
 internal DecoratorCompletionAnalysis(ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options)
     : base(span, textBuffer, options)
 {
 }
 internal StringLiteralCompletionList(ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options)
     : base(span, textBuffer, options)
 {
 }
Exemple #8
0
 /// <summary>
 /// Gets a CompletionAnalysis providing a list of possible members the user can dot through.
 /// </summary>
 public static CompletionAnalysis GetCompletions(this ITextSnapshot snapshot, ITrackingSpan span, ITrackingPoint point, CompletionOptions options)
 {
     return VsProjectAnalyzer.GetCompletions(snapshot, span, point, options);
 }
 internal OverrideCompletionAnalysis(ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options)
     : base(span, textBuffer, options) {
 }
Exemple #10
0
        /// <summary>
        /// Initializes a new instance with the specified properties.
        /// </summary>
        /// <param name="moniker">The unique, non-localized identifier for the
        /// completion set.</param>
        /// <param name="displayName">The localized name of the completion set.
        /// </param>
        /// <param name="applicableTo">The tracking span to which the
        /// completions apply.</param>
        /// <param name="completions">The list of completions.</param>
        /// <param name="options">The options to use for filtering and
        /// selecting items.</param>
        /// <param name="comparer">The comparer to use to order the provided
        /// completions.</param>
        public FuzzyCompletionSet(string moniker, string displayName, ITrackingSpan applicableTo, IEnumerable<DynamicallyVisibleCompletion> completions, CompletionOptions options, IComparer<Completion> comparer)
            : base(moniker, displayName, applicableTo, null, null)
        {
            _completions = new BulkObservableCollection<Completion>();
            _completions.AddRange(completions.OrderBy(c => c, comparer));
            _comparer = new FuzzyStringMatcher(options.SearchMode);

            _shouldFilter = options.FilterCompletions;
            _shouldHideAdvanced = options.HideAdvancedMembers;

            if (_shouldFilter | _shouldHideAdvanced) {
                _filteredCompletions = new FilteredObservableCollection<Completion>(_completions);

                foreach (var c in _completions.Cast<DynamicallyVisibleCompletion>()) {
                    c.Visible = !_shouldHideAdvanced || !IsAdvanced(c);
                }
                _filteredCompletions.Filter(IsVisible);
            }
        }