public AddAdditionalDocumentUndoUnit(
     VisualStudioWorkspaceImpl workspace,
     DocumentInfo docInfo,
     SourceText text)
     : base(workspace, docInfo, text)
 {
 }
Ejemplo n.º 2
0
        public CSharpProjectShim(
            ICSharpProjectRoot projectRoot,
            VisualStudioProjectTracker projectTracker,
            Func<ProjectId, IVsReportExternalErrors> reportExternalErrorCreatorOpt,
            string projectSystemName,
            IVsHierarchy hierarchy,
            IServiceProvider serviceProvider,
            VisualStudioWorkspaceImpl visualStudioWorkspaceOpt,
            HostDiagnosticUpdateSource hostDiagnosticUpdateSourceOpt,
            ICommandLineParserService commandLineParserServiceOpt)
            : base(projectTracker,
                   reportExternalErrorCreatorOpt,
                   projectSystemName,
                   hierarchy,
                   LanguageNames.CSharp,
                   serviceProvider,
                   visualStudioWorkspaceOpt,
                   hostDiagnosticUpdateSourceOpt,
                   commandLineParserServiceOpt)
        {
            _projectRoot = projectRoot;
            _warningNumberArrayPointer = Marshal.AllocHGlobal(0);

            // Ensure the default options are set up
            ResetAllOptions();
            UpdateOptions();

            projectTracker.AddProject(this);
        }
 protected AbstractAddRemoveUndoUnit(
     VisualStudioWorkspaceImpl workspace,
     ProjectId fromProjectId)
 {
     Workspace = workspace;
     FromProjectId = fromProjectId;
 }
Ejemplo n.º 4
0
        public AbstractLegacyProject(
            VisualStudioProjectTracker projectTracker,
            Func<ProjectId, IVsReportExternalErrors> reportExternalErrorCreatorOpt,
            string projectSystemName,
            IVsHierarchy hierarchy,
            string language,
            IServiceProvider serviceProvider,
            VisualStudioWorkspaceImpl visualStudioWorkspaceOpt,
            HostDiagnosticUpdateSource hostDiagnosticUpdateSourceOpt,
            ICommandLineParserService commandLineParserServiceOpt = null)
            : base(projectTracker,
                  reportExternalErrorCreatorOpt,
                  projectSystemName,
                  projectFilePath: GetProjectFilePath(hierarchy),
                  hierarchy: hierarchy,
                  projectGuid: GetProjectIDGuid(hierarchy),
                  language: language,
                  serviceProvider: serviceProvider,
                  visualStudioWorkspaceOpt: visualStudioWorkspaceOpt,
                  hostDiagnosticUpdateSourceOpt: hostDiagnosticUpdateSourceOpt,
                  commandLineParserServiceOpt: commandLineParserServiceOpt)
        {
            if (Hierarchy != null)
            {
                ConnectHierarchyEvents();
                this.IsWebSite = GetIsWebsiteProject(Hierarchy);
            }

            // Initialize command line arguments.
            base.SetArguments(commandLine: string.Empty);
        }
Ejemplo n.º 5
0
        public NavigationBarClient(
            IVsDropdownBarManager manager,
            IVsCodeWindow codeWindow,
            IServiceProvider serviceProvider,
            VisualStudioWorkspaceImpl workspace)
        {
            _manager = manager;
            _codeWindow = codeWindow;
            _workspace = workspace;
            _imageService = (IVsImageService2)serviceProvider.GetService(typeof(SVsImageService));
            _projectItems = SpecializedCollections.EmptyList<NavigationBarProjectItem>();
            _currentTypeItems = SpecializedCollections.EmptyList<NavigationBarItem>();

            var vsShell = serviceProvider.GetService(typeof(SVsShell)) as IVsShell;
            if (vsShell != null)
            {
                object varImageList;
                int hresult = vsShell.GetProperty((int)__VSSPROPID.VSSPROPID_ObjectMgrTypesImgList, out varImageList);
                if (ErrorHandler.Succeeded(hresult) && varImageList != null)
                {
                    _imageList = (IntPtr)(int)varImageList;
                }
            }

            _codeWindowEventsSink = ComEventSink.Advise<IVsCodeWindowEvents>(codeWindow, this);
            _editorAdaptersFactoryService = serviceProvider.GetMefService<IVsEditorAdaptersFactoryService>();

            IVsTextView pTextView;
            codeWindow.GetPrimaryView(out pTextView);
            StartTrackingView(pTextView);

            pTextView = null;
            codeWindow.GetSecondaryView(out pTextView);
            StartTrackingView(pTextView);
        }
 protected AbstractRemoveDocumentUndoUnit(
     VisualStudioWorkspaceImpl workspace,
     DocumentId documentId)
     : base(workspace, documentId.ProjectId)
 {
     DocumentId = documentId;
 }
 public VisualStudioErrorReportingServiceFactory(
     VisualStudioWorkspaceImpl workspace, 
     IForegroundNotificationService foregroundNotificationService,
     [ImportMany] IEnumerable<Lazy<IAsynchronousOperationListener, FeatureMetadata>> asyncListeners)
 {
     _singleton = new VisualStudioErrorReportingService(workspace, foregroundNotificationService, new AggregateAsynchronousOperationListener(asyncListeners, FeatureAttribute.InfoBar));
 }
