Пример #1
0
        private static CompletionContext GetCompletionContext(PaketDocument paketDocument, ITextStructureNavigator navigator, SnapshotPoint position)
        {
            var startPos = position.Position;
            var length   = 0;

            if (position.Position > 0)
            {
                TextExtent endPosition   = navigator.GetExtentOfWord(position);
                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);
                }


                startPos = startPosition.Span.Start.Position;
                length   = endPosition.Span.End.Position - startPos;
            }

            var span         = new Span(startPos, length);
            var snapShotSpan = new SnapshotSpan(position.Snapshot, span);

            var context = new CompletionContext(span);

            context.ContextType = CompletionContextType.InstalledNuGet;
            context.Snapshot    = snapShotSpan.Snapshot;
            return(context);
        }
Пример #2
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;

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

            context.Snapshot = snapShotSpan.Snapshot;
            return(context);
        }
Пример #3
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);
        }
Пример #4
0
 private static IEnumerable <ICompletionListProvider> GetCompletionProviders(PaketDocument paketDocument, ITextStructureNavigator navigator, SnapshotPoint position, out CompletionContext context)
 {
     context = GetCompletionContext(paketDocument, navigator, position);
     return(GetCompletionProviders(context.ContextType));
 }
Пример #5
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);
        }