public BottomMargin(IWpfTextView textView, IClassifierAggregatorService classifier, ITextDocumentFactoryService documentService)
        {
            _textView = textView;
            _classifier = classifier.GetClassifier(textView.TextBuffer);
            _foregroundBrush = new SolidColorBrush((Color)FindResource(VsColors.CaptionTextKey));
            _backgroundBrush = new SolidColorBrush((Color)FindResource(VsColors.ScrollBarBackgroundKey));

            this.Background = _backgroundBrush;
            this.ClipToBounds = true;

            _lblEncoding = new TextControl("Encoding");
            this.Children.Add(_lblEncoding);

            _lblContentType = new TextControl("Content type");
            this.Children.Add(_lblContentType);

            _lblClassification = new TextControl("Classification");
            this.Children.Add(_lblClassification);

            _lblSelection = new TextControl("Selection");
            this.Children.Add(_lblSelection);

            UpdateClassificationLabel();
            UpdateContentTypeLabel();
            UpdateContentSelectionLabel();

            if (documentService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out _doc))
            {
                _doc.FileActionOccurred += FileChangedOnDisk;
                UpdateEncodingLabel(_doc);
            }

            textView.Caret.PositionChanged += CaretPositionChanged;
        }
Exemplo n.º 2
0
        private void MonitorDocumentForRenames(ITextBuffer textBuffer)
        {
            if (!_textDocumentFactory.TryGetTextDocument(textBuffer, out var textDocument))
            {
                // Cannot monitor buffers that don't have an associated text document. In practice, this should never happen but being extra defensive here.
                return;
            }

            textDocument.FileActionOccurred += TextDocument_FileActionOccurred;
        }
Exemplo n.º 3
0
        public virtual bool IsDirty(ITextBuffer textbuffer)
        {
            ITextDocument document;

            if (!_textDocumentFactoryService.TryGetTextDocument(textbuffer, out document))
            {
                return(false);
            }

            return(document.IsDirty);
        }
Exemplo n.º 4
0
        internal void OnSubjectBufferConnected(ITextView textView, ITextBuffer textBuffer)
        {
            // Add this ITextView to the list of known views for this buffer.
            _textBufferToViewsMap.GetOrCreateValue(textBuffer).Add(textView);
            _textViewToBuffersMap.GetOrCreateValue(textView).Add(textBuffer);

            // Do we already know about this text buffer?
            if (_textBufferToDocumentIdMap.TryGetValue(textBuffer, out var _))
            {
                return;
            }

            // If this is the disk buffer, get the associated ITextDocument.
            if (_textDocumentFactoryService.TryGetTextDocument(textBuffer, out var textDocument))
            {
                _textBufferToTextDocumentMap.Add(textBuffer, textDocument);

                // TODO: hookup textDocument.FileActionOccurred for renames.
            }

            var debugName  = textDocument?.FilePath ?? "EmbeddedBuffer"; // TODO: Use more useful name based on projection buffer hierarchy.
            var documentId = DocumentId.CreateNewId(debugName);

            _textBufferToDocumentIdMap.Add(textBuffer, documentId);

            var textContainer = textBuffer.AsTextContainer();

            var document = CreateDocument(
                documentId,
                textBuffer.ContentType.TypeName,
                textContainer.CurrentText,
                textDocument?.FilePath);

            OnDocumentOpened(document);
        }
        public override bool TryGetProjectPath(ITextBuffer textBuffer, out string filePath)
        {
            if (!_liveShareSessionAccessor.IsGuestSessionActive)
            {
                filePath = null;
                return(false);
            }

            if (!_textDocumentFactory.TryGetTextDocument(textBuffer, out var textDocument))
            {
                filePath = null;
                return(false);
            }

            var hostProjectPath = GetHostProjectPath(textDocument);

            if (hostProjectPath == null)
            {
                filePath = null;
                return(false);
            }

            // Host always responds with a host-based path, convert back to a guest one.
            filePath = ResolveGuestPath(hostProjectPath);
            return(true);
        }
Exemplo n.º 6
0
        public void SubjectBuffersConnected(IWpfTextView textView, ConnectionReason reason, Collection <ITextBuffer> subjectBuffers)
        {
            ITextDocument textDocument;

            if (_textDocumentFactoryService.TryGetTextDocument(textView.TextBuffer, out textDocument))
            {
                textDocument.FileActionOccurred += delegate(object sender, TextDocumentFileActionEventArgs e)
                {
                    if (e.FileActionType != FileActionTypes.ContentSavedToDisk)
                    {
                        return;
                    }

                    ITextDocument document = (ITextDocument)sender;
                    ITextBuffer   buffer   = document.TextBuffer;
                    string        filePath = e.FilePath;

                    FixBufferOnSave(buffer, textView.FormattedLineSource.TabSize, filePath);
                };
            }
            foreach (var buffer in subjectBuffers)
            {
                IEditorOptions options = textView.Properties.GetProperty <IEditorOptions>(typeof(IEditorOptions));
                int            tabSize = options.GetTabSize();
                FixBufferOnLoad(buffer, tabSize);
            }

            if (textDocument != null)
            {
                textDocument.UpdateDirtyState(false, DateTime.Now);
            }
        }