Ejemplo n.º 8
0
        public AbstractLegacyProject(
            VisualStudioProjectTracker projectTracker,
            Func<ProjectId, IVsReportExternalErrors> reportExternalErrorCreatorOpt,
            string projectSystemName,
            IVsHierarchy hierarchy,
            string language,
            IServiceProvider serviceProvider,
            VisualStudioWorkspaceImpl visualStudioWorkspaceOpt,
            HostDiagnosticUpdateSource hostDiagnosticUpdateSourceOpt)
            : base(projectTracker,
                  reportExternalErrorCreatorOpt,
                  projectSystemName,
                  projectFilePath: GetProjectFilePath(hierarchy),
                  projectGuid: GetProjectIDGuid(hierarchy),
                  projectTypeGuid: GetProjectType(hierarchy),
                  hierarchy: hierarchy,
                  language: language,
                  serviceProvider: serviceProvider,
                  visualStudioWorkspaceOpt: visualStudioWorkspaceOpt,
                  hostDiagnosticUpdateSourceOpt: hostDiagnosticUpdateSourceOpt)
        {
            ConnectHierarchyEvents();

            this.IsWebSite = GetIsWebsiteProject(hierarchy);

            _lastParsedCompilerOptions = string.Empty;
            var commandLineArguments = ParseCommandLineArguments(SpecializedCollections.EmptyEnumerable<string>());
            base.SetArguments(commandLineArguments);
        }
Ejemplo n.º 9
0
        public CPSProject(
            VisualStudioProjectTracker projectTracker,
            Func<ProjectId, IVsReportExternalErrors> reportExternalErrorCreatorOpt,
            string projectDisplayName,
            string projectFilePath,
            IVsHierarchy hierarchy,
            string language,
            Guid projectGuid,
            string commandLineForOptions,
            IServiceProvider serviceProvider,
            VisualStudioWorkspaceImpl visualStudioWorkspaceOpt,
            HostDiagnosticUpdateSource hostDiagnosticUpdateSourceOpt,
            ICommandLineParserService commandLineParserServiceOpt)
            : base(projectTracker, reportExternalErrorCreatorOpt, projectDisplayName, projectFilePath,
                   hierarchy, language, projectGuid, serviceProvider, visualStudioWorkspaceOpt, hostDiagnosticUpdateSourceOpt, commandLineParserServiceOpt)
        {
            // Initialize the options.
            SetCommandLineArguments(commandLineForOptions);

            // We need to ensure that the bin output path for the project has been initialized before we hookup the project with the project tracker.
            // If we were unable to set the output path from SetCommandLineArguments (due to null output file name or directory in the given commandLineForOptions),
            // we set a default unique output path.
            if (this.TryGetBinOutputPath() == null)
            {
                var uniqueDefaultOutputPath = PathUtilities.CombinePathsUnchecked(Path.GetTempPath(), projectDisplayName + projectGuid.GetHashCode().ToString());
                SetOutputPathAndRelatedData(objOutputPath: uniqueDefaultOutputPath, hasSameBinAndObjOutputPaths: true);
            }

            Contract.ThrowIfNull(this.TryGetBinOutputPath());

            // Now hook up the project to the project tracker.
            projectTracker.AddProject(this);

            _lastDesignTimeBuildSucceeded = true;
        }
Ejemplo n.º 10
0
 public PackageInstallerService(
     VisualStudioWorkspaceImpl workspace,
     IVsEditorAdaptersFactoryService editorAdaptersFactoryService)
 {
     _workspace = workspace;
     _editorAdaptersFactoryService = editorAdaptersFactoryService;
 }
 public VisualStudioErrorReportingService(
     VisualStudioWorkspaceImpl workspace, IForegroundNotificationService foregroundNotificationService, IAsynchronousOperationListener listener)
 {
     _workspace = workspace;
     _foregroundNotificationService = foregroundNotificationService;
     _listener = listener;
 }
