private void DeleteExtensions(IContentType contentType)
 {
     foreach (var ext in _fileExtensionRegistryService.GetExtensionsForContentType(contentType))
     {
         _fileExtensionRegistryService.RemoveFileExtension(ext);
     }
 }
        /////////////////////////////////////////////////////////////////////////////
        // Overridden Package Implementation
        #region Package Members

        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            IComponentModel               componentModel               = (IComponentModel)this.GetService(typeof(SComponentModel));
            IContentTypeRegistryService   contentTypeRegistryService   = componentModel.GetService <IContentTypeRegistryService>();
            IFileExtensionRegistryService fileExtensionRegistryService = componentModel.GetService <IFileExtensionRegistryService>();

            IContentType perlContentType = contentTypeRegistryService.GetContentType(Perl.Constants.ContentType);

            if (perlContentType != null)
            {
                IList <string> exts = fileExtensionRegistryService.GetExtensionsForContentType(perlContentType).ToList();
                foreach (string ext in exts)
                {
                    fileExtensionRegistryService.RemoveFileExtension(ext);
                }

                contentTypeRegistryService.RemoveContentType(Perl.Constants.ContentType);
            }

            perlContentType = contentTypeRegistryService.AddContentType(Perl.Constants.ContentType, new List <string> {
                "code"
            });
            fileExtensionRegistryService.AddFileExtension(".pm", perlContentType);
        }
Esempio n. 3
0
 ///<summary>Gets a case-insensitive HashSet of all extensions for a given ContentType, including the leading dot.</summary>
 public static ISet <string> GetFileExtensionSet(this IFileExtensionRegistryService extService, IContentType contentType)
 {
     return(new HashSet <string>(
                extService.GetExtensionsForContentType(contentType)
                .Select(e => "." + e),
                StringComparer.OrdinalIgnoreCase
                ));
 }
        /// <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
        {
            if (!settings.IsActivateMoreEnabled)
            {
                return(null);
            }

            // Only attempt to track the view's edit buffer.
            // Multiple views could have that buffer open simultaneously, so only create one instance of the tracker.
            if (buffer != textView.TextBuffer || typeof(T) != typeof(IErrorTag))
            {
                return(null);
            }

            ITextDocument document;

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

            var filePath      = document.FilePath;
            var fileExtension = Path.GetExtension(filePath).Replace(".", "");

            var contentTypes = ContentTypeRegistryService.ContentTypes
                               .Where(type => FileExtensionRegistryService.GetExtensionsForContentType(type).Any(e => e == fileExtension))
                               .ToList();

            if (contentTypes.Count == 0 && buffer.ContentType != null)
            {
                // Fallback on TextBuffer content type
                contentTypes.Add(buffer.ContentType);
            }

            if (!contentTypes.Any(t => t.IsOfType("JavaScript") || t.IsOfType("C/C++")))
            {
                return(null);
            }

            lock (taggers)
            {
                if (!taggers.ExistsForFile(filePath))
                {
                    var tracker = new IssueTagger(dte, this, buffer, document, contentTypes);
                    return(tracker as ITagger <T>);
                }
            }

            return(null);
        }
Esempio n. 5
0
        private IEnumerable <IContentType> GetExtensionContentTypes(string fileExtension, IContentType bufferContentType)
        {
            var contentTypes = contentTypeRegistryService
                               .ContentTypes
                               .Where(type => fileExtensionRegistryService.GetExtensionsForContentType(type).Any(e =>
                                                                                                                 e.Equals(fileExtension, StringComparison.OrdinalIgnoreCase)))
                               .ToList();

            if (contentTypes.Count == 0 &&
                bufferContentType != null)
            {
                // Fallback on TextBuffer content type
                contentTypes.Add(bufferContentType);
            }

            return(contentTypes);
        }
Esempio n. 6
0
 private void OpenBufferInEditor(ITextBuffer buffer)
 {
     try {
         String extension = extensionRegistry
                            .GetExtensionsForContentType(buffer.ContentType)
                            .FirstOrDefault();
         if (String.IsNullOrEmpty(extension))
         {
             TextEditor.OpenBufferInPlainTextEditorAsReadOnly(buffer);
         }
         else
         {
             TextEditor.OpenBufferInEditorAsReadOnly(buffer, extension);
         }
     } catch (Exception ex) {
         MessageBox.Show(ex.Message, "Viasfora Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }