internal VsKeyProcessorAdditional(VsHost host, IVsTextView view,  System.IServiceProvider provider)
 {
     _host = host;
     _textView = view;
     _serviceProvider = provider;
     var hr = view.AddCommandFilter(this, out _nextTarget);
 }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            textView.Properties.GetOrCreateSingletonProperty(() => new ControllerGoToDefinition(textViewAdapter, textView, AngularPackage.DTE, this.StandardClassificationService, this.HierarchyProvider));
            textView.Properties.GetOrCreateSingletonProperty(() => new DirectiveGoToDefinition(textViewAdapter, textView, AngularPackage.DTE, this.HierarchyProvider));
        }
示例#3
0
        // ParseReason.CompleteWord
        // ParseReason.DisplayMemberList
        // ParseReason.MemberSelect
        // ParseReason.MemberSelectAndHilightBraces
        public override Microsoft.VisualStudio.Package.Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
        {
            IList<Declaration> declarations;
            switch (reason)
            {
                case ParseReason.CompleteWord:
                    var tokenInfo = GetTokenInfoOfFirstTokenOnLine(view, line, col);

                    if (tokenInfo.Token == (int)GherkinTerm.Step)
                        declarations = resolver.FindMembers(StepProvider, Grammar, line, col);
                    else
                        declarations = resolver.FindCompletions(StepProvider, Grammar, line, col);
                    break;

                case ParseReason.DisplayMemberList:
                case ParseReason.MemberSelect:
                case ParseReason.MemberSelectAndHighlightBraces:
                    declarations = resolver.FindMembers(StepProvider, Grammar, line, col);
                    break;
                default:
                    throw new ArgumentException("reason");
            }

            return new Declarations(declarations);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TextViewCommandFilter"/> class
        /// for the specified text view.
        /// </summary>
        /// <param name="textViewAdapter">The text view this command filter should attach to.</param>
        protected TextViewCommandFilter(IVsTextView textViewAdapter)
        {
            if (textViewAdapter == null)
                throw new ArgumentNullException("textViewAdapter");

            _textViewAdapter = textViewAdapter;
        }
 public SurroundWith(IVsTextView adapter, IWpfTextView textView, ICompletionBroker broker)
     : base(adapter, textView, GuidList.guidFormattingCmdSet, PkgCmdIDList.SurroundWith)
 {
     _broker = broker;
     _view = textView;
     _buffer = textView.TextBuffer;
 }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);
            var dte = ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE2;

            textView.Properties.GetOrCreateSingletonProperty<PasteCommandHandler>(() => new PasteCommandHandler(textViewAdapter, textView, dte));
        }