Ejemplo n.º 12
0
        public CSharpProjectShim(
            ICSharpProjectRoot projectRoot,
            VisualStudioProjectTracker projectTracker,
            Func<ProjectId, IVsReportExternalErrors> reportExternalErrorCreatorOpt,
            string projectSystemName,
            IVsHierarchy hierarchy,
            IServiceProvider serviceProvider,
            MiscellaneousFilesWorkspace miscellaneousFilesWorkspaceOpt,
            VisualStudioWorkspaceImpl visualStudioWorkspaceOpt,
            HostDiagnosticUpdateSource hostDiagnosticUpdateSourceOpt)
            : base(projectTracker,
                   reportExternalErrorCreatorOpt,
                   projectSystemName,
                   hierarchy,
                   LanguageNames.CSharp,
                   serviceProvider,
                   miscellaneousFilesWorkspaceOpt,
                   visualStudioWorkspaceOpt,
                   hostDiagnosticUpdateSourceOpt)
        {
            _projectRoot = projectRoot;
            _warningNumberArrayPointer = Marshal.AllocHGlobal(0);

            InitializeOptions();

            projectTracker.AddProject(this);
        }
        public VisualStudioWorkspaceDiagnosticAnalyzerProviderService(VisualStudioWorkspaceImpl workspace)
        {
            // Get the analyzer assets for installed VSIX extensions through the VSIX extension manager.
            var extensionManager = workspace.GetVsService<SVsExtensionManager, IVsExtensionManager>();

            _hostDiagnosticAnalyzerInfo = GetHostAnalyzerPackagesWithName(extensionManager);
        }
 public AnalyzerDependencyCheckingService(
     VisualStudioWorkspaceImpl workspace,
     HostDiagnosticUpdateSource updateSource)
 {
     _workspace = workspace;
     _updateSource = updateSource;
 }
 public RemoveMetadataReferenceUndoUnit(
     VisualStudioWorkspaceImpl workspace, 
     ProjectId fromProjectId, 
     string filePath)
     : base(workspace, fromProjectId)
 {
     _filePath = filePath;
 }
 public AnalyzerDependencyCheckingService(
     VisualStudioWorkspaceImpl workspace,
     HostDiagnosticUpdateSource updateSource)
 {
     _workspace = workspace;
     _updateSource = updateSource;
     _bindingRedirectionService = new BindingRedirectionService();
 }
 public RemoveProjectReferenceUndoUnit(
     VisualStudioWorkspaceImpl workspace, 
     ProjectId fromProjectId, 
     ProjectId toProjectId)
     : base(workspace, fromProjectId)
 {
     _toProjectId = toProjectId;
 }
Ejemplo n.º 18
0
 public CPSProjectFactory(
     SVsServiceProvider serviceProvider,
     VisualStudioWorkspaceImpl visualStudioWorkspace,
     HostDiagnosticUpdateSource hostDiagnosticUpdateSource)
 {
     _serviceProvider = serviceProvider;
     _visualStudioWorkspace = visualStudioWorkspace;
     _hostDiagnosticUpdateSource = hostDiagnosticUpdateSource;
 }
Ejemplo n.º 19
0
 public AnalyzerFileWatcherService(
     VisualStudioWorkspaceImpl workspace,
     HostDiagnosticUpdateSource hostDiagnosticUpdateSource,
     SVsServiceProvider serviceProvider)
 {
     _workspace = workspace;
     _updateSource = hostDiagnosticUpdateSource;
     _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx));
 }
 protected AbstractAddDocumentUndoUnit(
     VisualStudioWorkspaceImpl workspace,
     DocumentInfo docInfo,
     SourceText text)
     : base(workspace, docInfo.Id.ProjectId)
 {
     DocumentInfo = docInfo;
     Text = text;
 }
        public VisualStudioErrorReportingService(
            VisualStudioWorkspaceImpl workspace, IForegroundNotificationService foregroundNotificationService, IAsynchronousOperationListener listener)
        {
            _workspace = workspace;
            _foregroundNotificationService = foregroundNotificationService;
            _listener = listener;

            _documentTrackingService = workspace.Services.GetService<IDocumentTrackingService>();
        }
        public ProjectExternalErrorReporter(ProjectId projectId, string errorCodePrefix, IServiceProvider serviceProvider)
        {
            _projectId = projectId;
            _errorCodePrefix = errorCodePrefix;
            _diagnosticProvider = serviceProvider.GetMefService<ExternalErrorDiagnosticUpdateSource>();
            _workspace = serviceProvider.GetMefService<VisualStudioWorkspaceImpl>();

            Debug.Assert(_diagnosticProvider != null);
            Debug.Assert(_workspace != null);
        }
