Extensibility interface for clients who want to participate in completion inside an editor.
 public XmlDocCommentCompletionItem(CompletionListProvider provider,
     TextSpan filterSpan,
     string displayText,
     CompletionItemRules rules)
     : this(provider, filterSpan, displayText, displayText, string.Empty, rules)
 {
 }
        public CSharpCompletionItem(
            Workspace workspace,
            CompletionListProvider completionProvider,
            string displayText,
            TextSpan filterSpan,
            Func<CancellationToken, Task<ImmutableArray<SymbolDisplayPart>>> descriptionFactory,
            Glyph? glyph,
            string sortText = null,
            string filterText = null,
            bool preselect = false,
            bool isBuilder = false,
            bool showsWarningIcon = false,
            bool shouldFormatOnCommit = false)
            : base(completionProvider,
                   displayText,
                   filterSpan,
                   descriptionFactory,
                   glyph,
                   sortText,
                   filterText,
                   preselect,
                   isBuilder,
                   showsWarningIcon,
                   shouldFormatOnCommit)
        {
            Contract.ThrowIfNull(workspace);

            this.Workspace = workspace;
        }
        private static async Task <CompletionList> GetCompletionListAsync(
            CompletionListProvider provider,
            Document documentOpt,
            SourceText text,
            int position,
            CompletionTriggerInfo triggerInfo,
            CancellationToken cancellationToken)
        {
            if (provider is TextCompletionProvider)
            {
                return(((TextCompletionProvider)provider).GetCompletionList(text, position, triggerInfo, cancellationToken));
            }

            if (documentOpt != null)
            {
                var context = new CompletionListContext(documentOpt, position, triggerInfo, cancellationToken);

                await provider.ProduceCompletionListAsync(context).ConfigureAwait(false);

                return(new CompletionList(context.GetItems(), context.Builder, context.IsExclusive));
            }

            Contract.Fail("Should never get here.");

            return(null);
        }
예제 #4
0
        private CompletionItem(
            CompletionListProvider completionProvider,
            string displayText,
            TextSpan filterSpan,
            Func <CancellationToken, Task <ImmutableArray <SymbolDisplayPart> > > descriptionFactory,
            Glyph?glyph,
            bool hasAsyncDescription,
            string sortText,
            string filterText,
            bool preselect,
            bool isBuilder,
            bool showsWarningIcon,
            bool shouldFormatOnCommit,
            CompletionItemRules rules)
        {
            this.CompletionProvider = completionProvider;
            this.DisplayText        = displayText;
            this.Glyph                = glyph;
            this.SortText             = sortText ?? displayText;
            this.FilterText           = filterText ?? displayText;
            this.Preselect            = preselect;
            this.FilterSpan           = filterSpan;
            this.IsBuilder            = isBuilder;
            this.ShowsWarningIcon     = showsWarningIcon;
            this.ShouldFormatOnCommit = shouldFormatOnCommit;
            this.HasAsyncDescription  = hasAsyncDescription;
            this.Rules                = rules ?? CompletionItemRules.DefaultRules;

            if (descriptionFactory != null)
            {
                this.LazyDescription = new AsyncLazy <ImmutableArray <SymbolDisplayPart> >(descriptionFactory, cacheResult: true);
            }
        }
        public FileSystemCompletionHelper(
            CompletionListProvider completionProvider,
            TextSpan textChangeSpan,
            ICurrentWorkingDirectoryDiscoveryService fileSystemDiscoveryService,
            Glyph folderGlyph,
            Glyph fileGlyph,
            ImmutableArray<string> searchPaths,
            IEnumerable<string> allowableExtensions,
            Func<string, bool> exclude = null,
            CompletionItemRules itemRules = null)
        {
            Debug.Assert(searchPaths.All(path => PathUtilities.IsAbsolute(path)));

            _completionProvider = completionProvider;
            _textChangeSpan = textChangeSpan;
            _searchPaths = searchPaths;
            _allowableExtensions = allowableExtensions.Select(e => e.ToLowerInvariant()).ToSet();
            _fileSystemDiscoveryService = fileSystemDiscoveryService;
            _folderGlyph = folderGlyph;
            _fileGlyph = fileGlyph;
            _exclude = exclude;
            _itemRules = itemRules;

            _lazyGetDrives = new Lazy<string[]>(() =>
                IOUtilities.PerformIO(Directory.GetLogicalDrives, SpecializedCollections.EmptyArray<string>()));
        }