示例#7
0
        int IVsCodeWindowManager.OnNewView(IVsTextView pView)
        {
            if (pView == null)
                throw new ArgumentNullException("pView");

            return OnNewView(pView);
        }
 public EnterFormat(IVsTextView adapter, IWpfTextView textView, IEditorFormatterProvider formatterProvider, ICompletionBroker broker)
     : base(adapter, textView, typeof(Microsoft.VisualStudio.VSConstants.VSStd2KCmdID).GUID, 3)
 {
     _tree = HtmlEditorDocument.FromTextView(textView).HtmlEditorTree;
     _formatter = formatterProvider.CreateRangeFormatter();
     _broker = broker;
 }
 public RemoveWhitespaceOnSave(IVsTextView textViewAdapter, IWpfTextView view, DTE2 dte, ITextDocument document)
 {
     textViewAdapter.AddCommandFilter(this, out _nextCommandTarget);
     _view = view;
     _dte = dte;
     _document = document;
 }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            textView.Properties.GetOrCreateSingletonProperty(() => new EnterIndentation(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty(() => new CommentCommandTarget(textViewAdapter, textView, "#"));
        }
        internal CommandFilter(IVsTextView textViewAdapter, IWpfTextView textView)
        {
            recorder = new Recorder();
            listening = false;

            this.textView = textView;
            textViewAdapter.AddCommandFilter(this, out nextFilter);

            // trying to get document path from TextBuffer
            ITextBuffer buffer = this.textView.TextBuffer;
            ITextDocument document;

            var result = buffer.Properties.TryGetProperty<ITextDocument>(
                typeof(ITextDocument), out document);

            if (result)
            {
                string documentFullPath = document.FilePath;
                recordFullPath = documentFullPath + ".rec";
            }
            else
            {
                // TODO: save to some folder
                recordFullPath = "document.rec";
            }

            // subscribe to RecorderControl event
            RecorderControl.RecordStateChanged += new EventHandler<RecordStateChangedArgs>(OnRecordStateChanged);
        }
 public static void Register(IVsTextView interopTextView, IWpfTextView textView, Services services)
 {
     var dispatcher = new StandardCommandDispatcher();
     dispatcher._textView = textView;
     dispatcher._services = services;
     interopTextView.AddCommandFilter(dispatcher, out dispatcher._commandChain);
 }
        private static bool FindConfigLine(IVsTextView configTextView, out int configLineIndex, out string configLineText)
        {
            configLineText = null;

            for (configLineIndex = 0;
                 String.IsNullOrWhiteSpace(configLineText);
                 configLineIndex++)
            {
                int hr = configTextView.GetTextStream(
                    configLineIndex,
                    0,
                    configLineIndex + 1,
                    0,
                    out configLineText);

                if (hr != VSConstants.S_OK || configLineText == null)
                {
                    break;
                }

                if (IsConfigLine(configLineText))
                {
                    return true;
                }
            }

            configLineIndex = -1;
            configLineText = null;
            return false;
        }
        /// <summary>
        /// Creates a plugin instance when a new text editor is opened
        /// </summary>
        public void VsTextViewCreated(IVsTextView adapter)
        {
            IWpfTextView view = adapterFactory.GetWpfTextView(adapter);
            if (view == null)
                return;

            ITextDocument document;
            if (!docFactory.TryGetTextDocument(view.TextDataModel.DocumentBuffer, out document))
                return;

            IObjectWithSite iows = adapter as IObjectWithSite;
            if (iows == null)
                return;

            System.IntPtr p;
            iows.GetSite(typeof(IServiceProvider).GUID, out p);
            if (p == System.IntPtr.Zero)
                return;

            IServiceProvider isp = Marshal.GetObjectForIUnknown(p) as IServiceProvider;
            if (isp == null)
                return;

            ServiceProvider sp = new ServiceProvider(isp);
            DTE dte = sp.GetService(typeof(DTE)) as DTE;
            sp.Dispose();

            new Plugin(view, document, dte);
        }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);
            textView.Closed += TextviewClosed;

            // Both "Web Compiler" and "Bundler & Minifier" extensions add this property on their
            // generated output files. Generated output should be ignored from linting
            bool generated;
            if (textView.Properties.TryGetProperty("generated", out generated) && generated)
                return;

            if (TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out _document))
            {
                Task.Run(async () =>
                {
                    if (!LinterService.IsFileSupported(_document.FilePath))
                        return;

                    _document.FileActionOccurred += DocumentSaved;
                    textView.Properties.AddProperty("lint_filename", _document.FilePath);

                    // Don't run linter again if error list already contains errors for the file.
                    if (!TableDataSource.Instance.HasErrors(_document.FilePath))
                    {
                        await LinterService.LintAsync(false, _document.FilePath);
                    }
                });
            }
        }
示例#16
0
 public override TypeAndMemberDropdownBars CreateDropDownHelper(IVsTextView forView)
 {
     var fileNode = GlobalServices.GetFileNodeForView(forView);
     if (fileNode == null)
         return null;
     return new BooTypeAndMemberDropdownBars(this, fileNode);
 }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            textView.Properties.GetOrCreateSingletonProperty(() => new GoToDefinitionCommandTarget(textViewAdapter, textView, GoToDefinitionProviderService, ServiceProvider));
            textView.Properties.GetOrCreateSingletonProperty(() => new OpenIncludeFileCommandTarget(textViewAdapter, textView, ServiceProvider, SourceTextFactory));
        }
 public virtual void Dispose() {
     EndTemplateEditing(true);
     this.source = null;
     this.vsExpansion = null;
     this.view = null;
     GC.SuppressFinalize(this);
 }
