public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            if (!DocumentService.TryGetTextDocument(textView.TextBuffer, out ITextDocument doc))
            {
                return;
            }

            string fileName = Path.GetFileName(doc.FilePath);

            if (!fileName.Equals(Constants.ConfigFileName, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            new CompletionController(textViewAdapter, textView, CompletionBroker);


            _dependencies = Dependencies.FromConfigFile(doc.FilePath);
            _manifest     = Manifest.FromFileAsync(doc.FilePath, _dependencies, CancellationToken.None).Result;
            _manifestPath = doc.FilePath;
            _project      = VsHelpers.GetDTEProjectFromConfig(_manifestPath);

            if (_manifest == null)
            {
                AddErrorToList(PredefinedErrors.ManifestMalformed());
            }

            doc.FileActionOccurred += OnFileSaved;
            textView.Closed        += OnViewClosed;
        }
Example #2
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            textView.Properties.GetOrCreateSingletonProperty <CssSortProperties>(() => new CssSortProperties(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty <CssExtractToFile>(() => new CssExtractToFile(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty <CssAddMissingStandard>(() => new CssAddMissingStandard(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty <CssAddMissingVendor>(() => new CssAddMissingVendor(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty <CssRemoveDuplicates>(() => new CssRemoveDuplicates(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty <MinifySelection>(() => new MinifySelection(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty <CssFindReferences>(() => new CssFindReferences(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty <F1Help>(() => new F1Help(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty <CssSelectBrowsers>(() => new CssSelectBrowsers(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty <RetriggerTarget>(() => new RetriggerTarget(textViewAdapter, textView, CompletionBroker));

            uint cssFormatProperties;

            EditorExtensionsPackage.PriorityCommandTarget.RegisterPriorityCommandTarget(0, new CssFormatProperties(textView), out cssFormatProperties);
            textView.Closed += delegate { EditorExtensionsPackage.PriorityCommandTarget.UnregisterPriorityCommandTarget(cssFormatProperties); };

            uint cssSpeedTyping;

            EditorExtensionsPackage.PriorityCommandTarget.RegisterPriorityCommandTarget(0, new SpeedTypingTarget(this, textViewAdapter, textView), out cssSpeedTyping);
            textView.Closed += delegate { EditorExtensionsPackage.PriorityCommandTarget.UnregisterPriorityCommandTarget(cssSpeedTyping); };
        }
Example #3
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            if (_hasRun || _isProcessing)
            {
                return;
            }

            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            ITextDocument doc;

            if (TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out doc))
            {
                if (Path.IsPathRooted(doc.FilePath) && File.Exists(doc.FilePath))
                {
                    _isProcessing = true;
                    var dte  = (DTE2)Package.GetGlobalService(typeof(DTE));
                    var item = dte.Solution?.FindProjectItem(doc.FilePath);

                    System.Threading.Tasks.Task.Run(() =>
                    {
                        EnsureInitialized(item);
                        _hasRun = _isProcessing = false;
                    });
                }
            }
        }
        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));
        }
Example #5
0
        /// <summary>
        /// Called when a IVsTextView adapter has been created and initialized.
        /// </summary>
        /// <param name="textViewAdapter">The newly created and initialized text view adapter.</param>
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView textView    = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);
            ViewContext  context     = new ViewContext(textView, textViewAdapter);
            string       contentType = textView.TextBuffer.ContentType.TypeName;

            // As of v2019 Visual Studio does not use projection buffer for JSX files and thus we cannot
            // detect JS and HTML buffers. So, in order to prevent unintended JS and Emmet snippets
            // collisions we require prefix for emmet abbreviations to work correctly.
            if (contentType.EndsWith("script", StringComparison.InvariantCultureIgnoreCase))
            {
                context.AbbreviationPrefix = JsxPrefix;
            }

            if ("CSharp" != contentType)
            {
                EmmetCommandTarget target = textView.Properties.GetOrCreateSingletonProperty(
                    "EmmetCommandTarget",
                    () => new EmmetCommandTarget(context, CompletionBroker));
            }
            else
            {
                textView.Properties.GetOrCreateSingletonProperty(
                    "ZenSharpCommandTarget",
                    () => new ZenSharpCommandTarget(context, CompletionBroker));
            }
        }
Example #6
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (_hasRun || _isProcessing)
            {
                return;
            }

            IWpfTextView textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);


            if (TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out ITextDocument doc))
            {
                if (Path.IsPathRooted(doc.FilePath) && File.Exists(doc.FilePath))
                {
                    _isProcessing = true;
                    var         dte  = (DTE2)Package.GetGlobalService(typeof(DTE));
                    ProjectItem item = dte.Solution?.FindProjectItem(doc.FilePath);

                    ThreadHelper.JoinableTaskFactory.Run(async() =>
                    {
                        await EnsureInitializedAsync(item);
                        _hasRun = _isProcessing = false;
                    });
                }
            }
        }
Example #7
0
        public void VsTextViewCreated(Microsoft.VisualStudio.TextManager.Interop.IVsTextView textViewAdapter)
        {
            ITextDocument       document;
            RobotsTxtClassifier classifier;

            var view = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            if (TextDocumentFactoryService.TryGetTextDocument(view.TextDataModel.DocumentBuffer, out document))
            {
                TextType type = GetTextType(document.FilePath);
                if (type == TextType.Unsupported)
                {
                    return;
                }

                view.TextDataModel.DocumentBuffer.Properties.TryGetProperty(typeof(RobotsTxtClassifier), out classifier);
                view.Properties.GetOrCreateSingletonProperty(() => new CommentCommandTarget(textViewAdapter, view, "#"));

                if (classifier != null)
                {
                    ITextSnapshot snapshot = view.TextBuffer.CurrentSnapshot;
                    classifier.OnClassificationChanged(new SnapshotSpan(snapshot, 0, snapshot.Length), type);
                }
            }
        }
        /// <summary>
        /// Called when a <see cref="T:Microsoft.VisualStudio.TextManager.Interop.IVsTextView" /> adapter has
        /// been created and initialized.
        /// </summary>
        /// <param name="textViewAdapter">The newly created and initialized text view adapter.</param>
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            textView.Properties.GetOrCreateSingletonProperty(
                () => new ViewCommandFilter(textView, textViewAdapter, CompletionBroker, Syntax));
        }
Example #9
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView   = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);
            var classifier = ClassifierService.GetClassifier(textView.TextBuffer);

            AddCommandFilter(textViewAdapter, new ExpandCommand(textView, CompletionBroker, UndoProvider, classifier));
        }
Example #10
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            textView.Closed += TextviewClosed;

            if (TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out _document))
            {
                if (!LinterService.IsFileSupported(_document.FilePath))
                {
                    return;
                }

                WebLinterPackage.Dispatcher.BeginInvoke(new Action(() =>
                {
                    _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))
                    {
                        LinterService.Lint(false, _document.FilePath);
                    }
                }), DispatcherPriority.ApplicationIdle, null);
            }
        }
Example #11
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            DTE2         dte      = serviceProvider.GetService(typeof(DTE)) as DTE2;
            IWpfTextView textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            textView.Properties.GetOrCreateSingletonProperty(() => new QuoteItCommand(textViewAdapter, textView, dte));
        }