Ejemplo n.º 23
0
 public PackageInstallerService(
     VisualStudioWorkspaceImpl workspace,
     IVsEditorAdaptersFactoryService editorAdaptersFactoryService)
     : base(workspace, SymbolSearchOptions.Enabled,
                       SymbolSearchOptions.SuggestForTypesInReferenceAssemblies,
                       SymbolSearchOptions.SuggestForTypesInNuGetPackages)
 {
     _workspace = workspace;
     _editorAdaptersFactoryService = editorAdaptersFactoryService;
 }
Ejemplo n.º 24
0
 public CPSProjectFactory(
     SVsServiceProvider serviceProvider,
     VisualStudioWorkspaceImpl visualStudioWorkspace,
     HostDiagnosticUpdateSource hostDiagnosticUpdateSource)
 {
     _serviceProvider = serviceProvider;
     _visualStudioWorkspace = visualStudioWorkspace;
     _hostDiagnosticUpdateSource = hostDiagnosticUpdateSource;
     _externalErrorReporterMap = new Dictionary<string, IVsReportExternalErrors>(StringComparer.OrdinalIgnoreCase);
 }
        public AnalyzerFileWatcherService(
            VisualStudioWorkspaceImpl workspace,
            HostDiagnosticUpdateSource hostDiagnosticUpdateSource,
            SVsServiceProvider serviceProvider)
        {
            _workspace = workspace;
            _updateSource = hostDiagnosticUpdateSource;
            _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx));

            InMemoryAssemblyProvider.AssemblyLoad += AnalyzerFileReference_AssemblyLoad;
        }
            public WorkspaceHost(
                VisualStudioWorkspaceImpl workspace,
                RemoteHostClient client)
            {
                _workspace = workspace;
                _client = client;
                _currentSolutionId = workspace.CurrentSolution.Id;

                // Ensure that we populate the remote service with the initial state of
                // the workspace's solution.
                RegisterPrimarySolutionAsync().Wait();
            }
        public VisualStudioWorkspaceDiagnosticAnalyzerProviderService(VisualStudioWorkspaceImpl workspace)
        {
            // Microsoft.VisualStudio.ExtensionManager is non-versioned, so we need to dynamically load it, depending on the version of VS we are running on
            // this will allow us to build once and deploy on different versions of VS SxS.
            var vsDteVersion = Version.Parse(workspace.GetVsDte().Version.Split(' ')[0]); // DTE.Version is in the format of D[D[.D[D]]][ (?+)], so we need to split out the version part and check for uninitialized Major/Minor below
            var assembly = Assembly.Load($"Microsoft.VisualStudio.ExtensionManager, Version={(vsDteVersion.Major == -1 ? 0 : vsDteVersion.Major)}.{(vsDteVersion.Minor == -1 ? 0 : vsDteVersion.Minor)}.0.0, PublicKeyToken=b03f5f7f11d50a3a");

            // Get the analyzer assets for installed VSIX extensions through the VSIX extension manager.
            var extensionManager = workspace.GetVsService(assembly.GetType("Microsoft.VisualStudio.ExtensionManager.SVsExtensionManager"));

            _hostDiagnosticAnalyzerInfo = GetHostAnalyzerPackagesWithName(extensionManager, assembly.GetType("Microsoft.VisualStudio.ExtensionManager.IExtensionContent"));
        }
Ejemplo n.º 28
0
 public XamlProject(VisualStudioProjectTracker projectTracker, IVsHierarchy hierarchy, IServiceProvider serviceProvider, VisualStudioWorkspaceImpl visualStudioWorkspace) :
     base(
         projectTracker,
         reportExternalErrorCreatorOpt: null,
         projectSystemName: $"{XamlProject.GetProjectName(hierarchy)}-{nameof(XamlProject)}",
         hierarchy: hierarchy,
         language: StringConstants.XamlLanguageName,
         serviceProvider: serviceProvider,
         visualStudioWorkspaceOpt: visualStudioWorkspace,
         hostDiagnosticUpdateSourceOpt: null)
 {
     projectTracker.AddProject(this);
 }
        public VisualStudioSymbolSearchService(
            VisualStudioWorkspaceImpl workspace,
            VSShell.SVsServiceProvider serviceProvider)
            : base(workspace, SymbolSearchOptions.Enabled,
                              SymbolSearchOptions.SuggestForTypesInReferenceAssemblies,
                              SymbolSearchOptions.SuggestForTypesInNuGetPackages)
        {
            _workspace = workspace;
            _installerService = workspace.Services.GetService<IPackageInstallerService>();
            _localSettingsDirectory = new ShellSettingsManager(serviceProvider).GetApplicationDataFolder(ApplicationDataFolder.LocalSettings);

            _logService = new LogService((IVsActivityLog)serviceProvider.GetService(typeof(SVsActivityLog)));
        }
