Example #1
0
 private static IEnumerable <ICompletionListProvider> GetCompletionProviders(PaketDocument paketDocument, ITextStructureNavigator navigator, SnapshotPoint position, out CompletionContext context)
 {
     context = GetCompletionContext(paketDocument, navigator, position);
     return(GetCompletionProviders(context.ContextType));
 }
Example #2
0
        public static IEnumerable <ICompletionListProvider> GetCompletionProviders(IIntellisenseSession session, ITextBuffer textBuffer, SnapshotPoint position, ITextStructureNavigator navigator, out CompletionContext context)
        {
            IEnumerable <ICompletionListProvider> providers = GetCompletionProviders(PaketDocument.FromTextBuffer(textBuffer), navigator, position, out context);

            if (context == null)
            {
                return(providers);
            }

            if (context.Snapshot == null)
            {
                context.Snapshot = textBuffer.CurrentSnapshot;
            }
            if (context.Session != null)
            {
                return(providers);
            }

            context.Session = session;
            return(providers);
        }
Example #3
0
        private static CompletionContext GetCompletionContext(PaketDocument paketDocument, ITextStructureNavigator navigator, SnapshotPoint position)
        {
            TextExtent endPosition   = navigator.GetExtentOfWord(position - 1);
            TextExtent startPosition = endPosition;

            // try to extend the span over .
            while (!String.IsNullOrWhiteSpace(paketDocument.GetCharAt(startPosition.Span.Start.Position - 1)))
            {
                startPosition = navigator.GetExtentOfWord(startPosition.Span.Start - 2);
            }

            var startPos     = startPosition.Span.Start.Position;
            var length       = endPosition.Span.End.Position - startPos;
            var span         = new Span(startPos, length);
            var snapShotSpan = new SnapshotSpan(position.Snapshot, span);

            var context = new CompletionContext(span);

            var pos = startPosition.Span.Start;

            if (startPosition.Span.Start.Position > 0)
            {
                pos = startPosition.Span.Start - 1;
            }

            TextExtent previous = navigator.GetExtentOfWord(pos);

            // try to extend the span over blanks
            while (paketDocument.GetCharAt(previous.Span.Start.Position) == " ")
            {
                var pos2 = previous.Span.Start;
                if (previous.Span.Start.Position > 0)
                {
                    pos2 = previous.Span.Start - 1;
                }

                previous = navigator.GetExtentOfWord(pos2);
            }
            var lastWord = previous.Span.GetText();

            switch (lastWord)
            {
            case "nuget": context.ContextType = CompletionContextType.NuGet; break;

            case "source": context.ContextType = CompletionContextType.Source; break;

            case "strategy": context.ContextType = CompletionContextType.Strategy; break;

            case "framework": context.ContextType = CompletionContextType.Framework; break;

            case "version": context.ContextType = CompletionContextType.Version; break;

            case "storage": context.ContextType = CompletionContextType.Storage; break;

            case "content": context.ContextType = CompletionContextType.Content; break;

            case "copy_content_to_output_dir": context.ContextType = CompletionContextType.CopyToOutputDirectory; break;

            case "copy_local": context.ContextType = CompletionContextType.CopyLocal; break;

            case "import_targets": context.ContextType = CompletionContextType.ImportTargets; break;

            case "download_license": context.ContextType = CompletionContextType.DownloadLicense; break;

            case "redirects": context.ContextType = CompletionContextType.Redirects; break;

            case "lowest_matching": context.ContextType = CompletionContextType.LowestMatching; break;

            case "generate_load_scripts": context.ContextType = CompletionContextType.GenerateLoadScripts; break;

            case "references": context.ContextType = CompletionContextType.References; break;

            default: context.ContextType = CompletionContextType.Keyword; break;
            }

            context.Snapshot = snapShotSpan.Snapshot;
            return(context);
        }