Example #12
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            if (!DocumentService.TryGetTextDocument(textView.TextBuffer, out ITextDocument doc))
            {
                return;
            }

            string fileName = Path.GetFileName(doc.FilePath);

            if (!fileName.Equals(Constants.ConfigFileName, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            new CompletionController(textViewAdapter, textView, CompletionBroker);

            _dependencies = Dependencies.FromConfigFile(doc.FilePath);
            _manifest     = Manifest.FromFileAsync(doc.FilePath, _dependencies, CancellationToken.None).Result;
            _manifestPath = doc.FilePath;
            _project      = VsHelpers.GetDTEProjectFromConfig(_manifestPath);

            doc.FileActionOccurred += OnFileSaved;
            textView.Closed        += OnViewClosed;

            Task.Run(async() =>
            {
                IEnumerable <ILibraryOperationResult> results = await LibrariesValidator.GetManifestErrorsAsync(_manifest, _dependencies, CancellationToken.None).ConfigureAwait(false);
                if (!results.All(r => r.Success))
                {
                    AddErrorsToList(results);
                }
            });
        }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            textView.Closed += TextviewClosed;

            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.Lint(false, _document.FilePath);
                    }
                });
            }
        }
        int IVsImmediateStatementCompletion2.SetCompletionContext(string filePath,
                                                                  IVsTextLines buffer,
                                                                  Microsoft.VisualStudio.TextManager.Interop.TextSpan[] currentStatementSpan,
                                                                  object punkContext,
                                                                  IVsTextView textView)
        {
            // The immediate window is always marked read-only and the language service is
            // responsible for asking the buffer to make itself writable. We'll have to do that for
            // commit, so we need to drag the IVsTextLines around, too.
            IVsTextLines debuggerBuffer;

            Marshal.ThrowExceptionForHR(textView.GetBuffer(out debuggerBuffer));

            var view = EditorAdaptersFactoryService.GetWpfTextView(textView);

            // Sometimes, they give us a null context buffer. In that case, there's probably not any
            // work to do.
            if (buffer != null)
            {
                var contextBuffer = EditorAdaptersFactoryService.GetDataBuffer(buffer);
                var context       = CreateContext(view, textView, debuggerBuffer, contextBuffer, currentStatementSpan);
                if (context.TryInitialize())
                {
                    this.filters[textView].SetContext(context);
                }
                else
                {
                    this.filters[textView].RemoveContext();
                }
            }

            return(VSConstants.S_OK);
        }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            ITextView textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            if (textView == null)
            {
                return;
            }

            var provider = CommenterProviders.FirstOrDefault(providerInfo => providerInfo.Metadata.ContentTypes.Any(contentType => textView.TextBuffer.ContentType.IsOfType(contentType)));

            if (provider == null)
            {
                return;
            }

            var commenter = provider.Value.GetCommenter(textView);

            if (commenter == null)
            {
                return;
            }

            CommenterFilter filter = new CommenterFilter(textViewAdapter, textView, commenter);

            filter.Enabled = true;
            textView.Properties.AddProperty(typeof(CommenterFilter), filter);
        }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            textView.Properties.GetOrCreateSingletonProperty(() => new HtmlGoToDefinition(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty(() => new HtmlFindAllReferences(textViewAdapter, textView));
        }
Example #17
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            ITextDocument document;

            var view = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            if (TextDocumentFactoryService.TryGetTextDocument(view.TextDataModel.DocumentBuffer, out document))
            {
                string filePath = document.FilePath;

                if (!IsPaketLockFile(filePath))
                {
                    return;
                }

                PaketLockClassifier classifier;
                view.TextDataModel.DocumentBuffer.Properties.TryGetProperty(typeof(PaketLockClassifier), out classifier);
                view.Properties.GetOrCreateSingletonProperty(() => new CommentCommandTarget(textViewAdapter, view, "#"));

                if (classifier != null)
                {
                    ITextSnapshot snapshot = view.TextBuffer.CurrentSnapshot;
                    classifier.OnClassificationChanged(new SnapshotSpan(snapshot, 0, snapshot.Length));
                }
            }
        }
        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 CssExtractToFile(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 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);
                    }
                });
            }
        }
        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));
        }