Exemplo n.º 7
0
		public InstantVisualStudio (IWpfTextView view, ITextDocumentFactoryService textDocumentFactoryService)
		{
			this.view = view;
			this.layer = view.GetAdornmentLayer("Instant.VisualStudio");

			//Listen to any event that changes the layout (text changes, scrolling, etc)
			this.view.LayoutChanged += OnLayoutChanged;

			this.dispatcher = Dispatcher.CurrentDispatcher;

			this.evaluator.EvaluationCompleted += OnEvaluationCompleted;
			this.evaluator.Start();

			this.dte.Events.BuildEvents.OnBuildProjConfigDone += OnBuildProjeConfigDone;
			this.dte.Events.BuildEvents.OnBuildDone += OnBuildDone;
			this.dte.Events.BuildEvents.OnBuildBegin += OnBuildBegin;

			this.statusbar = (IVsStatusbar)this.serviceProvider.GetService (typeof (IVsStatusbar));

			ITextDocument textDocument;
			if (!textDocumentFactoryService.TryGetTextDocument (view.TextBuffer, out textDocument))
				throw new InvalidOperationException();

			this.document = this.dte.Documents.OfType<EnvDTE.Document>().FirstOrDefault (d => d.FullName == textDocument.FilePath);

			InstantTagToggleAction.Toggled += OnInstantToggled;
		}
Exemplo n.º 8
0
        public BottomMargin(IWpfTextView textView, IClassifierAggregatorService classifier, ITextDocumentFactoryService documentService)
        {
            _textView        = textView;
            _classifier      = classifier.GetClassifier(textView.TextBuffer);
            _foregroundBrush = new SolidColorBrush((Color)FindResource(VsColors.CaptionTextKey));
            _backgroundBrush = new SolidColorBrush((Color)FindResource(VsColors.ScrollBarBackgroundKey));

            this.Background   = _backgroundBrush;
            this.ClipToBounds = true;

            _lblEncoding = new TextControl("Encoding");
            this.Children.Add(_lblEncoding);

            _lblContentType = new TextControl("Content type");
            this.Children.Add(_lblContentType);

            _lblClassification = new TextControl("Classification");
            this.Children.Add(_lblClassification);

            _lblSelection = new TextControl("Selection");
            this.Children.Add(_lblSelection);

            UpdateClassificationLabel();
            UpdateContentTypeLabel();
            UpdateContentSelectionLabel();

            if (documentService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out _doc))
            {
                _doc.FileActionOccurred += FileChangedOnDisk;
                UpdateEncodingLabel(_doc);
            }

            textView.Caret.PositionChanged += CaretPositionChanged;
        }
        private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            _timer.Stop();

            Application.Current.Dispatcher.Invoke(() =>
            {
                string filepath = null;
                if (_textDocumentFactory != null &&
                    _textDocumentFactory.TryGetTextDocument(_view.TextBuffer, out ITextDocument textDocument))
                {
                    filepath = textDocument.FilePath;
                }

                foreach (var kvp in _editedLines)
                {
                    try
                    {
                        CreateVisuals(kvp.Value, kvp.Key, filepath);
                    }
                    catch (InvalidOperationException ex)
                    {
                        ExceptionHandler.Notify(ex, true);
                    }
                }

                _editedLines.Clear();
            });
        }
        public ITagger <T> CreateTagger <T>(ITextView textView, ITextBuffer buffer) where T : ITag
        {
            // Only provide the smart tagger on the top-level buffer
            if (textView.TextBuffer != buffer)
            {
                return(null);
            }

            var generalOptions = Setting.getGeneralOptions(serviceProvider);

            if (generalOptions == null || !generalOptions.ResolveUnopenedNamespacesEnabled)
            {
                return(null);
            }

            var dte       = serviceProvider.GetService(typeof(SDTE)) as EnvDTE.DTE;
            var vsVersion = VisualStudioVersionModule.fromDTEVersion(dte.Version);

            if (vsVersion == VisualStudioVersion.VS2015)
            {
                return(null);
            }

            ITextDocument doc;

            if (textDocumentFactoryService.TryGetTextDocument(buffer, out doc))
            {
                var resolver = new UnopenedNamespaceResolver(doc, textView, undoHistoryRegistry.RegisterHistory(buffer),
                                                             fsharpVsLanguageService, serviceProvider, projectFactory);
                return(new ResolveUnopenedNamespaceSmartTagger(buffer, serviceProvider, resolver) as ITagger <T>);
            }

            return(null);
        }
        private GoToDefinitionFilter Register(IVsTextView textViewAdapter, IWpfTextView textView, bool fireNavigationEvent)
        {
            var generalOptions = Setting.getGeneralOptions(_serviceProvider);

            if (generalOptions == null || (!generalOptions.GoToMetadataEnabled && !generalOptions.GoToSymbolSourceEnabled))
            {
                return(null);
            }
            // Favor Navigate to Source feature over Go to Metadata
            var preference = generalOptions.GoToSymbolSourceEnabled
                                ? (generalOptions.GoToMetadataEnabled ? NavigationPreference.SymbolSourceOrMetadata : NavigationPreference.SymbolSource)
                                : NavigationPreference.Metadata;
            ITextDocument doc;

            if (_textDocumentFactoryService.TryGetTextDocument(textView.TextBuffer, out doc))
            {
                var commandFilter = new GoToDefinitionFilter(doc, textView, _editorOptionsFactory,
                                                             _fsharpVsLanguageService, _serviceProvider, _projectFactory,
                                                             _referenceSourceProvider, preference, fireNavigationEvent);
                if (!_referenceSourceProvider.IsActivated && generalOptions.GoToSymbolSourceEnabled)
                {
                    _referenceSourceProvider.Activate();
                }
                textView.Properties.AddProperty(serviceType, commandFilter);
                AddCommandFilter(textViewAdapter, commandFilter);
                return(commandFilter);
            }
            return(null);
        }