Ejemplo n.º 30
0
        public CommentTaskTokenSerializer(
            VisualStudioWorkspaceImpl workspace)
        {
            _optionService = workspace.Services.GetService<IOptionService>();

            _taskList = workspace.GetVsService<SVsTaskList, ITaskList>();
            _lastCommentTokenCache = GetTaskTokenList(_taskList);

            // The SVsTaskList may not be available (e.g. during "devenv /build")
            if (_taskList != null)
            {
                _taskList.PropertyChanged += OnPropertyChanged;
            }
        }
        public ProjectExternalErrorReporter(ProjectId projectId, string errorCodePrefix, string language, VisualStudioWorkspaceImpl workspace)
        {
            Debug.Assert(projectId != null);
            Debug.Assert(errorCodePrefix != null);
            Debug.Assert(workspace != null);

            _projectId       = projectId;
            _errorCodePrefix = errorCodePrefix;
            _language        = language;
            _workspace       = workspace;
        }
Ejemplo n.º 32
0
 public HierarchyItemToProjectIdMap(VisualStudioWorkspaceImpl workspace)
 {
     _workspace = workspace;
 }
Ejemplo n.º 33
0
        public HostDiagnosticUpdateSource(VisualStudioWorkspaceImpl workspace, IDiagnosticUpdateSourceRegistrationService registrationService)
        {
            _workspace = workspace;

            registrationService.Register(this);
        }
        private static bool TryAdjustSpanIfNeededForVenus(VisualStudioWorkspaceImpl workspace, DocumentId documentId, int originalLine, int originalColumn, out MappedSpan mappedSpan)
        {
            mappedSpan = default;

            if (documentId == null)
            {
                return(false);
            }

            var containedDocument = workspace.GetHostDocument(documentId) as ContainedDocument;

            if (containedDocument == null)
            {
                return(false);
            }

            var originalSpanOnSecondaryBuffer = new TextManager.Interop.TextSpan()
            {
                iStartLine  = originalLine,
                iStartIndex = originalColumn,
                iEndLine    = originalLine,
                iEndIndex   = originalColumn
            };

            var containedLanguage     = containedDocument.ContainedLanguage;
            var bufferCoordinator     = containedLanguage.BufferCoordinator;
            var containedLanguageHost = containedLanguage.ContainedLanguageHost;

            var spansOnPrimaryBuffer = new TextManager.Interop.TextSpan[1];

            if (VSConstants.S_OK == bufferCoordinator.MapSecondaryToPrimarySpan(originalSpanOnSecondaryBuffer, spansOnPrimaryBuffer))
            {
                // easy case, we can map span in subject buffer to surface buffer. no need to adjust any span
                mappedSpan = new MappedSpan(originalLine, originalColumn, spansOnPrimaryBuffer[0].iStartLine, spansOnPrimaryBuffer[0].iStartIndex);
                return(true);
            }

            // we can't directly map span in subject buffer to surface buffer. see whether there is any visible span we can use from the subject buffer span
            if (containedLanguageHost != null &&
                VSConstants.S_OK != containedLanguageHost.GetNearestVisibleToken(originalSpanOnSecondaryBuffer, spansOnPrimaryBuffer))
            {
                // no visible span we can use.
                return(false);
            }

            // We need to map both the original and mapped location into visible code so that features such as error list, squiggle, etc. points to user visible area
            // We have the mapped location in the primary buffer.
            var nearestVisibleSpanOnPrimaryBuffer = new TextManager.Interop.TextSpan()
            {
                iStartLine  = spansOnPrimaryBuffer[0].iStartLine,
                iStartIndex = spansOnPrimaryBuffer[0].iStartIndex,
                iEndLine    = spansOnPrimaryBuffer[0].iStartLine,
                iEndIndex   = spansOnPrimaryBuffer[0].iStartIndex
            };

            // Map this location back to the secondary span to re-adjust the original location to be in user-code in secondary buffer.
            var spansOnSecondaryBuffer = new TextManager.Interop.TextSpan[1];

            if (VSConstants.S_OK != bufferCoordinator.MapPrimaryToSecondarySpan(nearestVisibleSpanOnPrimaryBuffer, spansOnSecondaryBuffer))
            {
                // we can't adjust original position but we can adjust mapped one
                mappedSpan = new MappedSpan(originalLine, originalColumn, nearestVisibleSpanOnPrimaryBuffer.iStartLine, nearestVisibleSpanOnPrimaryBuffer.iStartIndex);
                return(true);
            }

            var nearestVisibleSpanOnSecondaryBuffer = spansOnSecondaryBuffer[0];
            var originalLocationMovedAboveInFile    = IsOriginalLocationMovedAboveInFile(originalLine, originalColumn, nearestVisibleSpanOnSecondaryBuffer.iStartLine, nearestVisibleSpanOnSecondaryBuffer.iStartIndex);

            if (!originalLocationMovedAboveInFile)
            {
                mappedSpan = new MappedSpan(nearestVisibleSpanOnSecondaryBuffer.iStartLine, nearestVisibleSpanOnSecondaryBuffer.iStartIndex, nearestVisibleSpanOnPrimaryBuffer.iStartLine, nearestVisibleSpanOnPrimaryBuffer.iStartIndex);
                return(true);
            }

            if (TryFixUpNearestVisibleSpan(containedLanguageHost, bufferCoordinator, nearestVisibleSpanOnSecondaryBuffer.iStartLine, nearestVisibleSpanOnSecondaryBuffer.iStartIndex, out var adjustedPosition))
            {
                // span has changed yet again, re-calculate span
                return(TryAdjustSpanIfNeededForVenus(workspace, documentId, adjustedPosition.Line, adjustedPosition.Character, out mappedSpan));
            }

            mappedSpan = new MappedSpan(nearestVisibleSpanOnSecondaryBuffer.iStartLine, nearestVisibleSpanOnSecondaryBuffer.iStartIndex, nearestVisibleSpanOnPrimaryBuffer.iStartLine, nearestVisibleSpanOnPrimaryBuffer.iStartIndex);
            return(true);
        }
