Beispiel #1
0
 public Session(Controller controller, ModelComputation <Model> computation, ICompletionPresenterSession presenterSession)
     : base(controller, computation, presenterSession)
 {
     this.PresenterSession.ItemCommitted      += OnPresenterSessionItemCommitted;
     this.PresenterSession.ItemSelected       += OnPresenterSessionItemSelected;
     this.PresenterSession.FilterStateChanged += OnPresenterSessionCompletionItemFilterStateChanged;
 }
Beispiel #2
0
        private bool StartNewModelComputation(
            CompletionService completionService,
            CompletionTrigger trigger,
            bool filterItems,
            bool dismissIfEmptyAllowed)
        {
            AssertIsForeground();
            Contract.ThrowIfTrue(sessionOpt != null);

            if (this.TextView.Selection.Mode == TextSelectionMode.Box)
            {
                // No completion with multiple selection
                return(false);
            }

            // The caret may no longer be mappable into our subject buffer.
            var caret = TextView.GetCaretPoint(SubjectBuffer);

            if (!caret.HasValue)
            {
                return(false);
            }

            if (this.TextView.Caret.Position.VirtualBufferPosition.IsInVirtualSpace)
            {
                // Convert any virtual whitespace to real whitespace by doing an empty edit at the caret position.
                _editorOperationsFactoryService.GetEditorOperations(TextView).InsertText("");
            }

            var computation = new ModelComputation <Model>(this, PrioritizedTaskScheduler.AboveNormalInstance);

            this.sessionOpt = new Session(this, computation, Presenter.CreateSession(TextView, SubjectBuffer, null));

            sessionOpt.ComputeModel(completionService, trigger, _roles, GetOptions());

            var filterReason = trigger.Kind == CompletionTriggerKind.Deletion
                ? CompletionFilterReason.BackspaceOrDelete
                : trigger.Kind == CompletionTriggerKind.Other
                    ? CompletionFilterReason.Other
                    : CompletionFilterReason.TypeChar;

            if (filterItems)
            {
                sessionOpt.FilterModel(
                    filterReason,
                    recheckCaretPosition: false,
                    dismissIfEmptyAllowed: dismissIfEmptyAllowed,
                    filterState: null);
            }
            else
            {
                sessionOpt.IdentifyBestMatchAndFilterToAllItems(
                    filterReason,
                    recheckCaretPosition: false,
                    dismissIfEmptyAllowed: dismissIfEmptyAllowed);
            }

            return(true);
        }
Beispiel #3
0
            public Session(Controller controller, ModelComputation <Model> computation, IEnumerable <ICompletionRules> completionRules, ICompletionPresenterSession presenterSession)
                : base(controller, computation, presenterSession)
            {
                _completionRules = completionRules.ToList();

                this.PresenterSession.ItemCommitted += OnPresenterSessionItemCommitted;
                this.PresenterSession.ItemSelected  += OnPresenterSessionItemSelected;
            }
Beispiel #4
0
        private bool StartNewModelComputation(ICompletionService completionService, CompletionTriggerInfo triggerInfo, bool filterItems, bool dismissIfEmptyAllowed = true)
        {
            AssertIsForeground();
            Contract.ThrowIfTrue(sessionOpt != null);

            if (this.TextView.Selection.Mode == TextSelectionMode.Box)
            {
                Trace.WriteLine("Box selection, cannot have completion");

                // No completion with multiple selection
                return(false);
            }

            // The caret may no longer be mappable into our subject buffer.
            var caret = TextView.GetCaretPoint(SubjectBuffer);

            if (!caret.HasValue)
            {
                Trace.WriteLine("Caret is not mappable to subject buffer, cannot have completion");

                return(false);
            }


            if (this.TextView.Caret.Position.VirtualBufferPosition.IsInVirtualSpace)
            {
                // Convert any virtual whitespace to real whitespace by doing an empty edit at the caret position.
                _editorOperationsFactoryService.GetEditorOperations(TextView).InsertText("");
            }

            var computation = new ModelComputation <Model>(this, PrioritizedTaskScheduler.AboveNormalInstance);

            this.sessionOpt = new Session(this, computation, GetCompletionRules(), Presenter.CreateSession(TextView, SubjectBuffer, null));

            var completionProviders = triggerInfo.TriggerReason == CompletionTriggerReason.Snippets
                ? GetSnippetCompletionProviders()
                : GetCompletionProviders();

            sessionOpt.ComputeModel(completionService, triggerInfo, GetOptions(), completionProviders);

            var filterReason = triggerInfo.TriggerReason == CompletionTriggerReason.BackspaceOrDeleteCommand
                ? CompletionFilterReason.BackspaceOrDelete
                : CompletionFilterReason.TypeChar;

            if (filterItems)
            {
                sessionOpt.FilterModel(filterReason, dismissIfEmptyAllowed: dismissIfEmptyAllowed);
            }
            else
            {
                sessionOpt.IdentifyBestMatchAndFilterToAllItems(filterReason, dismissIfEmptyAllowed: dismissIfEmptyAllowed);
            }

            return(true);
        }
        /// <summary>
        /// Start a new ModelComputation. Completion computations and filtering tasks will be chained to this
        /// ModelComputation, and when the chain is complete the view will be notified via the
        /// OnCompletionModelUpdated handler.
        ///
        /// The latest immutable CompletionModel can be accessed at any time. Some parts of the code may choose
        /// to wait on it to arrive synchronously.
        ///
        /// Inspired by similar method in Completion/Controller.cs in Roslyn.
        /// </summary>
        void StartNewComputation(
            int position,
            CompletionRules rules,
            bool filterItems)
        {
            computation = new ModelComputation <CompletionModel> (
                OnCompletionModelUpdated,
                Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.Completion.PrioritizedTaskScheduler.AboveNormalInstance);

            ComputeModel(position);

            if (filterItems)
            {
                var document = compilationWorkspace.GetSubmissionDocument(sourceTextContent.Container);
                FilterModel(CompletionHelper.GetHelper(document));
            }
        }
Beispiel #6
0
        private bool StartNewModelComputation(
            CompletionService completionService,
            CompletionTrigger trigger)
        {
            AssertIsForeground();
            Contract.ThrowIfTrue(sessionOpt != null);

            if (completionService == null)
            {
                return(false);
            }

            if (this.TextView.Selection.Mode == TextSelectionMode.Box)
            {
                // No completion with multiple selection
                return(false);
            }

            // The caret may no longer be mappable into our subject buffer.
            var caret = TextView.GetCaretPoint(SubjectBuffer);

            if (!caret.HasValue)
            {
                return(false);
            }

            if (this.TextView.Caret.Position.VirtualBufferPosition.IsInVirtualSpace)
            {
                // Convert any virtual whitespace to real whitespace by doing an empty edit at the caret position.
                _editorOperationsFactoryService.GetEditorOperations(TextView).InsertText("");
            }

            var computation = new ModelComputation <Model>(this, PrioritizedTaskScheduler.AboveNormalInstance);

            this.sessionOpt = new Session(this, computation, Presenter.CreateSession(TextView, SubjectBuffer, null));

            sessionOpt.ComputeModel(completionService, trigger, _roles, GetOptions());
            sessionOpt.FilterModel(trigger.GetFilterReason(), filterState: null);

            return(true);
        }
 void StopComputation()
 {
     computation?.Stop();
     computation = null;
 }