Exemplo n.º 12
0
        internal FindReferencesFilter RegisterCommandFilter(IWpfTextView textView, bool showProgress)
        {
            var textViewAdapter = editorFactory.GetViewAdapter(textView);

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

            var generalOptions = Setting.getGeneralOptions(serviceProvider);

            if (generalOptions == null || !generalOptions.FindAllReferencesEnabled)
            {
                return(null);
            }

            ITextDocument doc;

            if (textDocumentFactoryService.TryGetTextDocument(textView.TextBuffer, out doc))
            {
                Debug.Assert(doc != null, "Text document shouldn't be null.");
                var filter = new FindReferencesFilter(doc, textView, fsharpVsLanguageService,
                                                      serviceProvider, projectFactory, showProgress, fileSystem);
                AddCommandFilter(textViewAdapter, filter);
                return(filter);
            }
            return(null);
        }
Exemplo n.º 13
0
        public ITagger <T> CreateTagger <T>(ITextView textView, ITextBuffer buffer) where T : ITag
        {
            // Only provide highlighting on the top-level buffer
            if (textView.TextBuffer != buffer)
            {
                return(null);
            }

            var generalOptions = Setting.getGeneralOptions(serviceProvider);

            if (generalOptions == null || !generalOptions.HighlightUsageEnabled)
            {
                return(null);
            }

            ITextDocument doc;

            if (textDocumentFactoryService.TryGetTextDocument(buffer, out doc))
            {
                Debug.Assert(doc != null, "Text document shouldn't be null.");
                return(new HighlightUsageTagger(doc, textView, fsharpVsLanguageService,
                                                serviceProvider, projectFactory) as ITagger <T>);
            }

            return(null);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Create a tagger that will track SonarLint issues on the view/buffer combination.
        /// </summary>
        public ITagger <T> CreateTagger <T>(ITextView textView, ITextBuffer buffer) where T : ITag
        {
            // Only attempt to track the view's edit buffer.
            if (buffer != textView.TextBuffer ||
                typeof(T) != typeof(IErrorTag))
            {
                return(null);
            }

            ITextDocument textDocument;

            if (!textDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out textDocument))
            {
                return(null);
            }

            var detectedLanguages = languageRecognizer.Detect(textDocument, buffer);

            if (detectedLanguages.Any() && analyzerController.IsAnalysisSupported(detectedLanguages))
            {
                // Multiple views could have that buffer open simultaneously, so only create one instance of the tracker.
                var issueTracker = buffer.Properties.GetOrCreateSingletonProperty(typeof(IIssueTracker),
                                                                                  () => new TextBufferIssueTracker(dte, this, textDocument, detectedLanguages, logger, issuesFilter));

                // Always create a new tagger for each request
                return(new IssueTagger(issueTracker) as ITagger <T>);
            }

            return(null);
        }
Exemplo n.º 15
0
        private ITextDocument GetTextDocument(RunningDocumentInfo info)
        {
            // Get vs buffer
            IVsTextBuffer docData;

            try {
                docData = info.DocData as IVsTextBuffer;
            }
            catch (Exception e) {
                Logger.LogWarn(e, "Error getting IVsTextBuffer for document {0}, skipping document", info.Moniker);
                return(null);
            }
            if (docData == null)
            {
                return(null);
            }

            // Get ITextDocument
            var textBuffer = _vsEditorAdaptersFactoryService.GetDocumentBuffer(docData);

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

            ITextDocument document;

            if (!_textDocumentFactoryService.TryGetTextDocument(textBuffer, out document))
            {
                return(null);
            }

            return(document);
        }
        internal FindReferencesFilter RegisterCommandFilter(IWpfTextView textView, bool showProgress)
        {
            var textViewAdapter = _editorFactory.GetViewAdapter(textView);

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

            var generalOptions = Setting.getGeneralOptions(_serviceProvider);

            if (generalOptions == null || !generalOptions.FindAllReferencesEnabled)
            {
                return(null);
            }

            ITextDocument doc;

            if (_textDocumentFactoryService.TryGetTextDocument(textView.TextBuffer, out doc))
            {
                var filter = new FindReferencesFilter(doc, textView, _fsharpVsLanguageService,
                                                      _serviceProvider, _projectFactory, showProgress, _fileSystem);
                Utils.AddCommandFilter(textViewAdapter, filter);
                return(filter);
            }
            return(null);
        }
Exemplo n.º 17
0
        public ITagger <T> CreateTagger <T>(ITextView textView, ITextBuffer buffer) where T : ITag
        {
            // Only provide the smart tagger on the top-level buffer
            if (textView.TextBuffer != buffer)
            {
                return(null);
            }

            var generalOptions = Setting.getGeneralOptions(serviceProvider);

            if (generalOptions == null || !generalOptions.UnionPatternMatchCaseGenerationEnabled)
            {
                return(null);
            }
            var codeGenOptions = Setting.getCodeGenerationOptions(serviceProvider);

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

            ITextDocument doc;

            if (textDocumentFactoryService.TryGetTextDocument(buffer, out doc))
            {
                return(new UnionPatternMatchCaseGeneratorSmartTagger(doc, textView,
                                                                     undoHistoryRegistry.RegisterHistory(buffer),
                                                                     fsharpVsLanguageService, serviceProvider,
                                                                     projectFactory, Setting.getDefaultMemberBody(codeGenOptions)) as ITagger <T>);
            }

            return(null);
        }
Exemplo n.º 18
0
        internal bool?ShouldCreateVimBuffer(ITextView textView)
        {
            if (!_reSharperUtil.IsInstalled)
            {
                return(null);
            }

            var textBuffer = textView.TextDataModel.DocumentBuffer;

            if (!_textDocumentFactoryService.TryGetTextDocument(textBuffer, out ITextDocument textDocument))
            {
                return(null);
            }

            // This is a bit of a heuristic.  It is technically possible for another component to create
            // a <see cref="ITextDocument"/> with the specified name pattern.  However it seems unlikely
            // that it will happen when R# is also installed.
            if (textDocument.FilePath.StartsWith(FilePathPrefixRegexEditor, StringComparison.OrdinalIgnoreCase) ||
                textDocument.FilePath.StartsWith(FilePathPrefixUnitTestSessionOutput, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            return(null);
        }
        public override Uri GetOrCreate(ITextBuffer textBuffer)
        {
            if (textBuffer is null)
            {
                throw new ArgumentNullException(nameof(textBuffer));
            }

            if (TryGet(textBuffer, out var uri))
            {
                return(uri);
            }

            string filePath;

            if (_textDocumentFactory.TryGetTextDocument(textBuffer, out var textDocument))
            {
                filePath = textDocument.FilePath;
            }
            else
            {
                // TextBuffer doesn't have a file path, we need to fabricate one.
                filePath = Path.GetTempFileName();
            }

            uri = new Uri(filePath, UriKind.Absolute);
            AddOrUpdate(textBuffer, uri);
            return(uri);
        }
Exemplo n.º 20
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = editorFactory.GetWpfTextView(textViewAdapter);

            if (textView == null)
            {
                return;
            }

            var generalOptions = Setting.getGeneralOptions(serviceProvider);

            if (generalOptions == null || !generalOptions.GoToMetadataEnabled)
            {
                return;
            }

            ITextDocument doc;

            if (textDocumentFactoryService.TryGetTextDocument(textView.TextBuffer, out doc))
            {
                Debug.Assert(doc != null, "Text document shouldn't be null.");
                AddCommandFilter(textViewAdapter,
                                 new GoToDefinitionFilter(doc, textView, editorOptionsFactory,
                                                          fsharpVsLanguageService, serviceProvider, projectFactory));
            }
        }
Exemplo n.º 21
0
        public override object GetHostProject(ITextBuffer textBuffer)
        {
            if (textBuffer == null)
            {
                throw new ArgumentNullException(nameof(textBuffer));
            }

            // If there's no document we can't find the FileName, or look for an associated project.
            if (!_documentFactory.TryGetTextDocument(textBuffer, out var textDocument))
            {
                return(null);
            }

            var projectsContainingFilePath = IdeApp.Workspace.GetProjectsContainingFile(textDocument.FilePath);

            foreach (var project in projectsContainingFilePath)
            {
                if (!(project is DotNetProject))
                {
                    continue;
                }

                var projectFile = project.GetProjectFile(textDocument.FilePath);
                if (!projectFile.IsHidden)
                {
                    return(project);
                }
            }

            return(null);
        }
        /// <summary>
        /// Creates a plugin instance when a new text editor is opened
        /// </summary>
        public void TextViewCreated(IWpfTextView view)
        {
            ITextDocument document;

            if (!DocFactory.TryGetTextDocument(view.TextDataModel.DocumentBuffer, out document))
            {
                return;
            }

            var app = (DTE)ServiceProvider.GetService(typeof(DTE));

            if (app == null)
            {
                return;
            }

            if (_messageList == null)
            {
                _messageList = new ErrorListProvider(ServiceProvider)
                {
                    ProviderGuid = Guids.GuidEditorConfigPackage,
                    ProviderName = "EditorConfig"
                };
            }

            _monitor = new TextViewMonitor(view, document, app, _messageList);
        }
        public IClassifier GetClassifier(ITextBuffer buffer)
        {
            var generalOptions = Setting.getGeneralOptions(_serviceProvider);

            if (generalOptions == null || !generalOptions.SyntaxColoringEnabled)
            {
                return(null);
            }

            bool includeUnusedReferences = generalOptions.UnusedReferencesEnabled;
            bool includeUnusedOpens      = generalOptions.UnusedOpensEnabled;

            if (includeUnusedOpens || includeUnusedReferences)
            {
                ITextDocument doc;
                if (_textDocumentFactoryService.TryGetTextDocument(buffer, out doc))
                {
                    return(buffer.Properties.GetOrCreateSingletonProperty(
                               () => new UnusedSymbolClassifier(
                                   doc, buffer, _classificationRegistry, _fsharpVsLanguageService,
                                   _serviceProvider, _projectFactory, includeUnusedReferences, includeUnusedOpens)));
                }
            }

            return(null);
        }
Exemplo n.º 24
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = editorFactory.GetWpfTextView(textViewAdapter);

            if (textView == null)
            {
                return;
            }

            var generalOptions = Setting.getGeneralOptions(serviceProvider);

            if (generalOptions == null || !generalOptions.RenameRefactoringEnabled)
            {
                return;
            }

            ITextDocument doc;

            if (textDocumentFactoryService.TryGetTextDocument(textView.TextBuffer, out doc))
            {
                AddCommandFilter(textViewAdapter,
                                 new RenameCommandFilter(doc, textView, fsharpVsLanguageService,
                                                         serviceProvider, projectFactory));
            }
        }
        public ITagger <T> CreateTagger <T>(ITextView textView, ITextBuffer buffer) where T : ITag
        {
            // Only provide highlighting on the top-level buffer
            if (textView.TextBuffer != buffer)
            {
                return(null);
            }

            var generalOptions = Setting.getGeneralOptions(_serviceProvider);

            if (generalOptions == null || !generalOptions.HighlightUsageEnabled)
            {
                return(null);
            }

            ITextDocument doc;

            if (_textDocumentFactoryService.TryGetTextDocument(buffer, out doc))
            {
                return(textView.Properties.GetOrCreateSingletonProperty(
                           () => new HighlightUsageTagger(doc, textView, _fsharpVsLanguageService, _serviceProvider, _projectFactory)) as ITagger <T>);
            }

            return(null);
        }
