Exemple #1
0
        // This creates the underlying tags that are shown on the designer.
        public IEnumerable <ITagSpan <IErrorTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (spans.Count == 0)
            {
                yield break;
            }

            var errors = RapidXamlDocumentCache.AdornmentTags(this.file);

            foreach (var viewTag in errors)
            {
                foreach (var span in spans)
                {
                    if (span.IntersectsWith(viewTag.Span))
                    {
                        if (span.Snapshot.TextBuffer != viewTag.Snapshot.TextBuffer)
                        {
                            SharedRapidXamlPackage.Logger.RecordInfo(StringRes.Info_TextBufferChanged.WithParams(this.file));
                            RapidXamlDocumentCache.Invalidate(this.file);
                            break;
                        }

                        if (span.Snapshot.Version.VersionNumber != viewTag.Snapshot.Version.VersionNumber)
                        {
                            SharedRapidXamlPackage.Logger.RecordInfo(StringRes.Info_SnapshotVersionChanged.WithParams(this.file));
                            RapidXamlDocumentCache.Invalidate(this.file);
                            break;
                        }

                        yield return(viewTag.AsErrorTag());
                    }
                }
            }
        }
        public SuggestedActionsSource(IViewTagAggregatorFactoryService tagService, ISuggestedActionCategoryRegistryService suggestedActionCategoryRegistry, ITextView view, ITextBuffer textBuffer, string file)
        {
            this.tagService = tagService;
            this.suggestedActionCategoryRegistry = suggestedActionCategoryRegistry;
            this.view = view;
            this.file = file;

            RapidXamlDocumentCache.Add(this.file, textBuffer.CurrentSnapshot);
        }
 private void OnViewLayoutChanged(object sender, TextViewLayoutChangedEventArgs e)
 {
     // It would be "nice" to only reparse the changed lines in large documents but would need to keep track or any processors that work on the encapsulated changes.
     // Caching processors for partial re-parsing would be complicated. Considering this a low priority optimization.
     if (e.OldSnapshot != e.NewSnapshot)
     {
         RapidXamlDocumentCache.Update(this.file, e.NewViewState.EditSnapshot);
     }
 }
Exemple #4
0
        public SuggestedActionsSource(IViewTagAggregatorFactoryService tagService, ISuggestedActionCategoryRegistryService suggestedActionCategoryRegistry, ITextView view, ITextBuffer textBuffer, string file)
        {
            this.tagService = tagService;
            this.suggestedActionCategoryRegistry = suggestedActionCategoryRegistry;
            this.view = view;
            this.file = file;

            // Don't want every change event as that is a lot during editing. Wait for a second of inactivity before reparsing.
            this.WhenViewLayoutChanged.Throttle(TimeSpan.FromSeconds(1)).Subscribe(e => this.OnViewLayoutChanged(this, e));

            RapidXamlDocumentCache.Add(this.file, textBuffer.CurrentSnapshot);
        }
Exemple #5
0
        public int OnAfterSave(uint docCookie)
        {
            var documentInfo = this.runningDocumentTable.GetDocumentInfo(docCookie);

            var documentPath = documentInfo.Moniker;

            if (Path.GetExtension(documentPath) == ".xaml")
            {
                RapidXamlDocumentCache.TryUpdate(documentPath);
            }

            return(VSConstants.S_OK);
        }
Exemple #6
0
        // For when don't have access to an ITextSnapshot but the document is open.
        public static void TryUpdate(string file)
        {
            if (package == null)
            {
                return;
            }

            bool DocIsOpenInLogicalView(string path, Guid logicalView, out IVsWindowFrame windowFrame)
            {
                if (package != null)
                {
                    return(VsShellUtilities.IsDocumentOpen(
                               package,
                               path,
                               logicalView,
                               out var dummyHierarchy2,
                               out var dummyItemId2,
                               out windowFrame));
                }
                else
                {
                    windowFrame = null;
                    return(false);
                }
            }

            var docIsOpenInTextView =
                DocIsOpenInLogicalView(file, VSConstants.LOGVIEWID_TextView, out var windowFrameForTextView) ||
                DocIsOpenInLogicalView(file, VSConstants.LOGVIEWID_Code, out windowFrameForTextView);

            if (docIsOpenInTextView && windowFrameForTextView != null)
            {
                var view = VsShellUtilities.GetTextView(windowFrameForTextView);

                if (view != null)
                {
                    view.GetBuffer(out var curDocTextLines);

                    var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));

                    var adaptersFactory = componentModel.GetService <IVsEditorAdaptersFactoryService>();

                    var docBuffer = adaptersFactory.GetDocumentBuffer(curDocTextLines as IVsTextBuffer);

                    RapidXamlDocumentCache.Update(file, docBuffer.CurrentSnapshot);
                }
            }
        }
Exemple #7
0
        public int OnAfterSave(uint docCookie)
        {
#if VSIXNOTEXE
            var documentInfo = this.runningDocumentTable.GetDocumentInfo(docCookie);

            var documentPath = documentInfo.Moniker;

            if (Path.GetExtension(documentPath) == ".xaml" &&
                RapidXamlAnalysisPackage.IsLoaded &&
                RapidXamlAnalysisPackage.Options.AnalyzeWhenDocumentSaved)
            {
                RapidXamlDocumentCache.TryUpdate(documentPath);
            }
#endif
            return(VSConstants.S_OK);
        }
        // This creates the underlying tags that are shown on the designer.
        public IEnumerable <ITagSpan <IErrorTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (spans.Count == 0)
            {
                yield break;
            }

            var errors = RapidXamlDocumentCache.AdornmentTags(this.file);

            foreach (var viewTag in errors)
            {
                foreach (var span in spans)
                {
                    if (span.IntersectsWith(viewTag.Span))
                    {
                        yield return(viewTag.AsErrorTag());
                    }
                }
            }
        }
Exemple #9
0
        // This handles adding and removing things from the error list
        private void OnXamlDocParsed(object sender, RapidXamlParsingEventArgs e)
        {
            var visibleErrors = RapidXamlDocumentCache.ErrorListTags(this.file);

            var projectName = this.GetProjectName(this.file);

            var result = new FileErrorCollection {
                Project = projectName, FilePath = this.file
            };

            foreach (var viewTag in visibleErrors)
            {
                result.Errors.Add(viewTag.AsErrorRow());
            }

            ErrorListService.Process(result);

            // As the tags that are shown in the error list might have changed, trigger that to be updated too.
            if (e != null)
            {
                var span = new SnapshotSpan(e.Snapshot, 0, e.Snapshot.Length);
                this.TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(span));
            }
        }
 private IEnumerable <IRapidXamlTag> GetTags(SnapshotSpan span)
 {
     return(RapidXamlDocumentCache.AdornmentTags(this.file).Where(t => t.Span.IntersectsWith(span)).Select(t => t));
 }