Ejemplo n.º 35
0
        private async Task SetSeverityHandlerAsync(VisualStudioWorkspaceImpl workspace, MenuCommand selectedItem, ArrayBuilder <string> notificationMessages)
        {
            using var token = _listener.BeginAsyncOperation(nameof(SetSeverityHandler));
            var componentModel            = (IComponentModel)_serviceProvider.GetService(typeof(SComponentModel));
            var uiThreadOperationExecutor = componentModel.GetService <VSUtilities.IUIThreadOperationExecutor>();

            using var context = uiThreadOperationExecutor.BeginExecute(
                      title: ServicesVSResources.Updating_severity,
                      defaultDescription: "",
                      allowCancellation: true,
                      showProgress: true);

            var selectedAction = MapSelectedItemToReportDiagnostic(selectedItem);

            if (!selectedAction.HasValue)
            {
                return;
            }

            foreach (var selectedDiagnostic in _tracker.SelectedDiagnosticItems)
            {
                var projectId     = selectedDiagnostic.ProjectId;
                var pathToRuleSet = workspace.TryGetRuleSetPathForProject(projectId);

                var project = workspace.CurrentSolution.GetProject(projectId);
                var pathToAnalyzerConfigDoc = project?.TryGetAnalyzerConfigPathForProjectConfiguration();

                if (pathToRuleSet == null && pathToAnalyzerConfigDoc == null)
                {
                    notificationMessages.Add(SolutionExplorerShim.No_rule_set_file_is_specified_or_the_file_does_not_exist);
                    continue;
                }

                var editHandlerService = componentModel.GetService <ICodeActionEditHandlerService>();

                try
                {
                    var envDteProject = workspace.TryGetDTEProject(projectId);

                    if (pathToRuleSet == null || SdkUiUtilities.IsBuiltInRuleSet(pathToRuleSet, _serviceProvider))
                    {
                        // If project is using the default built-in ruleset or no ruleset, then prefer .editorconfig for severity configuration.
                        if (pathToAnalyzerConfigDoc != null)
                        {
                            using var scope1 = context.AddScope(allowCancellation: true, description: "");
                            var newSolution = await selectedDiagnostic.GetSolutionWithUpdatedAnalyzerConfigSeverityAsync(selectedAction.Value, project, context.UserCancellationToken).ConfigureAwait(false);

                            var operations = ImmutableArray.Create <CodeActionOperation>(new ApplyChangesOperation(newSolution));
                            await editHandlerService.ApplyAsync(
                                _workspace,
                                fromDocument : null,
                                operations : operations,
                                title : ServicesVSResources.Updating_severity,
                                progressTracker : new UIThreadOperationContextProgressTracker(scope1),
                                cancellationToken : context.UserCancellationToken).ConfigureAwait(true);

                            continue;
                        }

                        // Otherwise, fall back to using ruleset.
                        if (pathToRuleSet == null)
                        {
                            notificationMessages.Add(SolutionExplorerShim.No_rule_set_file_is_specified_or_the_file_does_not_exist);
                            continue;
                        }

                        pathToRuleSet = CreateCopyOfRuleSetForProject(pathToRuleSet, envDteProject);
                        if (pathToRuleSet == null)
                        {
                            notificationMessages.Add(string.Format(SolutionExplorerShim.Could_not_create_a_rule_set_for_project_0, envDteProject.Name));
                            continue;
                        }

                        var fileInfo = new FileInfo(pathToRuleSet);
                        fileInfo.IsReadOnly = false;
                    }

                    using var scope2 = context.AddScope(
                              allowCancellation: false,
                              string.Format(SolutionExplorerShim.Checking_out_0_for_editing, Path.GetFileName(pathToRuleSet)));

                    if (envDteProject.DTE.SourceControl.IsItemUnderSCC(pathToRuleSet))
                    {
                        envDteProject.DTE.SourceControl.CheckOutItem(pathToRuleSet);
                    }

                    selectedDiagnostic.SetRuleSetSeverity(selectedAction.Value, pathToRuleSet);
                }
                catch (Exception e)
                {
                    notificationMessages.Add(e.Message);
                }
            }
        }