Exemplo n.º 26
0
        public BottomMargin(IWpfTextView textView, IClassifierAggregatorService classifier, ITextDocumentFactoryService documentService)
        {
            _textView = textView;
            _classifier = classifier.GetClassifier(textView.TextBuffer);

            SetResourceReference(BackgroundProperty, EnvironmentColors.ScrollBarBackgroundBrushKey);

            ClipToBounds = true;

            _lblEncoding = new TextControl("Encoding");
            Children.Add(_lblEncoding);

            _lblContentType = new TextControl("Content type");
            Children.Add(_lblContentType);

            _lblClassification = new TextControl("Classification");
            Children.Add(_lblClassification);

            _lblSelection = new TextControl("Selection");
            Children.Add(_lblSelection);

            UpdateClassificationLabel();
            UpdateContentTypeLabel();
            UpdateContentSelectionLabel();

            if (documentService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out _doc))
            {
                _doc.FileActionOccurred += FileChangedOnDisk;
                UpdateEncodingLabel(_doc);
            }

            textView.Caret.PositionChanged += CaretPositionChanged;
        }
Exemplo n.º 27
0
        internal static bool IsXSharpDocument(this ITextDocumentFactoryService factory, ITextBuffer buffer)
        {
            string path = "";

            if (buffer.Properties.ContainsProperty(typeof(XFile)))
            {
                return(buffer.GetFile() != null);
            }
            // When not found then locate the file in the XSolution by its name
            if (factory != null)
            {
                ITextDocument doc = null;
                if (factory.TryGetTextDocument(buffer, out doc))
                {
                    path = doc.FilePath;
                }
            }
            // Find and attach the X# document when we have it, or a null to indicate that we have searched
            // and not found it
            var file = XSolution.FindFile(path);

            if (file != null)
            {
                buffer.Properties.AddProperty(typeof(XFile), file);
            }
            return(file != null);
        }
