Пример #1
0
        internal TaggerProvider(ISonarErrorListDataSource sonarErrorDataSource,
                                ITextDocumentFactoryService textDocumentFactoryService,
                                IIssuesFilter issuesFilter,
                                IAnalyzerController analyzerController,
                                [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider,
                                ISonarLanguageRecognizer languageRecognizer,
                                IAnalysisRequester analysisRequester,
                                IAnalysisIssueVisualizationConverter converter,
                                ILogger logger,
                                IScheduler scheduler)
        {
            this.sonarErrorDataSource       = sonarErrorDataSource;
            this.textDocumentFactoryService = textDocumentFactoryService;
            this.issuesFilter = issuesFilter;

            this.analyzerController = analyzerController;
            this.dte = serviceProvider.GetService <DTE>();
            this.languageRecognizer = languageRecognizer;
            this.converter          = converter;
            this.logger             = logger;
            this.scheduler          = scheduler;

            vsStatusBar = serviceProvider.GetService(typeof(IVsStatusbar)) as IVsStatusbar;
            analysisRequester.AnalysisRequested += OnAnalysisRequested;

            vsSolution = serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution5;
        }
Пример #2
0
        private static string GetProjectGuid(string fullname, IVsSolution5 vsSolution5)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var guid = vsSolution5.GetGuidOfProjectFile(fullname);

            return(guid.ToString());
        }
        public TextBufferIssueTracker(DTE dte, TaggerProvider provider, ITextDocument document,
                                      IEnumerable <AnalysisLanguage> detectedLanguages, IIssuesFilter issuesFilter,
                                      ISonarErrorListDataSource sonarErrorDataSource, IAnalysisIssueVisualizationConverter converter,
                                      IVsSolution5 vsSolution, ILogger logger)
        {
            this.dte = dte;

            this.Provider   = provider;
            this.textBuffer = document.TextBuffer;

            this.detectedLanguages    = detectedLanguages;
            this.sonarErrorDataSource = sonarErrorDataSource;
            this.converter            = converter;
            this.vsSolution           = vsSolution;
            this.logger       = logger;
            this.issuesFilter = issuesFilter;

            this.document = document;
            this.FilePath = document.FilePath;
            this.charset  = document.Encoding.WebName;

            this.Factory = new IssuesSnapshotFactory(new IssuesSnapshot(GetProjectName(), GetProjectGuid(), FilePath, new List <IAnalysisIssueVisualization>()));

            document.FileActionOccurred += SafeOnFileActionOccurred;

            sonarErrorDataSource.AddFactory(this.Factory);
            Provider.AddIssueTracker(this);

            RequestAnalysis(null /* no options */);
        }
Пример #4
0
        private TextBufferIssueTracker CreateTextBufferIssueTracker(IVsSolution5 vsSolution = null)
        {
            logger = new TestLogger();
            vsSolution ??= Mock.Of <IVsSolution5>();

            return(new TextBufferIssueTracker(taggerProvider.dte, taggerProvider,
                                              mockedJavascriptDocumentFooJs.Object, javascriptLanguage, issuesFilter.Object,
                                              mockSonarErrorDataSource.Object, Mock.Of <IAnalysisIssueVisualizationConverter>(), vsSolution, logger));
        }