예제 #6
0
 public XmlItem(CompletionListProvider provider,
     TextSpan filterSpan,
     string displayText,
     string beforeCaretText,
     string afterCaretText)
     : base(provider, displayText, filterSpan, glyph: CodeAnalysis.Glyph.Keyword)
 {
     _beforeCaretText = beforeCaretText;
     _afterCaretText = afterCaretText;
 }
 public XmlDocCommentCompletionItem(CompletionListProvider provider,
     TextSpan filterSpan,
     string displayText,
     string beforeCaretText,
     string afterCaretText,
     CompletionItemRules rules)
     : base(provider, displayText, filterSpan, glyph: CodeAnalysis.Glyph.Keyword, rules: rules)
 {
     _beforeCaretText = beforeCaretText;
     _afterCaretText = afterCaretText;
 }
 public Item(
     CompletionListProvider completionProvider,
     string displayText,
     string insertionText,
     TextSpan textSpan,
     Func<CancellationToken,
     Task<ImmutableArray<SymbolDisplayPart>>> descriptionFactory,
     Glyph? glyph,
     string sortText)
     : base(completionProvider, displayText, textSpan, descriptionFactory, glyph, sortText, rules: ItemRules.Instance)
 {
     this.InsertionText = insertionText;
 }
        private static async Task <CompletionList> GetCompletionListAsync(
            CompletionListProvider provider,
            Document document,
            int position,
            CompletionTriggerInfo triggerInfo,
            CancellationToken cancellationToken)
        {
            var context = new CompletionListContext(document, position, triggerInfo, cancellationToken);

            await provider.ProduceCompletionListAsync(context).ConfigureAwait(false);

            return(new CompletionList(context.GetItems(), context.Builder, context.IsExclusive));
        }
 public CrefCompletionItem(
     Workspace workspace,
     CompletionListProvider completionProvider,
     string displayText,
     string insertionText,
     TextSpan textSpan,
     Func<CancellationToken,
     Task<ImmutableArray<SymbolDisplayPart>>> descriptionFactory,
     Glyph? glyph,
     string sortText)
     : base(workspace, completionProvider, displayText, textSpan, descriptionFactory, glyph, sortText)
 {
     this.InsertionText = insertionText;
 }
 public MemberInsertionCompletionItem(
     CompletionListProvider provider,
     string displayText,
     TextSpan filterSpan,
     Func<CancellationToken, Task<ImmutableArray<SymbolDisplayPart>>> descriptionFactory,
     Glyph? glyph,
     DeclarationModifiers modifiers,
     int line,
     SymbolKey symbolId,
     SyntaxToken token)
     : base(provider, displayText, filterSpan, descriptionFactory, glyph)
 {
     this.Modifiers = modifiers;
     this.Line = line;
     this.SymbolId = symbolId;
     this.Token = token;
 }
예제 #12
0
 public CompletionItem(
     CompletionListProvider completionProvider,
     string displayText,
     TextSpan filterSpan,
     Func <CancellationToken, Task <ImmutableArray <SymbolDisplayPart> > > descriptionFactory,
     Glyph?glyph,
     string sortText           = null,
     string filterText         = null,
     bool preselect            = false,
     bool isBuilder            = false,
     bool showsWarningIcon     = false,
     bool shouldFormatOnCommit = false,
     CompletionItemRules rules = null) :
     this(completionProvider, displayText, filterSpan, descriptionFactory, glyph, /*hasAsyncDescription*/ true, sortText,
          filterText, preselect, isBuilder, showsWarningIcon, shouldFormatOnCommit, rules)
 {
 }
예제 #13
0
 public CompletionItem(
     CompletionListProvider completionProvider,
     string displayText,
     TextSpan filterSpan,
     ImmutableArray <SymbolDisplayPart> description = default(ImmutableArray <SymbolDisplayPart>),
     Glyph?glyph               = null,
     string sortText           = null,
     string filterText         = null,
     bool preselect            = false,
     bool isBuilder            = false,
     bool showsWarningIcon     = false,
     bool shouldFormatOnCommit = false,
     CompletionItemRules rules = null)
     : this(completionProvider, displayText, filterSpan,
            description.IsDefault ? (Func <CancellationToken, Task <ImmutableArray <SymbolDisplayPart> > >)null : c => Task.FromResult(description),
            glyph, /*hasAsyncDescription*/ false, sortText, filterText, preselect, isBuilder, showsWarningIcon, shouldFormatOnCommit, rules)
 {
 }