Exemplo n.º 28
0
        public IClassifier GetClassifier(ITextBuffer buffer)
        {
            /* Avoid infinite recursion */
            if (m_inprogress)
            {
                return(null);
            }

#if FALSE
            if (m_textdoc_factory != null)
            {
                ITextDocument doc;
                m_textdoc_factory.TryGetTextDocument(buffer, out doc);
                /* print doc.FilePath */
            }
#endif

            /* Try to guess whether this is a Lol Engine project */
            EnvDTE.DTE dte         = m_sp.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
            bool       islolengine = false;
            if (dte.Solution.FullName.Contains("Lol.sln"))
            {
                islolengine = true;
            }

            LolGenericFormat.SetRegistry(m_type_registry, m_format_map);

            try
            {
                m_inprogress = true;
                return(buffer.Properties.GetOrCreateSingletonProperty <CppKeywordClassifier>(delegate { return new CppKeywordClassifier(m_type_registry, m_aggregator.GetClassifier(buffer), buffer.ContentType, islolengine); }));
            }
            finally { m_inprogress = false; }
        }
        /// <summary>
        /// Creates a <see cref="MarginCore"/> for a given <see cref="IWpfTextView"/>.
        /// </summary>
        /// <param name="textView">The <see cref="IWpfTextView"/> to attach the margin to.</param>
        /// <param name="textDocumentFactoryService">Service that creates, loads, and disposes text documents.</param>
        /// <param name="vsServiceProvider">Visual Studio service provider.</param>
        /// <param name="formatMapService">Service that provides the <see cref="IEditorFormatMap"/>.</param>
        /// <param name="scrollMapFactoryService">Factory that creates or reuses an <see cref="IScrollMap"/> for an <see cref="ITextView"/>.</param>
        public MarginCore(IWpfTextView textView, ITextDocumentFactoryService textDocumentFactoryService, SVsServiceProvider vsServiceProvider, IEditorFormatMapService formatMapService, IScrollMapFactoryService scrollMapFactoryService)
        {
            Debug.WriteLine("Entering constructor.", Properties.Resources.ProductName);

            _textView = textView;
            if (!textDocumentFactoryService.TryGetTextDocument(_textView.TextDataModel.DocumentBuffer, out _textDoc))
            {
                Debug.WriteLine("Can not retrieve TextDocument. Margin is disabled.", Properties.Resources.ProductName);
                _isEnabled = false;
                return;
            }

            _formatMap      = formatMapService.GetEditorFormatMap(textView);
            _marginSettings = new MarginSettings(_formatMap);

            _scrollMap = scrollMapFactoryService.Create(textView);

            var dte = (DTE2)vsServiceProvider.GetService(typeof(DTE));

            _tfExt = (TeamFoundationServerExt)dte.GetObject(typeof(TeamFoundationServerExt).FullName);
            Debug.Assert(_tfExt != null, "_tfExt is null.");
            _tfExt.ProjectContextChanged += OnTfExtProjectContextChanged;

            UpdateMargin();
        }
Exemplo n.º 30
0
        /// <summary>
        /// Create a tagger that will track SonarLint issues on the view/buffer combination.
        /// </summary>
        public ITagger <T> CreateTagger <T>(ITextBuffer buffer) where T : ITag
        {
            // Only attempt to track the view's edit buffer.
            if (typeof(T) != typeof(IErrorTag))
            {
                return(null);
            }

            if (!textDocumentFactoryService.TryGetTextDocument(buffer, out var textDocument))
            {
                return(null);
            }

            var detectedLanguages = languageRecognizer.Detect(textDocument.FilePath, buffer.ContentType);

            if (detectedLanguages.Any() && analyzerController.IsAnalysisSupported(detectedLanguages))
            {
                // We only want one TBIT per buffer and we don't want it be disposed until
                // it is not being used by any tag aggregators, so we're wrapping it in a SingletonDisposableTaggerManager
                var singletonTaggerManager = buffer.Properties.GetOrCreateSingletonProperty(SingletonManagerPropertyCollectionKey,
                                                                                            () => new SingletonDisposableTaggerManager <IErrorTag>(_ => InternalCreateTextBufferIssueTracker(textDocument, detectedLanguages)));

                var tagger = singletonTaggerManager.CreateTagger(buffer);
                return(tagger as ITagger <T>);
            }

            return(null);
        }
Exemplo n.º 31
0
        public override VisualStudioDocumentTracker Create(ITextBuffer textBuffer)
        {
            if (textBuffer == null)
            {
                throw new ArgumentNullException(nameof(textBuffer));
            }

            if (!_textDocumentFactory.TryGetTextDocument(textBuffer, out var textDocument))
            {
                Debug.Fail("Text document should be available from the text buffer.");
                return(null);
            }

            var filePath = textDocument.FilePath;
            var project  = _projectService.GetHostProject(textBuffer);

            if (project == null)
            {
                Debug.Fail("Text buffer should belong to a project.");
                return(null);
            }

            var projectPath = _projectService.GetProjectPath(project);

            var tracker = new DefaultVisualStudioDocumentTracker(_foregroundDispatcher, filePath, projectPath, _projectManager, _editorSettingsManager, _workspace, textBuffer, _importDocumentManager);

            return(tracker);
        }
