public override bool Execute(IProgressIndicator pi) { const int totalWorkUnits = 2; pi.Start(totalWorkUnits); return(base.Execute(pi.CreateSubProgress(1.0)) && ConvertMethods(pi.CreateSubProgress(1.0))); }
private bool ConvertMethods(IProgressIndicator pi) { if (base.NewMembers == null) return false; const int totalWorkUnits = 3; pi.Start(totalWorkUnits); var myWorkflow = Workflow as SharedToExtensionWorkflow; if (myWorkflow != null) Methods = base.NewMembers.OfType<IMethod>().ToList(); using (var progressIndicator = pi.CreateSubProgress(1.0)) FindUsages(progressIndicator); var isSharedToExtension = (this.Direction == SharedToExtensionWorkflow.WorkflowDirection.SharedToExtension); this.Methods.ForEachWithProgress(pi.CreateSubProgress(1.0), "", method => { this.Constructors[method.PresentationLanguage].MakeFirstPrameterThis(method, isSharedToExtension, this.Driver); method.GetPsiServices().Caches.Update(); }); if (isSharedToExtension) using (var progressIndicator = pi.CreateSubProgress(1.0)) MakeCallExtension(progressIndicator); else using (var progressIndicator = pi.CreateSubProgress(1.0)) MakeCallShared(progressIndicator); return true; }
public override ITreeRange Format( ITreeNode firstElement, ITreeNode lastElement, CodeFormatProfile profile, IProgressIndicator pi, IContextBoundSettingsStore overrideSettingsStore = null) { ITreeNode firstNode; ITreeNode lastNode; GetFirstAndLastNode(firstElement, lastElement, out firstNode, out lastNode); using (pi.SafeTotal(4)) { var context = new PsiCodeFormattingContext(this, firstNode, lastNode); if (profile != CodeFormatProfile.INDENT) { using (IProgressIndicator subPi = pi.CreateSubProgress(2)) { using (subPi.SafeTotal(2)) { PsiFormattingStage.DoFormat(context, subPi.CreateSubProgress(1)); PsiIndentingStage.DoIndent(context, subPi.CreateSubProgress(1), false); } } } else { using (IProgressIndicator subPi = pi.CreateSubProgress(4)) { PsiIndentingStage.DoIndent(context, subPi, true); } } } return(new TreeRange(firstElement, lastElement)); }
public override IRefactoringPage CreateRenamesConfirmationPage(IRenameWorkflow renameWorkflow, IProgressIndicator pi) { // do not run find usages too, silent == true for player projects and misc project(misc could happen due to RIDER-53753) // If we run find usages for player/misc declared element, find usages will return empty result, because // guid is resolved to psiSourceFile from real projects only (GetTypeElementFromScriptAssetGuid in AssetUtils) // NOTE: find usages under the hood uses cache which stores TextRanges, cache will not be updated between several atomic renames. // That means that only one atomic rename should exist or only one atomic rename should return non-empty result from find usages below if (myIsRenameShouldBeSilent) { return(null); } var de = myPointer.FindDeclaredElement(); if (de == null) { return(null); } myIsProperty = de is IProperty; pi.Start(1); using (var subProgress = pi.CreateSubProgress()) { myElementsToRename = GetAssetOccurrence(de, subProgress) .Select(t => new UnityEventHandlerOccurrence(t.SourceFile, de.CreateElementPointer(), t.OwningElemetLocation, t.AssetMethodUsages, t.IsPrefabModification)).ToList(); } return(new UnityEventTargetRefactoringPage( ((RefactoringWorkflowBase)renameWorkflow).WorkflowExecuterLifetime, mySolution.GetComponent <DeferredCacheController>())); }
public override ITreeRange Format( ITreeNode firstElement, ITreeNode lastElement, CodeFormatProfile profile, IProgressIndicator pi, IContextBoundSettingsStore overrideSettingsStore = null) { ITreeNode firstNode; ITreeNode lastNode; GetFirstAndLastNode(firstElement, lastElement, out firstNode, out lastNode); var contextBoundSettingsStore = this.GetProperContextBoundSettingsStore(overrideSettingsStore, firstNode); var globalSettings = GlobalFormatSettingsHelper .GetService(firstNode.GetSolution()) .GetSettingsForLanguage(this.myLanguage, firstNode.GetProjectFileType(), contextBoundSettingsStore); using (pi.SafeTotal(4)) { var context = new PsiCodeFormattingContext(this, firstNode, lastNode); if (profile != CodeFormatProfile.INDENT) { using (IProgressIndicator subPi = pi.CreateSubProgress(2)) { using (subPi.SafeTotal(2)) { SecretFormattingStage.DoFormat(context, subPi.CreateSubProgress(1)); SecretIndentingStage.DoIndent(context, globalSettings, subPi.CreateSubProgress(1), false); } } } else { using (IProgressIndicator subPi = pi.CreateSubProgress(4)) { SecretIndentingStage.DoIndent(context, globalSettings, subPi, true); } } } return(new TreeRange(firstElement, lastElement)); }
public override ITreeRange Format( ITreeNode firstElement, ITreeNode lastElement, CodeFormatProfile profile, IProgressIndicator pi, IContextBoundSettingsStore overrideSettingsStore = null) { ITreeNode firstNode; ITreeNode lastNode; GetFirstAndLastNode(firstElement, lastElement, out firstNode, out lastNode); var contextBoundSettingsStore = this.GetProperContextBoundSettingsStore(overrideSettingsStore, firstNode); var globalSettings = GlobalFormatSettingsHelper .GetService(firstNode.GetSolution()) .GetSettingsForLanguage(this.myLanguage, firstNode.GetProjectFileType(), contextBoundSettingsStore); using (pi.SafeTotal(4)) { var context = new PsiCodeFormattingContext(this, firstNode, lastNode); if (profile != CodeFormatProfile.INDENT) { using (IProgressIndicator subPi = pi.CreateSubProgress(2)) { using (subPi.SafeTotal(2)) { SecretFormattingStage.DoFormat(context, subPi.CreateSubProgress(1)); SecretIndentingStage.DoIndent(context, globalSettings, subPi.CreateSubProgress(1), false); } } } else { using (IProgressIndicator subPi = pi.CreateSubProgress(4)) { SecretIndentingStage.DoIndent(context, globalSettings, subPi, true); } } } return new TreeRange(firstElement, lastElement); }
private bool ConvertMethods(IProgressIndicator pi) { if (base.NewMembers == null) { return(false); } const int totalWorkUnits = 3; pi.Start(totalWorkUnits); var myWorkflow = Workflow as SharedToExtensionWorkflow; if (myWorkflow != null) { Methods = base.NewMembers.OfType <IMethod>().ToList(); } using (var progressIndicator = pi.CreateSubProgress(1.0)) FindUsages(progressIndicator); var isSharedToExtension = (this.Direction == SharedToExtensionWorkflow.WorkflowDirection.SharedToExtension); this.Methods.ForEachWithProgress(pi.CreateSubProgress(1.0), "", method => { this.Constructors[method.PresentationLanguage].MakeFirstPrameterThis(method, isSharedToExtension, this.Driver); method.GetPsiServices().Caches.Update(); }); if (isSharedToExtension) { using (var progressIndicator = pi.CreateSubProgress(1.0)) MakeCallExtension(progressIndicator); } else { using (var progressIndicator = pi.CreateSubProgress(1.0)) MakeCallShared(progressIndicator); } return(true); }
public void Process( IPsiSourceFile sourceFile, IRangeMarker rangeMarkerMarker, CodeCleanupProfile profile, IProgressIndicator progressIndicator) { ISolution solution = sourceFile.GetSolution(); if (!profile.GetSetting(OurDescriptor)) { return; } INTriplesFile[] files = sourceFile.GetPsiFiles <NTriplesLanguage>().Cast <INTriplesFile>().ToArray(); using (progressIndicator.SafeTotal("Reformat Psi", files.Length)) { foreach (INTriplesFile file in files) { using (IProgressIndicator pi = progressIndicator.CreateSubProgress(1)) { using (WriteLockCookie.Create()) { var languageService = file.Language.LanguageService(); Assertion.Assert(languageService != null, "languageService != null"); var formatter = languageService.CodeFormatter; Assertion.Assert(formatter != null, "formatter != null"); PsiManager.GetInstance(sourceFile.GetSolution()).DoTransaction( delegate { if (rangeMarkerMarker != null && rangeMarkerMarker.IsValid) { formatter.Format( solution, rangeMarkerMarker.DocumentRange, CodeFormatProfile.DEFAULT, true, false, pi); } else { formatter.FormatFile( file, CodeFormatProfile.DEFAULT, pi); } }, "Code cleanup"); } } } } }
public void Process( IPsiSourceFile sourceFile, IRangeMarker rangeMarkerMarker, CodeCleanupProfile profile, IProgressIndicator progressIndicator) { ISolution solution = sourceFile.GetSolution(); if (!profile.GetSetting(OurDescriptor)) { return; } INTriplesFile[] files = sourceFile.GetPsiFiles<NTriplesLanguage>().Cast<INTriplesFile>().ToArray(); using (progressIndicator.SafeTotal("Reformat Psi", files.Length)) { foreach (INTriplesFile file in files) { using (IProgressIndicator pi = progressIndicator.CreateSubProgress(1)) { using (WriteLockCookie.Create()) { var languageService = file.Language.LanguageService(); Assertion.Assert(languageService != null, "languageService != null"); var formatter = languageService.CodeFormatter; Assertion.Assert(formatter != null, "formatter != null"); PsiManager.GetInstance(sourceFile.GetSolution()).DoTransaction( delegate { if (rangeMarkerMarker != null && rangeMarkerMarker.IsValid) { formatter.Format( solution, rangeMarkerMarker.DocumentRange, CodeFormatProfile.DEFAULT, true, false, pi); } else { formatter.FormatFile( file, CodeFormatProfile.DEFAULT, pi); } }, "Code cleanup"); } } } } }
public void Process(IPsiSourceFile sourceFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, IProgressIndicator progressIndicator, IUserDataHolder cache) { var solution = sourceFile.GetSolution(); if (!profile.GetSetting(ourDescriptor)) { return; } var psiServices = sourceFile.GetPsiServices(); IShaderLabFile[] files; using (new ReleaseLockCookie(psiServices.Locks, LockKind.FullWrite)) { psiServices.Locks.AssertReadAccessAllowed(); files = sourceFile.GetPsiFiles <ShaderLabLanguage>().Cast <IShaderLabFile>().ToArray(); } using (progressIndicator.SafeTotal(Name, files.Length)) { foreach (var file in files) { using (var indicator = progressIndicator.CreateSubProgress(1)) { var service = file.Language.LanguageService(); if (service == null) { return; } var formatter = service.CodeFormatter; sourceFile.GetPsiServices().Transactions.Execute("Code cleanup", delegate { if (rangeMarker != null && rangeMarker.IsValid) { CodeFormatterHelper.Format(file.Language, solution, rangeMarker.DocumentRange, CodeFormatProfile.DEFAULT, true, false, indicator); } else { formatter.FormatFile( file, CodeFormatProfile.DEFAULT, indicator); } }); } } } }
public override IRefactoringPage CreateRenamesConfirmationPage(IRenameWorkflow renameWorkflow, IProgressIndicator pi) { var de = myPointer.FindDeclaredElement(); if (de == null) { return(null); } myIsProperty = de is IProperty; pi.Start(1); using (var subProgress = pi.CreateSubProgress()) { myElementsToRename = GetAssetOccurrence(de, subProgress) .Select(t => new UnityEventHandlerOccurrence(t.SourceFile, de.CreateElementPointer(), t.OwningElemetLocation, t.AssetMethodUsages, t.IsPrefabModification)).ToList(); } return(new UnityEventTargetRefactoringPage( ((RefactoringWorkflowBase)renameWorkflow).WorkflowExecuterLifetime, mySolution.GetComponent <DeferredCacheController>())); }
public override ITreeRange Format(ITreeNode firstElement, ITreeNode lastElement, CodeFormatProfile profile, IProgressIndicator pi, IContextBoundSettingsStore overrideSettingsStore = null) { var firstNode = firstElement; var lastNode = lastElement; Assertion.Assert(firstNode != null || lastNode != null, "The condition (firstNode != null || lastNode != null) is false."); // if first node is null, then start from the file beginning if (firstNode == null) { firstNode = lastNode.PathToRoot().Last(); foreach (var child in firstNode.FirstDescendants()) { if (firstNode == lastNode) { return(new TreeRange(firstElement, lastElement)); } firstNode = child; } } var token = (firstNode as ITokenNode).SkipLeftWhitespaces(); if (token != null) { firstNode = token; } //var solution = firstNode.GetSolution(); //var globalSettings = GlobalFormatSettingsHelper.GetService(solution).GetSettingsForLanguage(LanguageType); //var contextBoundSettingsStore = GetProperContextBoundSettingsStore(overrideSettingsStore, firstNode); //var formatterSettings = new JavaScriptCodeFormattingSettings(contextBoundSettingsStore, mySettingsOptimization, globalSettings); using (firstNode.CreateWriteLock()) using (pi.SafeTotal(4)) { var context = new CodeFormattingContext(this, firstNode, lastNode, NullProgressIndicator.Instance); if (profile != CodeFormatProfile.INDENT) { /*using (var subPi = pi.CreateSubProgress(1)) * { * //FormatterImplHelper.DecoratingIterateNodes(context, context.FirstNode, context.LastNode, new JavaScriptDecorationStage(formatterSettings, profile, subPi)); * }*/ using (var subPi = pi.CreateSubProgress(1)) { using (subPi.SafeTotal(2)) { FormattingStage(context).DoFormat(subPi.CreateSubProgress(1)); IndentingStage().DoIndent(context, subPi.CreateSubProgress(1)); } } } else { using (var subPi = pi.CreateSubProgress(4)) { IndentingStage().DoIndent(context, subPi, true); } } } return(new TreeRange(firstElement, lastElement)); }
public override ITreeRange Format(ITreeNode firstElement, ITreeNode lastElement, CodeFormatProfile profile, [CanBeNull] IProgressIndicator pi, IContextBoundSettingsStore overrideSettingsStore = null) { var psiProfile = new PsiFormatProfile(profile); ITreeNode firstNode = firstElement; ITreeNode lastNode = lastElement; if (firstElement != lastElement) { if (firstElement == null) { firstNode = lastElement; } ITreeNode commonParent = firstNode.FindCommonParent(lastNode); ITreeNode firstChild = firstNode; ITreeNode lastChild = lastElement; while (firstChild.Parent != commonParent) { firstChild = firstChild.Parent; } while (lastChild.Parent != commonParent) { lastChild = lastChild.Parent; } bool hasPrevSibling = false; while (firstNode.NextSibling == null) { if (firstNode.PrevSibling != null) { hasPrevSibling = true; } firstNode = firstNode.Parent; if (firstNode == firstChild) { break; } } if (hasPrevSibling) { while ((firstNode == firstChild) || (firstChild.IsWhitespaceToken())) { firstChild = firstChild.NextSibling; } } firstNode = firstChild; while (firstNode.FirstChild != null) { firstNode = firstNode.FirstChild; } } else { if (firstElement.FirstChild != null) { firstNode = firstElement.FirstChild; lastNode = firstElement.LastChild; } } ISolution solution = firstNode.GetSolution(); var contextBoundSettingsStore = GetProperContextBoundSettingsStore(overrideSettingsStore, firstNode); GlobalFormatSettings globalSettings = GlobalFormatSettingsHelper.GetService(solution).GetSettingsForLanguage(myLanguage); //var formatterSettings = new PsiCodeFormattingSettings(globalSettings, contextBoundSettingsStore.GetKey<CommonFormatterSettingsKey>(mySettingsOptimization)); var formatterSettings = new PsiCodeFormattingSettings(globalSettings); using (pi.SafeTotal(4)) { var context = new PsiCodeFormattingContext(this, firstNode, lastNode, NullProgressIndicator.Instance); if (psiProfile.Profile != CodeFormatProfile.INDENT) { using (pi.CreateSubProgress(1)) { //FormatterImplHelper.DecoratingIterateNodes(context, context.FirstNode, context.LastNode, new PsiDecorationStage(formatterSettings, psiProfile, subPi)); } using (IProgressIndicator subPi = pi.CreateSubProgress(1)) { using (subPi.SafeTotal(2)) { var data = new FormattingStageData(formatterSettings, context, psiProfile, myExtensions.ToList()); PsiFormattingStage.DoFormat(data, subPi.CreateSubProgress(1)); PsiIndentingStage.DoIndent(formatterSettings, context, subPi.CreateSubProgress(1), false); } } } else { using (IProgressIndicator subPi = pi.CreateSubProgress(4)) { PsiIndentingStage.DoIndent(formatterSettings, context, subPi, true); } } } return(new TreeRange(firstElement, lastElement)); }
public override bool Execute(IProgressIndicator pi) { const int totalWorkUnits = 2; pi.Start(totalWorkUnits); return base.Execute(pi.CreateSubProgress(1.0)) && ConvertMethods(pi.CreateSubProgress(1.0)); }