private void CreateImage()
        {
            Children.Clear();

            EditorConfigDocument parent = _document.Parent;
            int parentsCount            = 0;

            if (parent != null)
            {
                var inherits = new ThemedTextBlock()
                {
                    Text     = "Inherits from",
                    FontSize = 22,
                };

                Children.Add(inherits);
            }

            while (parent != null)
            {
                CreateInheritance(parent.FileName, parentsCount);
                parentsCount += 3;
                parent        = parent.Parent;
            }

            UpdateLayout();

            ThreadHelper.Generic.BeginInvoke(DispatcherPriority.ApplicationIdle, () =>
            {
                SetAdornmentLocation(_adornmentLayer.TextView, EventArgs.Empty);
            });
        }
Esempio n. 2
0
 public ParseItem(EditorConfigDocument document, ItemType type, Span span, string text)
 {
     Document = document;
     ItemType = type;
     Span     = span;
     Text     = text;
 }
Esempio n. 3
0
        public override int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (pguidCmdGroup == _commandGroup && nCmdID == _commandId)
            {
                var document = EditorConfigDocument.FromTextBuffer(_buffer);
                EditorConfigDocument parent = document?.Parent;

                if (parent != null)
                {
                    VsHelpers.PreviewDocument(parent.FileName);
                }
                else
                {
                    var statusBar = Package.GetGlobalService(typeof(SVsStatusbar)) as IVsStatusbar;
                    statusBar.IsFrozen(out int frozen);

                    if (frozen == 0)
                    {
                        statusBar.SetText("This is a root document with no inheritance");
                    }
                }

                return(VSConstants.S_OK);
            }

            return(Next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
Esempio n. 4
0
        public OutliningTagger(ITextBuffer buffer)
        {
            _buffer   = buffer;
            _snapshot = buffer.CurrentSnapshot;

            _document         = EditorConfigDocument.FromTextBuffer(buffer);
            _document.Parsed += DocumentChanged;

            StartParsing();
        }
        private EditorConfigValidator(EditorConfigDocument document)
        {
            _document         = document;
            _document.Parsed += DocumentParsedAsync;

            if (_prevEnabled)
            {
                ValidateAsync().ConfigureAwait(false);
            }

            ValidationOptions.Saved += DocumentParsedAsync;
        }
Esempio n. 6
0
        public EditorConfigClassifier(IClassificationTypeRegistryService registry, ITextBuffer buffer)
        {
            _map = _map ?? new Dictionary <ItemType, IClassificationType> {
                { ItemType.Comment, registry.GetClassificationType(PredefinedClassificationTypeNames.Comment) },
                { ItemType.Section, registry.GetClassificationType(PredefinedClassificationTypeNames.String) },
                { ItemType.Keyword, registry.GetClassificationType(PredefinedClassificationTypeNames.Identifier) },
                { ItemType.Value, registry.GetClassificationType(PredefinedClassificationTypeNames.Keyword) },
                { ItemType.Severity, registry.GetClassificationType(PredefinedClassificationTypeNames.SymbolDefinition) },
                { ItemType.Suppression, registry.GetClassificationType(PredefinedClassificationTypeNames.ExcludedCode) },
            };

            _buffer   = buffer;
            _document = EditorConfigDocument.FromTextBuffer(buffer);
        }
        internal static void AddMissingRules(EditorConfigDocument document, List <Keyword> missingRules, ITextEdit edit)
        {
            var sb = new StringBuilder();

            sb.AppendLine();

            bool   firstRule = true;
            string curHeader = "";

            foreach (Keyword curRule in missingRules)
            {
                if (firstRule)
                {
                    curHeader = GetHeader(curRule);
                    sb.AppendLine(curHeader);
                    firstRule = false;
                }
                else if (!curHeader.Equals(GetHeader(curRule)))
                {
                    curHeader = GetHeader(curRule);
                    sb.AppendLine();
                    sb.AppendLine(curHeader);
                }

                sb.Append(curRule.Name + " = ");
                IEnumerator <Value> defaultValues = curRule.DefaultValue.GetEnumerator();
                bool firstValue = true;
                while (defaultValues.MoveNext())
                {
                    if (firstValue)
                    {
                        firstValue = false;
                    }
                    else
                    {
                        sb.Append(",");
                    }
                    sb.Append(defaultValues.Current.Name);
                }

                if (curRule.RequiresSeverity)
                {
                    sb.Append(":" + curRule.DefaultSeverity);
                }
                sb.AppendLine();
            }
            ;

            edit.Insert(document.TextBuffer.CurrentSnapshot.Length, sb.ToString());
        }
Esempio n. 8
0
        private IEnumerable <EditorConfigDocument> GetAllParentDocuments()
        {
            if (EditorConfigPackage.ValidationOptions.EnableDuplicateFoundInParent)
            {
                EditorConfigDocument parent = _document.Parent;

                while (parent != null)
                {
                    yield return(parent);

                    parent = parent.Parent;
                }
            }
        }
Esempio n. 9
0
        public void TextViewCreated(IWpfTextView view)
        {
            if (_documentService.TryGetTextDocument(view.TextBuffer, out var doc))
            {
                _file = doc.FilePath;
                view.Properties.AddProperty("file", doc.FilePath);
            }

            _document  = EditorConfigDocument.FromTextBuffer(view.TextBuffer);
            _validator = EditorConfigValidator.FromDocument(_document);
            _project   = VsHelpers.DTE.Solution?.FindProjectItem(_file)?.ContainingProject;

            view.Closed          += ViewClosed;
            _validator.Validated += Validated;
        }
Esempio n. 10
0
        public ErrorTagger(IWpfTextView view)
        {
            _view = view;

            _document             = EditorConfigDocument.FromTextBuffer(view.TextBuffer);
            _validator            = EditorConfigValidator.FromDocument(_document);
            _validator.Validated += DocumentValidated;

            ThreadHelper.Generic.BeginInvoke(DispatcherPriority.ApplicationIdle, () =>
            {
                _hasLoaded = true;
                var span   = new SnapshotSpan(view.TextBuffer.CurrentSnapshot, 0, view.TextBuffer.CurrentSnapshot.Length);
                TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(span));
            });
        }
 private void Execute(object sender, EventArgs e)
 {
     try
     {
         if (TextViewUtil.TryGetWpfTextView(_filePath, out var view))
         {
             var document  = EditorConfigDocument.FromTextBuffer(view.TextBuffer);
             var validator = EditorConfigValidator.FromDocument(document);
             validator.SuppressError(_selectedError.Code);
         }
     }
     catch (Exception ex)
     {
         Telemetry.TrackException("SuppressError", ex);
     }
 }
        public ErrorTagger(IWpfTextView view)
        {
            _view = view;

            _document             = EditorConfigDocument.FromTextBuffer(view.TextBuffer);
            _validator            = EditorConfigValidator.FromDocument(_document);
            _validator.Validated += DocumentValidated;

            ThreadHelper.JoinableTaskFactory.StartOnIdle(
                () =>
            {
                _hasLoaded = true;
                var span   = new SnapshotSpan(view.TextBuffer.CurrentSnapshot, 0, view.TextBuffer.CurrentSnapshot.Length);
                TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(span));
                return(Task.CompletedTask);
            },
                VsTaskRunContext.UIThreadIdlePriority);
        }