示例#19
0
        internal TypeCharFilter(IVsTextView adapter, ITextView textView, TypingSpeedMeter adornment)
        {
            this.textView = textView;
            this.adornment = adornment;

            adapter.AddCommandFilter(this, out nextCommandHandler);
        }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            textView.Properties.GetOrCreateSingletonProperty(() => new MinifySelection(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty(() => new JavaScriptFindReferences(textViewAdapter, textView, Navigator));
            textView.Properties.GetOrCreateSingletonProperty(() => new ExtractToFile(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty(() => new NodeModuleGoToDefinition(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty(() => new ReferenceTagGoToDefinition(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty(() => new CommentCompletionCommandTarget(textViewAdapter, textView, AggregatorService));
            textView.Properties.GetOrCreateSingletonProperty(() => new CommentIndentationCommandTarget(textViewAdapter, textView, AggregatorService, CompletionBroker));

            ITextDocument document;
            if (TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out document))
            {
                if (ProjectHelpers.GetProjectItem(document.FilePath) == null)
                    return;

                var jsHintLintInvoker = new LintFileInvoker(f => new JavaScriptLintReporter(new JsHintCompiler(), f), document);
                textView.Closed += (s, e) => jsHintLintInvoker.Dispose();

                textView.TextBuffer.Properties.GetOrCreateSingletonProperty(() => jsHintLintInvoker);

                var jsCodeStyleLintInvoker = new LintFileInvoker(f => new JavaScriptLintReporter(new JsCodeStyleCompiler(), f), document);
                textView.Closed += (s, e) => jsCodeStyleLintInvoker.Dispose();

                textView.TextBuffer.Properties.GetOrCreateSingletonProperty(() => jsCodeStyleLintInvoker);
            }
        }
        public VsInteractiveWindowCommandFilter(IVsEditorAdaptersFactoryService adapterFactory, IInteractiveWindow window, IVsTextView textViewAdapter, IVsTextBuffer bufferAdapter, IEnumerable<Lazy<IVsInteractiveWindowOleCommandTargetProvider, ContentTypeMetadata>> oleCommandTargetProviders, IContentTypeRegistryService contentTypeRegistry)
        {
            _window = window;
            _oleCommandTargetProviders = oleCommandTargetProviders;
            _contentTypeRegistry = contentTypeRegistry;

            this.textViewAdapter = textViewAdapter;

            // make us a code window so we'll have the same colors as a normal code window.
            IVsTextEditorPropertyContainer propContainer;
            ErrorHandler.ThrowOnFailure(((IVsTextEditorPropertyCategoryContainer)textViewAdapter).GetPropertyCategory(Microsoft.VisualStudio.Editor.DefGuidList.guidEditPropCategoryViewMasterSettings, out propContainer));
            propContainer.SetProperty(VSEDITPROPID.VSEDITPROPID_ViewComposite_AllCodeWindowDefaults, true);
            propContainer.SetProperty(VSEDITPROPID.VSEDITPROPID_ViewGlobalOpt_AutoScrollCaretOnTextEntry, true);

            // editor services are initialized in textViewAdapter.Initialize - hook underneath them:
            _preEditorCommandFilter = new CommandFilter(this, CommandFilterLayer.PreEditor);
            ErrorHandler.ThrowOnFailure(textViewAdapter.AddCommandFilter(_preEditorCommandFilter, out _editorCommandFilter));

            textViewAdapter.Initialize(
                (IVsTextLines)bufferAdapter,
                IntPtr.Zero,
                (uint)TextViewInitFlags.VIF_HSCROLL | (uint)TextViewInitFlags.VIF_VSCROLL | (uint)TextViewInitFlags3.VIF_NO_HWND_SUPPORT,
                new[] { new INITVIEW { fSelectionMargin = 0, fWidgetMargin = 0, fVirtualSpace = 0, fDragDropMove = 1 } });

            // disable change tracking because everything will be changed
            var textViewHost = adapterFactory.GetWpfTextViewHost(textViewAdapter);

            _preLanguageCommandFilter = new CommandFilter(this, CommandFilterLayer.PreLanguage);
            ErrorHandler.ThrowOnFailure(textViewAdapter.AddCommandFilter(_preLanguageCommandFilter, out _editorServicesCommandFilter));

            _textViewHost = textViewHost;
        }
        public void Attach(IVsTextView textViewAdapter)
        {
            // Try loading only once since this is a heavy operation.
              if (_loaded)
            return;
              _loaded = true;

              var shell = _serviceProvider.GetService(typeof(SVsShell)) as IVsShell;
              if (shell == null)
            return;

              IVsPackage package = null;
              var packageToBeLoadedGuid = new Guid(GuidList.GuidVsChromiumPkgString);
              shell.LoadPackage(ref packageToBeLoadedGuid, out package);

              // Ensure document is seen as loaded - This is necessary for the first
              // opened editor because the document is open before the package has a
              // chance to listen to TextDocumentFactoryService events.
              var textView = _adaptersFactoryService.GetWpfTextView(textViewAdapter);
              if (textView != null) {
            foreach (var buffer in textView.BufferGraph.GetTextBuffers(x => true)) {
              ITextDocument textDocument;
              if (_textDocumentFactoryService.TryGetTextDocument(buffer, out textDocument)) {
            _textDocumentService.OnDocumentOpen(textDocument);
              }
            }
              }
        }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var view = textViewAdapter.ToITextView();
            var filePath = textViewAdapter.GetFilePath();

            var project = ProjectInfo.FindProject(filePath);
            if (project == null)
                return;

            var engine = project.Engine;
            if (engine.IsExtensionRegistered(Path.GetExtension(filePath))
                || engine.HasSourceChangedSubscribers(Location.GetFileIndex(filePath)))
            {
                //Trace.WriteLine("Opened: " + filePath);

                IVsTextLines vsTextLines = textViewAdapter.GetBuffer();
                var langSrv = NemerlePackage.GetGlobalService(typeof(NemerleLanguageService)) as NemerleLanguageService;
                if (langSrv == null)
                    return;
                var source = (NemerleSource)langSrv.GetOrCreateSource(vsTextLines);
              source.AddRef();
                project.AddEditableSource(source);

                if (!Utils.IsNemerleFileExtension(filePath))
                    view.TextBuffer.Changed += TextBuffer_Changed;
                view.Closed += view_Closed;
            }
        }
示例#24
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            textView.Options.SetOptionValue(DefaultOptions.IndentSizeOptionId, 2);
            textView.Options.SetOptionValue(DefaultOptions.ConvertTabsToSpacesOptionId, true);
        }
 public void VsTextViewCreated(IVsTextView textViewAdapter)
 {
     var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);
     var completionModelManager = CompletionModelManagerProvider.GetCompletionModel(textView);
     textView.Properties.GetOrCreateSingletonProperty(() => new CompletionCommandHandlerTriggers(textViewAdapter, textView, completionModelManager));
     textView.Properties.GetOrCreateSingletonProperty(() => new CompletionCommandHandler(textViewAdapter, textView, completionModelManager));
 }
 public void VsTextViewCreated(IVsTextView textViewAdapter)
 {
     var commandFilter = new EditorCommandFilter(serviceProvider: this.serviceProvider);
     IOleCommandTarget nextTarget;
     ErrorHandler.ThrowOnFailure(textViewAdapter.AddCommandFilter(commandFilter, out nextTarget));
     commandFilter.NextCommandTarget = nextTarget;
 }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView textView = editorFactory.GetWpfTextView(textViewAdapter);

            if (textView != null)
                AddCommandFilter(textViewAdapter, new MultiPointEditCommandFilter(textView));
        }
示例#28
0
        void IVsTextViewCreationListener.VsTextViewCreated(IVsTextView vsView)
        {
            var view = _adaptersFactory.GetWpfTextView(vsView);
            if (view == null)
            {
                return;
            }

            var opt = _vim.GetBuffer(view);
            if (!opt.IsSome())
            {
                return;
            }

            var buffer = opt.Value;
            var broker = _displayWindowBrokerFactoryServcie.CreateDisplayWindowBroker(view);
            var result = VsCommandTarget.Create(buffer, vsView, _adapter, broker, _externalEditorManager);
            if (result.IsSuccess)
            {
                _filterMap.Add(buffer, result.Value);
            }

            // Try and install the IVsFilterKeys adapter.  This cannot be done synchronously here
            // because Venus projects are not fully initialized at this state.  Merely querying
            // for properties cause them to corrupt internal state and prevents rendering of the
            // view.  Occurs for aspx and .js pages
            Action install = () => VsFilterKeysAdapter.TryInstallFilterKeysAdapter(_adapter, _editorOptionsFactoryService, buffer);

            Dispatcher.CurrentDispatcher.BeginInvoke(install, null);
        }
示例#29
0
        void IVsTextViewCreationListener.VsTextViewCreated(IVsTextView vsView)
        {
            var view = _adaptersFactory.GetWpfTextView(vsView);
            if (view == null)
            {
                return;
            }

            var opt = _vim.GetBuffer(view);
            if (!opt.IsSome())
            {
                return;
            }

            var buffer = opt.Value;
            var filter = new VsCommandFilter(buffer, vsView, _serviceProvider);
            _filterMap.Add(buffer, filter);

            // Try and install the IVsFilterKeys adapter.  This cannot be done synchronously here
            // because Venus projects are not fully initialized at this state.  Merely querying
            // for properties cause them to corrupt internal state and prevents rendering of the
            // view.  Occurs for aspx and .js pages
            Action install = () =>
                {
                    VsFilterKeysAdapter.TryInstallFilterKeysAdapter(_adapter, _editorOptionsFactoryService, buffer);
                };

            Dispatcher.CurrentDispatcher.BeginInvoke(install, null);
        }
        public async void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView view = AdaptersFactory.GetWpfTextView(textViewAdapter);
            Debug.Assert(view != null);

            int tries = 0;

            // Ugly ugly hack
            // Keep trying to register our filter until after the JSLS CommandFilter
            // is added so we can catch completion before JSLS swallows all of them.
            // To confirm this, click Debug, New Breakpoint, Break at Function, type
            // Microsoft.VisualStudio.JSLS.TextView.TextView.CreateCommandFilter,
            // then make sure that our last filter is added after that runs.
            JsCommandFilter filter = new JsCommandFilter(view, CompletionBroker, _standardClassifications);
            while (true)
            {
                IOleCommandTarget next;
                textViewAdapter.AddCommandFilter(filter, out next);
                filter.Next = next;

                if (IsJSLSInstalled(next) || ++tries > 10)
                    return;
                await Task.Delay(500);
                textViewAdapter.RemoveCommandFilter(filter);    // Remove the too-early filter and try again.
            }
        }
示例#31
0
 public CssRemoveDuplicates(IVsTextView adapter, IWpfTextView textView)
     : base(adapter, textView, CssCommandId.RemoveDuplicates)
 {
 }
示例#32
0
 public override string Goto(VSConstants.VSStd97CmdID cmd, IVsTextView textView, int line, int col, out TextSpan span)
 {
     span = new TextSpan();
     return(null);
 }
示例#33
0
 public override Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
 {
     return(null);
 }
示例#34
0
 public override TypeAndMemberDropdownBars CreateDropDownHelper(IVsTextView forView)
 {
     return(new ProbeDropDownHelper(this));
 }
示例#35
0
 public override ViewFilter CreateViewFilter(CodeWindowManager mgr, IVsTextView newView)
 {
     return(new NShaderViewFilter(this, mgr, newView));
 }
示例#36
0
 private NShaderSource GetNShaderSource(IVsTextView textView)
 {
     return(this.GetSource(textView) as NShaderSource);
 }
 public PasteImage(IVsTextView adapter, IWpfTextView textView, string fileName)
     : base(adapter, textView, VSConstants.VSStd97CmdID.Paste)
 {
     _fileName = fileName;
     //WebEssentialsPackage.DTE.Events.SolutionEvents.AfterClosing += delegate { _lastPath = null; };
 }
 public CompletionController(IVsTextView adapter, ITextView textView, ICompletionBroker broker)
 {
     _textView = textView;
     _broker   = broker;
     ErrorHandler.ThrowOnFailure(adapter.AddCommandFilter(this, out _nextCommandTarget));
 }
示例#39
0
 public CssSelectBrowsers(IVsTextView adapter, IWpfTextView textView)
     : base(adapter, textView, MinifyCommandId.SelectBrowsers)
 {
     _dte = WebEssentialsPackage.DTE;
 }
示例#40
0
 private static bool GetTextViewFromFrame(IVsWindowFrame frame, out IVsTextView textView)
 {
     textView = VsShellUtilities.GetTextView(frame);
     return(textView != null);
 }
示例#41
0
 public void OnUnregisterView(IVsTextView pView)
 {
     throw new NotImplementedException();
 }
示例#42
0
 public SurroundWith(IVsTextView adapter, IWpfTextView textView)
     : base(adapter, textView, FormattingCommandId.SurroundWith)
 {
     _view   = textView;
     _buffer = textView.TextBuffer;
 }
示例#43
0
 public int OnNewView(IVsTextView pView)
 {
     // NO-OP We use IVsCodeWindowEvents to track text view lifetime
     return(VSConstants.S_OK);
 }
示例#44
0
 public RemoveDuplicateLines(IVsTextView adapter, IWpfTextView textView)
     : base(adapter, textView, LinesCommandId.RemoveDuplicateLines)
 {
 }
示例#45
0
 private void TeardownView(IVsTextView view)
 {
 }
        /// <summary>
        /// This function is called whenever a new item to edit is opened
        /// </summary>
        /// <param name="textViewAdapter">adapter of the text view (given by the VS itself [MEF] )</param>
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            if (!runFlag)
            {
                cb = CoProgrammerPackage.cb;// gets current network object
                if (cb == null)
                {
                    cb = new CoProNetwork();//if null create new
                    CoProgrammerPackage.cb = cb;
                }
                ToolWindowPane window = CoProgrammerPackage.currRunning.FindToolWindow(typeof(CoProToolWindow), 0, true);
                if ((null == window) || (null == window.Frame))
                {
                    throw new NotSupportedException(Resources.CanNotCreateWindow);
                }
                gobj = new GraphicObjects(GetCurrentViewHost(textViewAdapter), cb, (CoProExplorer)window.Content);
                gobj.CoProExplorer.SetConnection(cb); //updates co pro explorer window
                if (isFirst)                          // on opening the solution
                {
                    se                 = ((Events2)gobj.DTE2.Events).SolutionEvents;
                    de                 = ((Events2)gobj.DTE2.Events).DebuggerEvents;
                    se.Opened         += SubscribeGlobalEvents;                                     //solution opened event
                    de.OnEnterRunMode += new _dispDebuggerEvents_OnEnterRunModeEventHandler(OnRun); //when running the code event
                    bool setAdminConfiguraions = false;
                    var  slnName   = gobj.DTE2.Solution.FullName;
                    var  adminFile = slnName.Substring(0, slnName.Substring(0, slnName.LastIndexOf('\\')).LastIndexOf('\\')) + "\\admin.txt";
                    //IF THERE IS ADMIN INFO
                    if (File.Exists(adminFile))//internal file that was created
                    {
                        StreamReader sr  = new StreamReader(adminFile);
                        string       dir = sr.ReadToEnd();
                        if (dir.Split('\n')[0] == slnName.Substring(0, slnName.LastIndexOf('\\')))
                        {
                            CoProgrammerPackage.service = new CoProServer();// runs the server
                            string filesDir = slnName.Substring(0, slnName.LastIndexOf('\\')) + "\\CoProFiles";
                            if (!Directory.Exists(filesDir))
                            {
                                Directory.CreateDirectory(slnName.Substring(0, slnName.LastIndexOf('\\')) + "\\CoProFiles");
                            }
                            string        path = slnName.Substring(0, slnName.LastIndexOf('\\'));
                            XElement      xe   = CoProgrammerPackage.CreateFileSystemXmlTree(path, 1, path.Substring(path.LastIndexOf('\\') + 1));
                            XmlTextWriter xwr  = new XmlTextWriter(path + "\\CoProFiles\\timestamps.xml", System.Text.Encoding.UTF8);// timestamps file creation
                            xwr.Formatting = Formatting.Indented;
                            xe.WriteTo(xwr);
                            xwr.Close();
                            FileStream fs     = File.Create(slnName.Substring(0, slnName.LastIndexOf('\\')) + "\\CoProFiles\\client.txt");
                            string     ipPort = "localhost:" + (CoProgrammerPackage.service.PortOfService() + 10).ToString() + ":" + dir.Split('\n')[1];
                            fs.Write(Encoding.ASCII.GetBytes(ipPort), 0, ipPort.Length);// creating client file if there is no one exsisting
                            fs.Close();
                            setAdminConfiguraions = true;
                        }
                    }
                    //IF THERE IS A CLIENT INFO
                    if (File.Exists(slnName.Substring(0, slnName.LastIndexOf('\\')) + "\\CoProFiles\\client.txt"))// internal client info file
                    {
                        StreamReader sr        = new StreamReader(slnName.Substring(0, slnName.LastIndexOf('\\')) + "\\CoProFiles\\client.txt");
                        string       iportName = sr.ReadToEnd();
                        cb.SetIpPort(iportName.Split(':')[0], iportName.Split(':')[1]);
                        cb.Name = iportName.Split(':')[2]; // configurates the class accoridng to info in file
                        if (cb.Connect())                  // attempt to connect
                        {
                            cb.ProjPath = slnName.Substring(0, slnName.LastIndexOf('\\'));
                            if (setAdminConfiguraions)
                            {
                                if (cb.SetAdmin(true))
                                {
                                    cb.IsAdmin = true;// if is admin, he gets the access to some funcitons
                                    cb.SetProjectDir(slnName.Substring(0, slnName.LastIndexOf('\\')));
                                }
                            }
                            else
                            {
                                cb.IsAdmin = false;
                                cb.UpdateProject();// updates project for regular clients
                            }
                            if (cb.IsAdmin)
                            {
                                cb.ExpectedSequence++;       // +1 to current count toget next messages
                            }
                            gobj.CoProExplorer.UpdateInfo(); // updates window info
                        }
                    }
                    else
                    {
                        cb   = null;
                        gobj = null;
                    }
                    isFirst = false;
                }

                IWpfTextView textView = editorFactory.GetWpfTextView(textViewAdapter);//gets the text view
                if (textView == null)
                {
                    return;
                }
                AddCommandFilter(textViewAdapter, new CoProCommandFilter(textView, cb, gobj));//adds an instance of our command filter to the text view
            }
            runFlag = false;
        }
