public Package GetPackage()
 {
     try
     {
         return(ExposedObject.From(ServiceProvider).ServiceProvider as Package);
     }
     catch
     {
         return(null);
     }
 }
 private void SetFsiToolWindowCompletionSetVisibilty(bool displayed)
 {
     if (fsiToolWindow != null)
     {
         dynamic source = ExposedObject.From(fsiToolWindow).source;
         if (source != null)
         {
             dynamic completionSet = ExposedObject.From(source).CompletionSet;
             if (completionSet != null)
             {
                 dynamic completionSetExp = ExposedObject.From(completionSet);
                 completionSetExp.displayed = displayed;
             }
         }
     }
 }
示例#3
0
        private Object GetSession()
        {
            try
            {
                var     providerGlobal     = (IOleServiceProvider)Package.GetGlobalService(typeof(IOleServiceProvider));
                var     provider           = new ServiceProvider(providerGlobal);
                dynamic fsiLanguageService = ExposedObject.From(provider.GetService(fsiLanguageServiceType));
                dynamic sessions           = fsiLanguageService.sessions;
                if (sessions != null)
                {
                    dynamic sessionsValue      = ExposedObject.From(sessions).Value;
                    dynamic sessionR           = ExposedObject.From(sessionsValue).sessionR;
                    dynamic sessionRValue      = ExposedObject.From(sessionR).Value;
                    dynamic sessionRValueValue = ExposedObject.From(sessionRValue).Value;
                    dynamic exitedE            = ExposedObject.From(sessionRValueValue).exitedE;

                    MethodInfo methodInfo          = fsiAssembly.GetType("Microsoft.VisualStudio.FSharp.Interactive.Session+Session").GetMethod("get_Exited");
                    IObservable <EventArgs> exited = methodInfo.Invoke(sessionRValueValue, null);
                    IObserver <EventArgs>   obsvr  = Observer.Create <EventArgs>(
                        x => {
                        //    RegisterAutocompleteServer();
                    },
                        ex => { },
                        () => { });

                    exited.Subscribe(obsvr);


                    return(sessionRValueValue);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

            return(null);
        }
 public static T Cast <T>(ExposedObject t)
 {
     return((T)t.m_object);
 }
 private CommandChainNodeWrapper(Object commandChainNode)
 {
     this.commandChainNode = ExposedObject.From(commandChainNode);
 }
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (autocompleteMode == AutocompleteModeType.Off ||
                VsShellUtilities.IsInAutomationFunction(m_provider.ServiceProvider))
            {
                return(m_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
            }
            //make a copy of this so we can look at it after forwarding some commands
            uint commandID = nCmdID;
            char typedChar = char.MinValue;

            //make sure the input is a char before getting it
            if (pguidCmdGroup == VSConstants.VSStd2K && nCmdID == (uint)VSConstants.VSStd2KCmdID.TYPECHAR)
            {
                typedChar = (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn);
            }

            //check for a commit character
            if (nCmdID == (uint)VSConstants.VSStd2KCmdID.RETURN ||
                nCmdID == (uint)VSConstants.VSStd2KCmdID.TAB ||
                char.IsPunctuation(typedChar) && typedChar != '.')
            {
                //check for a a selection
                if (m_session != null && !m_session.IsDismissed)
                {
                    //if the selection is fully selected, commit the current session
                    if (m_session.SelectedCompletionSet.SelectionStatus.IsSelected)
                    {
                        m_session.Commit();
                        //also, don't add the character to the buffer
                        if (typedChar != '.')
                        {
                            return(VSConstants.S_OK);
                        }
                    }
                    else
                    {
                        //if there is no selection, dismiss the session
                        m_session.Dismiss();
                    }
                }
            }

            // Dismiss session when whitespace is pressed.
            if (char.IsWhiteSpace(typedChar) && m_session != null && !m_session.IsDismissed)
            {
                m_session.Dismiss();
            }

            //pass along the command so the char is added to the buffer
            int  retVal  = m_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
            bool handled = false;

            if (!typedChar.Equals(char.MinValue) && (char.IsLetterOrDigit(typedChar) || typedChar == '.'))
            {
                if ((m_session == null || m_session.IsDismissed) && autocompleteMode == AutocompleteModeType.Automatic) // If there is no active session, bring up completion
                {
                    this.TriggerCompletion();
                    if (m_session != null && typedChar != '.')
                    {
                        m_session.Filter();
                    }
                }
                else     //the completion session is already active, so just filter
                {
                    if (m_session.SelectedCompletionSet != null &&
                        m_session.SelectedCompletionSet.Completions != null &&
                        m_session.SelectedCompletionSet.Completions.Count > 0 &&
                        m_session.SelectedCompletionSet.Completions[0].InsertionText.StartsWith("."))
                    {
                        // For sorm reason m_session.Filter() filters by DisplayName, not InsertionText no matter what.
                        // Probbly need to remimplement it in order to work properly, otherwise just restarting completion session.
                        m_session.Dismiss();
                        this.TriggerCompletion();
                    }
                    else
                    {
                        m_session.Filter();
                    }
                }

                if (m_session != null && m_session.Presenter != null)
                {
                    handled = true;
                    dynamic presenter = ExposedObject.From(m_session.Presenter);
                    IIntellisensePresenter intelisensePresenter           = m_session.Presenter;
                    System.Windows.Controls.ContentControl surfaceElement = (System.Windows.Controls.ContentControl)presenter.SurfaceElement;
                    surfaceElement.Focus();
                }
            }
            else if ((autocompleteMode == AutocompleteModeType.Automatic || autocompleteMode == AutocompleteModeType.CtrlSpace) &&
                     (commandID == (uint)VSConstants.VSStd2KCmdID.AUTOCOMPLETE || commandID == (uint)VSConstants.VSStd2KCmdID.COMPLETEWORD))
            {
                // Trigger completion on Ctrl + Space
                if (m_session == null || m_session.IsDismissed) // If there is no active session, bring up completion
                {
                    this.TriggerCompletion();


                    if (m_session != null && GetLastTypedCharter() != '.')
                    {
                        m_session.Filter();
                    }
                }
            }
            else if (commandID == (uint)VSConstants.VSStd2KCmdID.BACKSPACE || //redo the filter if there is a deletion
                     commandID == (uint)VSConstants.VSStd2KCmdID.DELETE)
            {
                if (m_session != null && !m_session.IsDismissed)
                {
                    m_session.Filter();
                }
                handled = true;
            }
            if (handled)
            {
                return(VSConstants.S_OK);
            }
            return(retVal);
        }