예제 #14
0
 // Constructor kept for back compat.  When we move to our new completion API we can remove this.
 public CompletionItem(
     CompletionListProvider completionProvider,
     string displayText,
     TextSpan filterSpan,
     Func <CancellationToken, Task <ImmutableArray <SymbolDisplayPart> > > descriptionFactory,
     Glyph?glyph,
     string sortText,
     string filterText,
     bool preselect,
     bool isBuilder,
     bool showsWarningIcon,
     bool shouldFormatOnCommit,
     CompletionItemRules rules)
     : this(completionProvider, displayText, filterSpan, descriptionFactory, glyph, sortText,
            filterText, preselect, isBuilder, showsWarningIcon, shouldFormatOnCommit, rules,
            ImmutableArray <CompletionItemFilter> .Empty)
 {
 }
예제 #15
0
        private static async Task <CompletionList> GetCompletionListAsync(
            CompletionListProvider provider,
            Document document,
            int position,
            CompletionTriggerInfo triggerInfo,
            OptionSet options,
            CancellationToken cancellationToken)
        {
            var context = new CompletionListContext(document, position, triggerInfo, options, cancellationToken);

            if (document.SupportsSyntaxTree)
            {
                var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

                if (!root.FullSpan.IntersectsWith(position))
                {
                    try
                    {
                        // Trying to track down source of https://github.com/dotnet/roslyn/issues/9325
                        var sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);

                        ReportException(position, root, sourceText);
                    }
                    catch (Exception e) when(FatalError.ReportWithoutCrash(e))
                    {
                    }
                }
                else
                {
                    await provider.ProduceCompletionListAsync(context).ConfigureAwait(false);
                }
            }
            else
            {
                await provider.ProduceCompletionListAsync(context).ConfigureAwait(false);
            }

            return(new CompletionList(context.GetItems(), context.Builder, context.IsExclusive));
        }
예제 #16
0
 public XmlItem(CompletionListProvider provider,
     TextSpan filterSpan,
     string displayText)
     : this(provider, filterSpan, displayText, displayText, string.Empty)
 {
 }
        private static async Task<CompletionList> GetCompletionListAsync(
            CompletionListProvider provider,
            Document document,
            int position,
            CompletionTriggerInfo triggerInfo,
            OptionSet options,
            CancellationToken cancellationToken)
        {
            var context = new CompletionListContext(document, position, triggerInfo, options, cancellationToken);

            await provider.ProduceCompletionListAsync(context).ConfigureAwait(false);

            return new CompletionList(context.GetItems(), context.Builder, context.IsExclusive);
        }
 public GlobalAssemblyCacheCompletionHelper(CompletionListProvider completionProvider, TextSpan textChangeSpan, CompletionItemRules itemRules = null)
 {
     _completionProvider = completionProvider;
     _textChangeSpan = textChangeSpan;
     _itemRules = itemRules;
 }
 public GlobalAssemblyCacheCompletionHelper(CompletionListProvider completionProvider, TextSpan textChangeSpan)
 {
     _completionProvider = completionProvider;
     _textChangeSpan = textChangeSpan;
 }
예제 #20
0
        private static async Task<CompletionList> GetCompletionListAsync(
            CompletionListProvider provider,
            Document document,
            int position,
            CompletionTriggerInfo triggerInfo,
            OptionSet options,
            CancellationToken cancellationToken)
        {
            var context = new CompletionListContext(document, position, triggerInfo, options, cancellationToken);
            if (document.SupportsSyntaxTree)
            {
                var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
                if (!root.FullSpan.IntersectsWith(position))
                {
                    try
                    {
                        // Trying to track down source of https://github.com/dotnet/roslyn/issues/9325
                        var sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
                        ReportException(position, root, sourceText);
                    }
                    catch (Exception e) when (FatalError.ReportWithoutCrash(e))
                    {
                    }
                }
                else
                {
                    await provider.ProduceCompletionListAsync(context).ConfigureAwait(false);
                }
            }
            else
            {
                await provider.ProduceCompletionListAsync(context).ConfigureAwait(false);
            }

            return new CompletionList(context.GetItems(), context.Builder, context.IsExclusive);
        }
        private static async Task<CompletionList> GetCompletionListAsync(
            CompletionListProvider provider,
            Document documentOpt,
            SourceText text,
            int position,
            CompletionTriggerInfo triggerInfo,
            CancellationToken cancellationToken)
        {
            if (provider is TextCompletionProvider)
            {
                return ((TextCompletionProvider)provider).GetCompletionList(text, position, triggerInfo, cancellationToken);
            }

            if (documentOpt != null)
            {
                var context = new CompletionListContext(documentOpt, position, triggerInfo, cancellationToken);

                await provider.ProduceCompletionListAsync(context).ConfigureAwait(false);

                return new CompletionList(context.GetItems(), context.Builder, context.IsExclusive);
            }

            Contract.Fail("Should never get here.");

            return null;
        }