Example #21
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView    = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);
            var contentType = textView.TextBuffer.ContentType;

            ITextDocument document;

            if (!TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out document))
            {
                return;
            }

            var settings = WESettings.Instance.ForContentType <IChainableCompilerSettings>(contentType);

            var notifierProvider = Mef.GetImport <ICompilationNotifierProvider>(contentType);

            if (notifierProvider == null)
            {
                return;
            }

            var notifier = notifierProvider.GetCompilationNotifier(document);

            var compilerProvider = Mef.GetImport <ICompilerRunnerProvider>(contentType);

            if (compilerProvider == null)
            {
                return;
            }

            var compilerRunner = compilerProvider.GetCompiler(contentType);

            var graph = GetGraph(contentType);

            notifier.CompilationReady += async(s, e) =>
            {
                if (!e.CompilerResult.IsSuccess)
                {
                    return;
                }

                if (!settings.CompileOnSave || !settings.EnableChainCompilation || (bool)s)
                {
                    return;
                }

                var count = 0;
                foreach (var file in await graph.GetRecursiveDependentsAsync(e.CompilerResult.SourceFileName))
                {
                    if (File.Exists(compilerRunner.GetTargetPath(file)))
                    {
                        compilerRunner.CompileToDefaultOutputAsync(file).DoNotWait("compiling " + file);
                        count++;
                    }
                }
                WebEssentialsPackage.DTE.StatusBar.Text = "Compiling " + count + " dependent file" + (count == 1 ? "s" : "")
                                                          + " for " + Path.GetFileName(e.CompilerResult.SourceFileName);
            };
        }