示例#47
0
            public int OnNewView(IVsTextView view)
            {
                SetupView(view);

                return(VSConstants.S_OK);
            }
示例#48
0
        private static IVsCodeWindow TryGetCodeWindow(IVsTextView textView)
        {
            if (textView == null)
            {
                throw new ArgumentNullException(nameof(textView));
            }

            if (!(textView is IObjectWithSite objectWithSite))
            {
                return(null);
            }

            var riid = typeof(IOleServiceProvider).GUID;

            objectWithSite.GetSite(ref riid, out var ppvSite);
            if (ppvSite == IntPtr.Zero)
            {
                return(null);
            }

            IOleServiceProvider oleServiceProvider = null;

            try
            {
                oleServiceProvider = Marshal.GetObjectForIUnknown(ppvSite) as IOleServiceProvider;
            }
            finally
            {
                Marshal.Release(ppvSite);
            }

            if (oleServiceProvider == null)
            {
                return(null);
            }

            var guidService = typeof(SVsWindowFrame).GUID;

            riid = typeof(IVsWindowFrame).GUID;
            if (ErrorHandler.Failed(oleServiceProvider.QueryService(ref guidService, ref riid, out var ppvObject)) || ppvObject == IntPtr.Zero)
            {
                return(null);
            }

            IVsWindowFrame frame = null;

            try
            {
                frame = Marshal.GetObjectForIUnknown(ppvObject) as IVsWindowFrame;
            }
            finally
            {
                Marshal.Release(ppvObject);
            }

            riid = typeof(IVsCodeWindow).GUID;
            if (ErrorHandler.Failed(frame.QueryViewInterface(ref riid, out ppvObject)) || ppvObject == IntPtr.Zero)
            {
                return(null);
            }

            try
            {
                return(Marshal.GetObjectForIUnknown(ppvObject) as IVsCodeWindow);
            }
            finally
            {
                Marshal.Release(ppvObject);
            }
        }