Пример #5
0
 public SolutionWrapper(
     IVsSolution solution,
     IVsSolution2 solution2 = null,
     IVsSolution3 solution3 = null,
     IVsSolution4 solution4 = null,
     IVsSolution5 solution5 = null,
     IVsSolution6 solution6 = null,
     IVsSolution7 solution7 = null,
     IVsSolution8 solution8 = null
     )
 {
     _solution  = solution;
     _solution2 = solution2;
     _solution3 = solution3;
     _solution4 = solution4;
     _solution5 = solution5;
     _solution6 = solution6;
     _solution7 = solution7;
     _solution8 = solution8;
 }
        private void BuildProjectPathToIdMap()
        {
            projectPathToProjectIdMap = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase);

            IVsSolution solution = this.serviceProvider.GetService <SVsSolution, IVsSolution>();

            Debug.Assert(solution != null, "Cannot find SVsSolution");

            // 1. Call with nulls to get the number of files
            const uint grfGetOpsIncludeUnloadedFiles = 0; // required since the projects might not have finished loading
            uint       fileCount;
            var        result = solution.GetProjectFilesInSolution(grfGetOpsIncludeUnloadedFiles, 0, null, out fileCount);

            if (ErrorHandler.Failed(result))
            {
                return;
            }

            // 2. Size array and call again to get the data
            string[] fileNames = new string[fileCount];
            result = solution.GetProjectFilesInSolution(grfGetOpsIncludeUnloadedFiles, fileCount, fileNames, out fileCount);
            if (ErrorHandler.Failed(result))
            {
                return;
            }

            IVsSolution5 soln5 = (IVsSolution5)solution;

            foreach (string projectFile in fileNames)
            {
                // We need to use the same project id that is used by the Scanner for MSBuild.
                // For non-.Net Core projects, the scanner will use the <ProjectGuid> value in the project.
                // .Net Core projects don't have a <ProjectGuid> property so the scanner uses the GUID allocated
                // to the project in the solution file.
                // Fortunately, this is the logic used by soln5.GetGuidOfProjectFile... so we can just use that.
                Guid projectId = soln5.GetGuidOfProjectFile(projectFile);
                Debug.Assert(projectId != null, "Not expecting VS to return a null project guid");

                projectPathToProjectIdMap.Add(projectFile, projectId.ToString().Replace("{", "").Replace("}", ""));
            }
        }
        internal /* for testing */ static IDictionary <string, string> BuildProjectPathToIdMap(IVsSolution solution)
        {
            var map = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            // 1. Call with nulls to get the number of files
            const uint grfGetOpsIncludeUnloadedFiles = 0; // required since the projects might not have finished loading
            uint       fileCount;
            var        result = solution.GetProjectFilesInSolution(grfGetOpsIncludeUnloadedFiles, 0, null, out fileCount);

            if (ErrorHandler.Failed(result))
            {
                return(map);
            }

            // 2. Size array and call again to get the data
            string[] fileNames = new string[fileCount];
            result = solution.GetProjectFilesInSolution(grfGetOpsIncludeUnloadedFiles, fileCount, fileNames, out _);
            if (ErrorHandler.Failed(result))
            {
                return(map);
            }

            IVsSolution5 soln5 = (IVsSolution5)solution;

            foreach (string projectFile in fileNames)
            {
                // We need to use the same project id that is used by the Scanner for MSBuild.
                // For non-.Net Core projects, the scanner will use the <ProjectGuid> value in the project.
                // .Net Core projects don't have a <ProjectGuid> property so the scanner uses the GUID allocated
                // to the project in the solution file.
                // Fortunately, this is the logic used by soln5.GetGuidOfProjectFile... so we can just use that.
                Guid projectGuid = soln5.GetGuidOfProjectFile(projectFile);

                // Overwrite duplicate entries. This won't happen for real project files: it will only happen
                // for solution folders with duplicate names, which we don't care about.
                map[projectFile] = projectGuid.ToString().Replace("{", "").Replace("}", "");
            }
            return(map);
        }
Пример #8
0
 public VsSolution5(IVsSolution5 solution)
 {
     _solution = solution;
 }
Пример #9
0
        /// <summary>
        /// Factory method initializing instance of <see cref="ProjectNames"/> with values retrieved from a DTE project.
        /// </summary>
        /// <param name="dteProject">DTE project to get project names for.</param>
        /// <returns>New instance of <see cref="ProjectNames"/>.</returns>
        public static async Task <ProjectNames> FromDTEProjectAsync(EnvDTE.Project dteProject, IVsSolution5 vsSolution5)
        {
            Assumes.Present(dteProject);
            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var fullname         = dteProject.FullName;
            var uniqueName       = EnvDTEProjectInfoUtility.GetUniqueName(dteProject);
            var shortName        = EnvDTEProjectInfoUtility.GetName(dteProject);
            var customUniqueName = await EnvDTEProjectInfoUtility.GetCustomUniqueNameAsync(dteProject);

            var projectId = GetProjectGuid(fullname, vsSolution5);

            return(new ProjectNames(
                       fullName: fullname,
                       uniqueName: uniqueName,
                       shortName: shortName,
                       customUniqueName: customUniqueName,
                       projectId: projectId));
        }
Пример #10
0
 public TestableTextBufferIssueTracker(DTE dte, TaggerProvider provider, ITextDocument document,
                                       IEnumerable <AnalysisLanguage> detectedLanguages, IIssuesFilter issuesFilter,
                                       ISonarErrorListDataSource sonarErrorDataSource, IAnalysisIssueVisualizationConverter converter, IVsSolution5 vsSolution, ILogger logger)
     : base(dte, provider, document, detectedLanguages, issuesFilter, sonarErrorDataSource, converter, vsSolution, logger)
 {
 }