Example #22
0
        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 textView             = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);
            var signatureHelpManager = SignatureHelpManagerProvider.GetSignatureHelpManager(textView);

            textView.Properties.GetOrCreateSingletonProperty(() => new SignatureHelpCommandHandlerParamInfo(textViewAdapter, textView, signatureHelpManager));
            textView.Properties.GetOrCreateSingletonProperty(() => new SignatureHelpCommandHandlerTypeChar(textViewAdapter, textView, signatureHelpManager));
        }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            textView.Properties.GetOrCreateSingletonProperty <EncodeSelection>(() => new EncodeSelection(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty <SortSelectedLines>(() => new SortSelectedLines(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty <RemoveDuplicateLines>(() => new RemoveDuplicateLines(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty <RemoveEmptyLines>(() => new RemoveEmptyLines(textViewAdapter, textView));
        }
Example #25
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            textView.Properties.GetOrCreateSingletonProperty(() => new ZenCoding(textViewAdapter, textView, CompletionBroker));

            textView.MouseHover += textView_MouseHover;
            textView.Closed     += textView_Closed;
        }
Example #26
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var           textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);
            ITextDocument doc;

            if (TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out doc))
            {
                doc.FileActionOccurred += DocumentSaved;
            }
        }
Example #27
0
        protected virtual void SetupNewTextView(IVsTextView textView)
        {
            Contract.ThrowIfNull(textView);

            var wpfTextView = EditorAdaptersFactoryService.GetWpfTextView(textView);

            Contract.ThrowIfNull(wpfTextView, "Could not get IWpfTextView for IVsTextView");

            Debug.Assert(!wpfTextView.Properties.ContainsProperty(typeof(AbstractVsTextViewFilter)));

            var workspace = Package.ComponentModel.GetService <VisualStudioWorkspace>();

            // The lifetime of CommandFilter is married to the view
            wpfTextView.GetOrCreateAutoClosingProperty(v =>
                                                       new StandaloneCommandFilter(
                                                           v, Package.ComponentModel).AttachToVsTextView());

            var isMetadataAsSource         = false;
            var collapseAllImplementations = false;

            var openDocument = wpfTextView.TextBuffer.AsTextContainer().GetRelatedDocuments().FirstOrDefault();

            if (openDocument?.Project.Solution.Workspace is MetadataAsSourceWorkspace masWorkspace)
            {
                isMetadataAsSource = true;

                // If the file is metadata as source, and the user has the preference set to collapse them, then
                // always collapse all metadata as source
                var globalOptions = this.Package.ComponentModel.GetService <IGlobalOptionService>();
                var options       = BlockStructureOptionsStorage.GetBlockStructureOptions(globalOptions, openDocument.Project.Language, isMetadataAsSource: masWorkspace is not null);
                collapseAllImplementations = masWorkspace.FileService.ShouldCollapseOnOpen(openDocument.FilePath, options);
            }

            ConditionallyCollapseOutliningRegions(textView, wpfTextView, collapseAllImplementations);

            // If this is a metadata-to-source view, we want to consider the file read-only and prevent
            // it from being re-opened when VS is opened
            if (isMetadataAsSource && ErrorHandler.Succeeded(textView.GetBuffer(out var vsTextLines)))
            {
                Contract.ThrowIfNull(openDocument);

                ErrorHandler.ThrowOnFailure(vsTextLines.GetStateFlags(out var flags));
                flags |= (int)BUFFERSTATEFLAGS.BSF_USER_READONLY;
                ErrorHandler.ThrowOnFailure(vsTextLines.SetStateFlags(flags));

                var runningDocumentTable  = (IVsRunningDocumentTable)SystemServiceProvider.GetService(typeof(SVsRunningDocumentTable));
                var runningDocumentTable4 = (IVsRunningDocumentTable4)runningDocumentTable;

                if (runningDocumentTable4.IsMonikerValid(openDocument.FilePath))
                {
                    var cookie = runningDocumentTable4.GetDocumentCookie(openDocument.FilePath);
                    runningDocumentTable.ModifyDocumentFlags(cookie, (uint)_VSRDTFLAGS.RDT_DontAddToMRU | (uint)_VSRDTFLAGS.RDT_CantSave | (uint)_VSRDTFLAGS.RDT_DontAutoOpen, fSet: 1);
                }
            }
        }
Example #28
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            textView.Properties.GetOrCreateSingletonProperty <SurroundWith>(() => new SurroundWith(textViewAdapter, textView, CompletionBroker));
            textView.Properties.GetOrCreateSingletonProperty <ExpandSelection>(() => new ExpandSelection(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty <ContractSelection>(() => new ContractSelection(textViewAdapter, textView));
            //textView.Properties.GetOrCreateSingletonProperty<EnterFormat>(() => new EnterFormat(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty <MinifySelection>(() => new MinifySelection(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty <HtmlGoToDefinition>(() => new HtmlGoToDefinition(textViewAdapter, textView));
        }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var dte = ServiceProvider.GetService(typeof(DTE)) as DTE2;
            IWpfTextView textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            textView.Properties.GetOrCreateSingletonProperty(() => new WhitespaceRemoverCommand(textViewAdapter, textView, dte));

            if (TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out ITextDocument doc))
            {
                textView.Properties.GetOrCreateSingletonProperty(() => new RemoveWhitespaceOnSave(textViewAdapter, textView, dte, doc));
            }
        }
Example #30
0
        private IWpfTextView GetInitializedTextView(IVsTextView textViewAdapter)
        {
            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            textView.Properties.GetOrCreateSingletonProperty(() => new EncodeSelection(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty(() => new SortSelectedLines(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty(() => new RemoveDuplicateLines(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty(() => new RemoveEmptyLines(textViewAdapter, textView));
            //textView.Properties.GetOrCreateSingletonProperty(() => new CommandExceptionFilter(textViewAdapter, textView, UndoRegistry));

            return(textView);
        }