Exemplo n.º 32
0
        public ITagger <T> CreateTagger <T>(ITextBuffer buffer) where T : ITag
        {
            var generalOptions = Setting.getGeneralOptions(_serviceProvider);

            if (generalOptions == null || !generalOptions.OutliningEnabled)
            {
                return(null);
            }

            ITextDocument doc;

            if (_textDocumentFactoryService.TryGetTextDocument(buffer, out doc))
            {
                return((ITagger <T>)buffer.Properties.GetOrCreateSingletonProperty(() =>
                                                                                   new OutliningTagger(
                                                                                       doc,
                                                                                       _serviceProvider,
                                                                                       _textEditorFactoryService,
                                                                                       _projectionBufferFactoryService,
                                                                                       _projectFactory,
                                                                                       _vsLanguageService,
                                                                                       _openDocumentsTracker)));
            }

            return(null);
        }
        public ITagger <T> CreateTagger <T>(ITextView textView, ITextBuffer buffer) where T : ITag
        {
            // Only provide the smart tagger on the top-level buffer
            if (textView.TextBuffer != buffer)
            {
                return(null);
            }

            var generalOptions = Setting.getGeneralOptions(serviceProvider);

            if (generalOptions == null || !generalOptions.ResolveUnopenedNamespacesEnabled)
            {
                return(null);
            }

            ITextDocument doc;

            if (textDocumentFactoryService.TryGetTextDocument(buffer, out doc))
            {
                return(new ResolveUnopenedNamespaceSmartTagger(doc, textView,
                                                               undoHistoryRegistry.RegisterHistory(buffer),
                                                               fsharpVsLanguageService, serviceProvider, projectFactory) as ITagger <T>);
            }

            return(null);
        }
        public MarkdownBackgroundParser(ITextBuffer textBuffer, TaskScheduler taskScheduler, ITextDocumentFactoryService textDocumentFactoryService)
            : base(textBuffer, taskScheduler, textDocumentFactoryService)
        {
            ReparseDelay = TimeSpan.FromMilliseconds(300);

            ITextDocument document;
            if (textDocumentFactoryService.TryGetTextDocument(textBuffer, out document))
                this.LoadRuleset(document);
        }
 public PreviewWindowBackgroundParser(ITextBuffer textBuffer, TaskScheduler taskScheduler, ITextDocumentFactoryService textDocumentFactoryService)
     : base(textBuffer, taskScheduler, textDocumentFactoryService)
 {
     ReparseDelay = TimeSpan.FromMilliseconds(1000);
     if (!textDocumentFactoryService.TryGetTextDocument(textBuffer, out document))
     {
         document = null;
     }
     markdownTransform.DocumentToTransformPath = document == null ? null : document.FilePath;
 }
Exemplo n.º 36
0
        public DartCodeWindowManager(ITextDocumentFactoryService textDocumentFactory, IVsEditorAdaptersFactoryService editorAdapterFactory, IVsCodeWindow codeWindow, DartAnalysisServiceFactory analysisServiceFactory)
        {
            this.barManager = ((IVsDropdownBarManager)codeWindow);
            this.analysisServiceFactory = analysisServiceFactory;

            // Figure out the filename (seriously; this is the best way?!).
            IVsTextView textView;
            codeWindow.GetPrimaryView(out textView);
            wpfTextView = editorAdapterFactory.GetWpfTextView(textView);
            textDocumentFactory.TryGetTextDocument(wpfTextView.TextBuffer, out this.textDocument);
        }
        public PreviewWindowBackgroundParser(ITextBuffer textBuffer, TaskScheduler taskScheduler, ITextDocumentFactoryService textDocumentFactoryService)
            : base(textBuffer, taskScheduler, textDocumentFactoryService)
        {
            ReparseDelay = TimeSpan.FromMilliseconds(1000);

            ITextDocument markdownDocument;
            if (textDocumentFactoryService.TryGetTextDocument(textBuffer, out markdownDocument))
            {
                markdownDocumentPath = markdownDocument.FilePath;
            }
        }
Exemplo n.º 38
0
        private TemplateErrorReporter(ITextBuffer buffer, IServiceProvider serviceProvider, ITextDocumentFactoryService documentFactory)
        {
            Debug.Assert(buffer != null, "buffer");
            Debug.Assert(serviceProvider != null, "serviceProvider");
            Debug.Assert(documentFactory != null, "documentFactory");

            this.serviceProvider = serviceProvider;
            
            documentFactory.TryGetTextDocument(buffer, out this.document);
            WeakEventManager<ITextDocumentFactoryService, TextDocumentEventArgs>.AddHandler(documentFactory, "TextDocumentDisposed", this.DocumentDisposed);

            this.analyzer = TemplateAnalyzer.GetOrCreate(buffer);
            WeakEventManager<TemplateAnalyzer, TemplateAnalysis>.AddHandler(this.analyzer, "TemplateChanged", this.TemplateChanged);

            this.UpdateErrorTasks(this.analyzer.CurrentAnalysis);
        }