示例#49
0
 public IWpfTextViewHost GetWpfTextViewHost(IVsTextView viewAdapter)
 {
     throw new NotImplementedException();
 }
示例#50
0
 private void SetupView(IVsTextView view)
 {
     _languageService.SetupNewTextView(view);
 }
示例#51
0
        public GoToDefinitionInterceptor(IEnumerable <IReferenceSourceProvider> references, IServiceProvider sp, IVsTextView adapter, IWpfTextView textView, ITextDocument doc) : base(adapter, textView, VSConstants.VSStd97CmdID.GotoDefn)
        {
            this.references = references;
            this.doc        = doc;

            var dte = (DTE)sp.GetService(typeof(DTE));

            // Dev12 (VS2013) has the new simpler native API
            // Dev14, and Dev12 with Roslyn preview, will have Roslyn
            // All other versions need ParseTreeNodes
            if (new Version(dte.Version).Major > 12 ||
                textView.BufferGraph.GetTextBuffers(tb => tb.ContentType.IsOfType("Roslyn Languages")).Any())
            {
                RoslynAssemblyRedirector.Register();
                resolvers.Add("CSharp", CreateRoslynResolver());
                resolvers.Add("Basic", CreateRoslynResolver());
            }
            else
            {
                resolvers.Add("Basic", new VBResolver());

                if (dte.Version == "12.0")
                {
                    resolvers.Add("CSharp", new CSharp12Resolver());
                }
                else
                {
                    resolvers.Add("CSharp", new CSharp10Resolver(dte));
                }
            }
        }