Esempio n. 13
0
        public override int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
        {
            if (pguidCmdGroup == _commandGroup && prgCmds[0].cmdID == _commandId)
            {
                var document = EditorConfigDocument.FromTextBuffer(_buffer);
                EditorConfigDocument parent = document?.Parent;

                if (parent != null)
                {
                    prgCmds[0].cmdf = (uint)OLECMDF.OLECMDF_ENABLED | (uint)OLECMDF.OLECMDF_SUPPORTED;
                    return(VSConstants.S_OK);
                }

                return(VSConstants.S_OK);
            }

            return(Next.QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText));
        }
Esempio n. 14
0
        public DropDownBars(LanguageService languageService, IVsTextView view)
            : base(languageService)
        {
            _languageService = languageService;

            var componentModel = (IComponentModel)languageService.GetService(typeof(SComponentModel));
            IVsEditorAdaptersFactoryService editorAdapterFactoryService = componentModel.GetService <IVsEditorAdaptersFactoryService>();
            IWpfTextView textView = editorAdapterFactoryService.GetWpfTextView(view);

            textView.Caret.PositionChanged += CaretPositionChanged;

            _buffer = textView.TextBuffer;

            _document         = EditorConfigDocument.FromTextBuffer(_buffer);
            _document.Parsed += DocumentParsed;

            UpdateElements();
        }
