Beispiel #1
0
        internal bool IsCPSProject(CodeAnalysis.Project project)
        {
            _foregroundObject.Value.AssertIsForeground();

            if (this.TryGetHierarchy(project.Id, out var hierarchy))
            {
                // Currently renaming files in CPS projects (i.e. .Net Core) doesn't work proprey.
                // This is because the remove/add of the documents in CPS is not synchronous
                // (despite the DTE interfaces being synchronous).  So Roslyn calls the methods
                // expecting the changes to happen immediately.  Because they are deferred in CPS
                // this causes problems.
                return(hierarchy.IsCapabilityMatch("CPS"));
            }

            return(false);
        }
        private void ScheduleRename(string oldFilePath, string newFilePath)
        {
            string codeExtension = Path.GetExtension(newFilePath);

            if (!oldFilePath.EndsWith(codeExtension, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            CodeAnalysis.Project myProject = _visualStudioWorkspace
                                             .CurrentSolution
                                             .Projects.Where(p => StringComparers.Paths.Equals(p.FilePath, _projectVsServices.Project.FullPath))
                                             .FirstOrDefault();

            if (myProject == null)
            {
                return;
            }

            var renamer = new Renamer(_visualStudioWorkspace, _projectVsServices.ThreadingService, _userNotificationServices, _environmentOptions, _roslynServices, myProject, oldFilePath, newFilePath);

            _visualStudioWorkspace.WorkspaceChanged += renamer.OnWorkspaceChangedAsync;
        }
 private static CodeAnalysis.Document GetDocument(CodeAnalysis.Project project, string?filePath) =>
 project.Documents.FirstOrDefault(d => StringComparers.Paths.Equals(d.FilePath, filePath));
        private static async Task <(bool, Renamer.RenameDocumentActionSet?)> GetRenameSymbolsActionsAsync(CodeAnalysis.Project project, string?oldFilePath, string newFileWithExtension)
        {
            CodeAnalysis.Document?oldDocument = GetDocument(project, oldFilePath);
            if (oldDocument is null)
            {
                return(false, null);
            }

            // Get the list of possible actions to execute
            Renamer.RenameDocumentActionSet documentRenameResult = await Renamer.RenameDocumentAsync(oldDocument, newFileWithExtension);

            // Check if there are any symbols that need to be renamed
            if (documentRenameResult.ApplicableActions.IsEmpty)
            {
                return(false, documentRenameResult);
            }

            // Check errors before applying changes
            if (documentRenameResult.ApplicableActions.Any(a => !a.GetErrors().IsEmpty))
            {
                return(false, documentRenameResult);
            }

            return(true, documentRenameResult);
        }
Beispiel #5
0
        protected override bool CanApplyParseOptionChange(ParseOptions oldOptions, ParseOptions newOptions, CodeAnalysis.Project project)
        {
            var parseOptionsService = project.LanguageServices.GetService <IParseOptionsService>();

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

            // Currently, only changes to the LanguageVersion of parse options are supported.
            var newLanguageVersion = parseOptionsService.GetLanguageVersion(newOptions);
            var updated            = parseOptionsService.WithLanguageVersion(oldOptions, newLanguageVersion);

            return(newOptions == updated);
        }
Beispiel #6
0
 internal override bool CanRenameFilesDuringCodeActions(CodeAnalysis.Project project)
 => !IsCPSProject(project);