Ejemplo n.º 36
0
 public VisualStudioProjectTelemetryService(VisualStudioWorkspaceImpl workspace, IThreadingContext threadingContext) : base(threadingContext)
     => _workspace = workspace;
Ejemplo n.º 37
0
 public Analyzer(IForegroundNotificationService notificationService, IAsynchronousOperationListener listener, VisualStudioWorkspaceImpl workspace)
 {
     _notificationService = notificationService;
     _listener            = listener;
     _workspace           = workspace;
 }
Ejemplo n.º 38
0
 public ProjectCodeModel(ProjectId projectId, ICodeModelInstanceFactory codeModelInstanceFactory, VisualStudioWorkspaceImpl visualStudioWorkspace, IServiceProvider serviceProvider)
 {
     _projectId = projectId;
     _codeModelInstanceFactory = codeModelInstanceFactory;
     _visualStudioWorkspace    = visualStudioWorkspace;
     _serviceProvider          = serviceProvider;
 }
 public SolutionExplorerWorkspaceProvider(VisualStudioWorkspaceImpl workspace)
 {
     _workspace = workspace;
 }
Ejemplo n.º 40
0
 public CSharpProjectCodeModel(CSharpProjectShimWithServices project, VisualStudioWorkspaceImpl visualStudioWorkspace, IServiceProvider serviceProvider)
     : base(project, visualStudioWorkspace, serviceProvider)
 {
     _project = project;
 }
Ejemplo n.º 41
0
 public VisualStudioVenusSpanMappingService(VisualStudioWorkspaceImpl workspace) =>
Ejemplo n.º 42
0
 public CSharpCodeCleanUpFixer(IThreadingContext threadingContext, VisualStudioWorkspaceImpl workspace, IVsHierarchyItemManager vsHierarchyItemManager)
 {
     _threadingContext       = threadingContext;
     _workspace              = workspace;
     _vsHierarchyItemManager = vsHierarchyItemManager;
 }
Ejemplo n.º 43
0
 public CSharpCodeCleanUpFixer(IThreadingContext threadingContext, VisualStudioWorkspaceImpl workspace, IVsHierarchyItemManager vsHierarchyItemManager, IGlobalOptionService globalOptions)
     : base(threadingContext, workspace, vsHierarchyItemManager, globalOptions)
 {
 }
Ejemplo n.º 44
0
 public CSharpCodeCleanUpFixer(IThreadingContext threadingContext, VisualStudioWorkspaceImpl workspace, IVsHierarchyItemManager vsHierarchyItemManager)
     : base(threadingContext, workspace, vsHierarchyItemManager)
 {
 }
 public CSharpSettingsManagerOptionSerializer(VisualStudioWorkspaceImpl workspace)
     : base(workspace)
 {
 }