Exemplo n.º 39
0
        protected ErrorManager(ITextView textView,
            IOptionsService optionsService, IServiceProvider serviceProvider,
            ITextDocumentFactoryService textDocumentFactoryService)
        {
            _textView = textView;
            _optionsService = optionsService;

            optionsService.OptionsChanged += OnOptionsChanged;

            ITextDocument document;
            if (textDocumentFactoryService.TryGetTextDocument(textView.TextBuffer, out document))
                ErrorListHelper = new ErrorListHelper(serviceProvider, document);

            textView.Closed += OnViewClosed;

            OnOptionsChanged(this, EventArgs.Empty);
        }
        public PreviewWindowUpdateListener(IWpfTextView wpfTextView, MarkdownPackage package, ITextDocumentFactoryService textDocumentFactoryService)
        {
            this.textView = wpfTextView;
            this.package = package;
            this.backgroundParser = new PreviewWindowBackgroundParser(wpfTextView.TextBuffer, TaskScheduler.Default, textDocumentFactoryService);
            this.backgroundParser.ParseComplete += HandleBackgroundParseComplete;

            if (!textDocumentFactoryService.TryGetTextDocument(wpfTextView.TextDataModel.DocumentBuffer, out document))
                document = null;

            if (textView.HasAggregateFocus)
                UpdatePreviewWindow(string.Empty);

            backgroundParser.RequestParse(true);

            textView.Closed += HandleTextViewClosed;
            textView.GotAggregateFocus += HandleTextViewGotAggregateFocus;
        }
        public DocumentInsightsMargin(IWpfTextView textView, ITextDocumentFactoryService documentService)
        {
            Int32 sourceLineCount = 0;
            Int32 sourceCharCount = 0;

            // Instance initialization
            _textView = textView;

            if (documentService.TryGetTextDocument(textView.TextBuffer, out _textDocument)) {
                sourceLineCount = _textDocument.TextBuffer.CurrentSnapshot.LineCount;
                sourceCharCount = _textDocument.TextBuffer.CurrentSnapshot.Length;
                _textDocument.FileActionOccurred += TextDocument_FileActionOccurred;
            }

            Encoding encoding = _textDocument != null ? _textDocument.Encoding : null;

            _viewModel = new DocumentInsightsViewModel(sourceLineCount, sourceCharCount, encoding) {
                ShowCharInfo = DocumentInsightsOptions.Current.EnableCharInfo,
                ShowLineInfo = DocumentInsightsOptions.Current.EnableLineInfo,
                ShowEncodingInfo = DocumentInsightsOptions.Current.EnableEncodingInfo
            };

            _view = new DocumentInsightsView() {
                DataContext = _viewModel,
                Visibility = DocumentInsightsOptions.Current.ShowMargin ? Visibility.Visible : Visibility.Collapsed
            };

            // Add event handler
            if (textView != null) {
                textView.Closed += TextView_Closed;
                if (textView.TextBuffer != null) {
                    textView.TextBuffer.Changed += TextBuffer_Changed;
                }
            }

            // Subscribe options property changed notifications
            DocumentInsightsOptions.Current.PropertyChanged += Options_PropertyChanged;
        }
Exemplo n.º 42
0
        /// <summary>
        /// Creates a <see cref="MarginCore"/> for a given <see cref="IWpfTextView"/>.
        /// </summary>
        /// <param name="textView">The <see cref="IWpfTextView"/> to attach the margin to.</param>
        /// <param name="textDocumentFactoryService">Service that creates, loads, and disposes text documents.</param>
        /// <param name="vsServiceProvider">Visual Studio service provider.</param>
        /// <param name="formatMapService">Service that provides the <see cref="IEditorFormatMap"/>.</param>
        /// <param name="scrollMapFactoryService">Factory that creates or reuses an <see cref="IScrollMap"/> for an <see cref="ITextView"/>.</param>
        public MarginCore(IWpfTextView textView, ITextDocumentFactoryService textDocumentFactoryService, SVsServiceProvider vsServiceProvider, IEditorFormatMapService formatMapService, IScrollMapFactoryService scrollMapFactoryService)
        {
            Debug.WriteLine("Entering constructor.", Properties.Resources.ProductName);

            _textView = textView;
            if (!textDocumentFactoryService.TryGetTextDocument(_textView.TextBuffer, out _textDoc))
            {
                Debug.WriteLine("Can not retrieve TextDocument. Margin is disabled.", Properties.Resources.ProductName);
                _isEnabled = false;
                return;
            }

            _formatMap = formatMapService.GetEditorFormatMap(textView);
            _marginSettings = new MarginSettings(_formatMap);

            _scrollMap = scrollMapFactoryService.Create(textView);

            var dte = (DTE2)vsServiceProvider.GetService(typeof(DTE));
            _tfExt = dte.GetObject(typeof(TeamFoundationServerExt).FullName);
            Debug.Assert(_tfExt != null, "_tfExt is null.");
            _tfExt.ProjectContextChanged += OnTfExtProjectContextChanged;

            UpdateMargin();
        }