示例#52
0
            public int OnCloseView(IVsTextView view)
            {
                TeardownView(view);

                return(VSConstants.S_OK);
            }
        public bool Save(string configPath, string bindingsXml)
        {
            bindingsXml = bindingsXml.Replace("\u200B", string.Empty);

            XElement bindingsXmlObject = XElement.Parse(bindingsXml);
            JObject  bindingsXmlBody   = JObject.Parse(@"{}");
            bool     anyAdded          = false;

            foreach (XAttribute attribute in bindingsXmlObject.Attributes())
            {
                JArray type = new JArray();
                bindingsXmlBody[attribute.Name.LocalName] = type;
                string[] tasks = attribute.Value.Split(',');

                foreach (string task in tasks)
                {
                    anyAdded = true;
                    type.Add(task.Trim());
                }
            }

            IVsTextView configTextView = TextViewUtil.FindTextViewFor(configPath);
            ITextUtil   textUtil;

            if (configTextView != null)
            {
                textUtil = new VsTextViewTextUtil(configTextView);
            }
            else
            {
                textUtil = new FileTextUtil(configPath);
            }

            string    currentContents = textUtil.ReadAllText();
            JObject   fileModel       = JObject.Parse(currentContents);
            bool      commaRequired   = fileModel.Properties().Any();
            JProperty currentBindings = fileModel.Property(BindingsName);
            bool      insert          = currentBindings == null;

            fileModel[BindingsName] = bindingsXmlBody;

            JProperty property    = fileModel.Property(BindingsName);
            string    bindingText = property.ToString(Formatting.None);

            textUtil.Reset();

            if (!anyAdded)
            {
                insert = false;
            }

            if (insert)
            {
                if (commaRequired)
                {
                    bindingText = ", " + bindingText;
                }

                string line;
                int    lineNumber = 0, candidateLine = -1, lastBraceIndex = -1, characterCount = 0;
                while (textUtil.TryReadLine(out line))
                {
                    if (!string.IsNullOrWhiteSpace(line))
                    {
                        int brace = line.LastIndexOf('}');
                        if (brace >= 0)
                        {
                            lastBraceIndex = brace;
                            candidateLine  = lineNumber;
                        }
                    }

                    characterCount += line?.Length ?? 0;
                    ++lineNumber;
                }

                if (candidateLine >= 0 && lastBraceIndex >= 0)
                {
                    if (textUtil.Insert(new Range {
                        LineNumber = candidateLine, LineRange = new LineRange {
                            Start = lastBraceIndex, Length = bindingText.Length
                        }
                    }, bindingText, true))
                    {
                        textUtil.FormatRange(new LineRange {
                            Start = characterCount, Length = bindingText.Length
                        });
                        return(true);
                    }
                }

                return(false);
            }

            int bindingsIndex      = currentContents.IndexOf(@"""" + BindingsName + @"""", StringComparison.Ordinal);
            int closeBindingsBrace = currentContents.IndexOf('}', bindingsIndex) + 1;
            int length             = closeBindingsBrace - bindingsIndex;

            int startLine, startLineOffset, endLine, endLineOffset;

            textUtil.GetExtentInfo(bindingsIndex, length, out startLine, out startLineOffset, out endLine, out endLineOffset);

            if (!anyAdded)
            {
                int previousComma = currentContents.LastIndexOf(',', bindingsIndex);
                int tail          = 0;

                if (previousComma > -1)
                {
                    tail += bindingsIndex - previousComma;
                    textUtil.GetExtentInfo(previousComma, length, out startLine, out startLineOffset, out endLine, out endLineOffset);
                }

                if (textUtil.Delete(new Range {
                    LineNumber = startLine, LineRange = new LineRange {
                        Start = startLineOffset, Length = length + tail
                    }
                }))
                {
                    textUtil.Reset();
                    textUtil.FormatRange(new LineRange {
                        Start = bindingsIndex, Length = 2
                    });
                    return(true);
                }

                return(false);
            }

            bool success = textUtil.Replace(new Range {
                LineNumber = startLine, LineRange = new LineRange {
                    Start = startLineOffset, Length = length
                }
            }, bindingText);

            if (success)
            {
                textUtil.FormatRange(new LineRange {
                    Start = bindingsIndex, Length = bindingText.Length
                });
            }

            return(success);
        }
示例#54
0
 public override Microsoft.VisualStudio.Package.Declarations GetDeclarations(IVsTextView view, int line,
                                                                             int col, TokenInfo info, ParseReason reason)
 {
     return(Declarations);
 }
 public CssAddMissingVendor(IVsTextView adapter, IWpfTextView textView)
     : base(adapter, textView, CssCommandId.AddMissingVendor)
 {
 }
示例#56
0
 public CssFindReferences(IVsTextView adapter, IWpfTextView textView)
     : base(adapter, textView, typeof(VSConstants.VSStd97CmdID).GUID, (uint)VSConstants.VSStd97CmdID.FindReferences)
 {
     _dte = EditorExtensionsPackage.DTE;
 }
示例#57
0
        public static void OpenDocument(IServiceProvider serviceProvider, string filename, out IVsTextView viewAdapter, out IVsWindowFrame pWindowFrame)
        {
            IVsTextManager textMgr = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager));

            IVsUIHierarchy hierarchy;
            uint           itemid;

            VsShellUtilities.OpenDocument(
                serviceProvider,
                filename,
                Guid.Empty,
                out hierarchy,
                out itemid,
                out pWindowFrame,
                out viewAdapter);
        }
示例#58
0
 /// <summary>
 /// Get the secondary view of the code window.  Is actually the one on top
 /// </summary>
 internal static bool TryGetSecondaryView(this IVsCodeWindow codeWindow, out IVsTextView textView)
 {
     return(ErrorHandler.Succeeded(codeWindow.GetSecondaryView(out textView)) && textView != null);
 }
示例#59
0
 public int GetActiveView2(int fMustHaveFocus, IVsTextBuffer pBuffer, uint grfIncludeViewFrameType, out IVsTextView ppView)
 {
     throw new NotImplementedException();
 }
示例#60
0
        public static void OpenDocument(IServiceProvider serviceProvider, string filename, Guid docViewGuid, out IVsTextView viewAdapter, out IVsWindowFrame pWindowFrame)
        {
            IVsUIHierarchy hierarchy;
            uint           itemid;

            VsShellUtilities.OpenDocumentWithSpecificEditor(
                serviceProvider,
                filename,
                docViewGuid,
                Guid.Empty,
                out hierarchy,
                out itemid,
                out pWindowFrame
                );
            viewAdapter = VsShellUtilities.GetTextView(pWindowFrame);
        }