Ejemplo n.º 46
0
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(true);

            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            var shell = (IVsShell) await GetServiceAsync(typeof(SVsShell)).ConfigureAwait(true);

            var solution = (IVsSolution) await GetServiceAsync(typeof(SVsSolution)).ConfigureAwait(true);

            cancellationToken.ThrowIfCancellationRequested();
            Assumes.Present(shell);
            Assumes.Present(solution);

            foreach (var editorFactory in CreateEditorFactories())
            {
                RegisterEditorFactory(editorFactory);
            }

            RegisterLanguageService(typeof(TLanguageService), async ct =>
            {
                await JoinableTaskFactory.SwitchToMainThreadAsync(ct);

                // Create the language service, tell it to set itself up, then store it in a field
                // so we can notify it that it's time to clean up.
                _languageService = CreateLanguageService();
                _languageService.Setup();
                return(_languageService.ComAggregate);
            });

            // Okay, this is also a bit strange.  We need to get our Interop dll into our process,
            // but we're in the GAC.  Ask the base Roslyn Package to load, and it will take care of
            // it for us.
            // * NOTE * workspace should never be created before loading roslyn package since roslyn package
            //          installs a service roslyn visual studio workspace requires
            shell.LoadPackage(Guids.RoslynPackageId, out var setupPackage);

            _miscellaneousFilesWorkspace = this.ComponentModel.GetService <MiscellaneousFilesWorkspace>();
            if (_miscellaneousFilesWorkspace != null)
            {
                // make sure solution crawler start once everything has been setup.
                _miscellaneousFilesWorkspace.StartSolutionCrawler();
            }

            RegisterMiscellaneousFilesWorkspaceInformation(_miscellaneousFilesWorkspace);

            this.Workspace = this.CreateWorkspace();
            if (await IsInIdeModeAsync(this.Workspace, cancellationToken).ConfigureAwait(true))
            {
                // make sure solution crawler start once everything has been setup.
                // this also should be started before any of workspace events start firing
                this.Workspace.StartSolutionCrawler();

                // start remote host
                EnableRemoteHostClientService();

                Workspace.AdviseSolutionEvents(solution);
            }

            // Ensure services that must be created on the UI thread have been.
            HACK_AbstractCreateServicesOnUiThread.CreateServicesOnUIThread(ComponentModel, RoslynLanguageName);

            LoadComponentsInUIContextOnceSolutionFullyLoaded(cancellationToken);
        }
Ejemplo n.º 47
0
 public HierarchyEventsSink(VisualStudioWorkspaceImpl visualStudioWorkspace, IVsHierarchy sharedHierarchy, DocumentId documentId)
 {
     _workspace       = visualStudioWorkspace;
     _sharedHierarchy = sharedHierarchy;
     _documentId      = documentId;
 }
Ejemplo n.º 48
0
 public AbstractProjectCodeModel(AbstractProject project, VisualStudioWorkspaceImpl visualStudioWorkspace, IServiceProvider serviceProvider)
 {
     VSProject             = project;
     VisualStudioWorkspace = visualStudioWorkspace;
     ServiceProvider       = serviceProvider;
 }
Ejemplo n.º 49
0
        private Dictionary <IVsHierarchy, List <uint> > GetHierarchiesAndItemIDsFromDocumentIDs(VisualStudioWorkspaceImpl visualStudioWorkspace, IEnumerable <DocumentId> changedDocumentIDs)
        {
            AssertIsForeground();

            var hierarchyToItemIDsMap = new Dictionary <IVsHierarchy, List <uint> >();

            foreach (var docID in changedDocumentIDs)
            {
                var project = visualStudioWorkspace.GetHostProject(docID.ProjectId);
                var itemID  = project.GetDocumentOrAdditionalDocument(docID).GetItemId();

                if (itemID == (uint)VSConstants.VSITEMID.Nil)
                {
                    continue;
                }

                if (!hierarchyToItemIDsMap.TryGetValue(project.Hierarchy, out var itemIDsForCurrentHierarchy))
                {
                    itemIDsForCurrentHierarchy = new List <uint>();
                    hierarchyToItemIDsMap.Add(project.Hierarchy, itemIDsForCurrentHierarchy);
                }

                if (!itemIDsForCurrentHierarchy.Contains(itemID))
                {
                    itemIDsForCurrentHierarchy.Add(itemID);
                }
            }

            return(hierarchyToItemIDsMap);
        }
Ejemplo n.º 50
0
 public VisualStudioDiagnosticAnalyzerService(VisualStudioWorkspaceImpl workspace, IDiagnosticAnalyzerService diagnosticService)
 {
     _workspace         = workspace;
     _diagnosticService = diagnosticService;
 }
Ejemplo n.º 51
0
 public VisualStudioErrorReportingServiceFactory(VisualStudioWorkspaceImpl workspace, IForegroundNotificationService foregroundNotificationService)
 {
     _singleton = new Lazy <IErrorReportingService>(() => new VisualStudioErrorReportingService(workspace, foregroundNotificationService));
 }
Ejemplo n.º 52
0
 public WorkspaceHost(VisualStudioWorkspaceImpl workspace, KeepAliveSession session)
 {
     _workspace         = workspace;
     _currentSolutionId = workspace.CurrentSolution.Id;
     _session           = session;
 }