Esempio n. 15
0
        /// <summary>Returns a list of all rules included in the current or parent document(s).</summary>
        public List <string> GetAllIncludedRules()
        {
            EditorConfigDocument curDoc = this;
            var rules = new List <string>();

            while (curDoc != null)
            {
                foreach (ParseItem parseItem in curDoc.ParseItems)
                {
                    string parseItemStr = parseItem.Text;
                    if (!rules.Contains(parseItemStr) && parseItem.ItemType == ItemType.Keyword)
                    {
                        rules.Add(parseItemStr);
                    }
                }
                curDoc = curDoc.Parent;
            }
            return(rules);
        }
        public InheritanceAdornment(IWpfTextView view, ITextDocument doc)
        {
            _adornmentLayer = view.GetAdornmentLayer(InheritanceAdornmentLayer.LayerName);
            _document       = EditorConfigDocument.FromTextBuffer(view.TextBuffer);

            Visibility = System.Windows.Visibility.Hidden;

            Loaded += (s, e) =>
            {
                CreateImage();
                doc.FileActionOccurred += FileActionOccurred;
                Updated += InheritanceUpdated;

                view.ViewportHeightChanged += SetAdornmentLocation;
                view.ViewportWidthChanged  += SetAdornmentLocation;
            };

            if (_adornmentLayer.IsEmpty)
            {
                _adornmentLayer.AddAdornment(AdornmentPositioningBehavior.ViewportRelative, null, null, this, null);
            }
        }
        private void CreateImage()
        {
            Dispatcher.VerifyAccess();

            Children.Clear();

            EditorConfigDocument parent = _document.Parent;
            int parentsCount            = 0;

            if (parent != null)
            {
                var inherits = new ThemedTextBlock()
                {
                    Text     = "Inherits from",
                    FontSize = 22,
                };

                Children.Add(inherits);
            }

            while (parent != null)
            {
                CreateInheritance(parent.FileName, parentsCount);
                parentsCount += 3;
                parent        = parent.Parent;
            }

            UpdateLayout();

#pragma warning disable VSTHRD001 // Avoid legacy thread switching APIs
            ThreadHelper.Generic.BeginInvoke(DispatcherPriority.ApplicationIdle, () =>
#pragma warning restore VSTHRD001 // Avoid legacy thread switching APIs
            {
                SetAdornmentLocation(_adornmentLayer.TextView, EventArgs.Empty);
            });
        }
Esempio n. 18
0
 public EditorConfigCompletionSource(ITextBuffer buffer, ITextStructureNavigatorSelectorService navigator)
 {
     _buffer = buffer;
     _navigator = navigator;
     _document = EditorConfigDocument.FromTextBuffer(buffer);
 }
        bool Commit(bool force)
        {
            if (_currentSession == null)
            {
                return(false);
            }

            if (!_currentSession.SelectedCompletionSet.SelectionStatus.IsSelected && !force)
            {
                _currentSession.Dismiss();
                return(false);
            }
            else
            {
                string moniker = _currentSession.SelectedCompletionSet.Moniker;
                _currentSession.Commit();

                if (!EditorConfigPackage.CompletionOptions.AutoInsertDelimiters)
                {
                    return(true);
                }

                SnapshotPoint     position = TextView.Caret.Position.BufferPosition;
                ITextSnapshotLine line     = TextView.TextBuffer.CurrentSnapshot.GetLineFromPosition(position);
                string            lineText = line.GetText();

                if (moniker == "keyword" && !lineText.Contains("="))
                {
                    TextView.TextBuffer.Insert(position, " = ");

                    // Contains placeholders
                    int start = lineText.IndexOf('<');
                    int end   = lineText.IndexOf('>');

                    if (start > -1 && start < end)
                    {
                        var span = new SnapshotSpan(TextView.TextBuffer.CurrentSnapshot, Span.FromBounds(line.Start + start, line.Start + end + 1));
                        TextView.Selection.Select(span, false);
                        TextView.Caret.MoveTo(span.Start);
                        return(true);
                    }

                    if (EditorConfigPackage.Language.Preferences.AutoListMembers)
                    {
                        StartSession();
                    }
                }
                else if (moniker == "value" && !lineText.Contains(":"))
                {
                    var      document = EditorConfigDocument.FromTextBuffer(TextView.TextBuffer);
                    Property prop     = document.PropertyAtPosition(position - 1);

                    if (SchemaCatalog.TryGetKeyword(prop.Keyword.Text, out Keyword keyword) && prop.Value != null)
                    {
                        if (keyword.RequiresSeverity)
                        {
                            TextView.TextBuffer.Insert(position, ":");

                            if (EditorConfigPackage.Language.Preferences.AutoListMembers)
                            {
                                StartSession();
                            }
                        }
                    }
                }

                return(true);
            }
        }
 public EditorConfigFormatter(ITextBuffer buffer)
 {
     _document = EditorConfigDocument.FromTextBuffer(buffer);
 }
 public SortAllPropertiesAction(EditorConfigDocument document, ITextView view)
 {
     _document = document;
     _view     = view;
 }
Esempio n. 22
0
 public AddMissingRulesAction(List <Keyword> missingRules, EditorConfigDocument document, ITextView view)
 {
     _missingRules = missingRules;
     _document     = document;
     _view         = view;
 }
 public EditorConfigQuickInfo(ITextBuffer buffer)
 {
     _buffer   = buffer;
     _document = EditorConfigDocument.FromTextBuffer(buffer);
 }
 public SuppressErrorAction(EditorConfigDocument document, string errorCode)
 {
     _document  = document;
     _errorCode = errorCode;
 }
Esempio n. 25
0
 public SuggestedActionsSource(ITextView view, ITextBuffer buffer)
 {
     _view     = view;
     _document = EditorConfigDocument.FromTextBuffer(buffer);
 }
 /// <summary>Gets or creates an instace of the validator and stores it in the text buffer properties.</summary>
 public static EditorConfigValidator FromDocument(EditorConfigDocument document)
 {
     return(document.TextBuffer.Properties.GetOrCreateSingletonProperty(() => new EditorConfigValidator(document)));
 }