public static void PokeReSharpersAssemblyReferences(IPsiModule module, IEnumerable <FileSystemPath> assemblyLocations, string packageLocation, IProjectPsiModule projectModule) { if (string.IsNullOrEmpty(packageLocation)) { return; } // TODO: I wish we didn't have to do this // When NuGet references the assemblies, they are queued up to be processed, but after // this method completes. Which means the import type part of the process fails to find // the type to import. We force an update which works through the system early. It would // be nice to find out if we can process the proper import notifications instead using (var cookie = module.GetSolution() .CreateTransactionCookie(DefaultAction.Commit, "ReferenceModuleWithType", NullProgressIndicator.Instance)) { var assemblyLocation = assemblyLocations.FirstOrDefault( l => l.FullPath.StartsWith(packageLocation, StringComparison.InvariantCultureIgnoreCase)); if (!assemblyLocation.IsNullOrEmpty()) { cookie.AddAssemblyReference(projectModule.Project, assemblyLocation); } } }
private static bool ExecuteTransaction([NotNull] IPsiModule module, [NotNull] Action action) { PsiManager psiManager = PsiManager.GetInstance(module.GetSolution()); if (psiManager.HasActiveTransaction) { action(); return(true); } return(psiManager.DoTransaction(action, "T4 Assembly Reference").Succeded); }
public bool CanReferenceModule(IPsiModule module, IPsiModule moduleToReference) { if (!IsProjectModule(module) || !IsAssemblyModule(moduleToReference)) return false; Logger.LogMessage(LoggingLevel.VERBOSE, "[NUGET PLUGIN] Checking if module '{0}' is a nuget package", moduleToReference.DisplayName); var assemblyLocations = GetAllAssemblyLocations(moduleToReference); var canReference = module.GetSolution().GetComponent<NuGetApi>().AreAnyAssemblyFilesNuGetPackages(assemblyLocations); Logger.LogMessage(LoggingLevel.VERBOSE, "[NUGET PLUGIN] Module '{0}' is {1}a nuget package", moduleToReference.DisplayName, canReference ? string.Empty : "NOT "); return canReference; }
private bool ReferenceModuleImpl([NotNull] IPsiModule module, [NotNull] IPsiModule moduleToReference, [CanBeNull] string ns) { if (!CanReferenceModule(module, moduleToReference)) { return(false); } var t4PsiModule = (T4PsiModule)module; var assembly = (IAssembly)moduleToReference.ContainingProjectModule; Assertion.AssertNotNull(assembly, "assembly != null"); var t4File = t4PsiModule.SourceFile.GetNonInjectedPsiFile <T4Language>() as IT4File; if (t4File == null) { return(false); } Action action = () => { // add assembly directive AddDirective(t4File, _directiveInfoManager.Assembly.CreateDirective(assembly.FullAssemblyName)); // add import directive if necessary if (!String.IsNullOrEmpty(ns) && !t4File.GetDirectives(_directiveInfoManager.Import).Any(d => String.Equals(ns, d.GetAttributeValue(_directiveInfoManager.Import.NamespaceAttribute.Name), StringComparison.Ordinal))) { AddDirective(t4File, _directiveInfoManager.Import.CreateDirective(ns)); } }; PsiManager psiManager = PsiManager.GetInstance(module.GetSolution()); if (psiManager.HasActiveTransaction) { action(); return(true); } return(psiManager.DoTransaction(action, "T4 Assembly Reference").Succeded); }
public PsiElementFactoryImpl([NotNull] IPsiModule module) : this(module, module.GetSolution()) { }
public bool ReferenceModule(IPsiModule module, IPsiModule moduleToReference) { if (!IsProjectModule(module) || !IsAssemblyModule(moduleToReference)) return false; Logger.LogMessage(LoggingLevel.VERBOSE, "[NUGET PLUGIN] Attempting to reference module '{0}' as a nuget package", moduleToReference.DisplayName); var assemblyLocations = GetAllAssemblyLocations(moduleToReference); var projectModule = (IProjectPsiModule)module; FileSystemPath packageLocation; var handled = module.GetSolution().GetComponent<NuGetApi>().InstallNuGetPackageFromAssemblyFiles(assemblyLocations, projectModule.Project, out packageLocation); if (handled) { Hacks.PokeReSharpersAssemblyReferences(module, assemblyLocations, packageLocation, projectModule); Hacks.HandleFailureToReference(packageLocation, lifetime, textControlManager, shellLocks, tooltipManager, actionManager); } if (handled) Logger.LogMessage(LoggingLevel.VERBOSE, "[NUGET PLUGIN] Referenced module '{0}' as nuget package from '{1}'", moduleToReference.DisplayName, packageLocation); return handled; }
public static JsonNewElementFactory GetInstance(IPsiModule psiModule) { return(new JsonNewElementFactory(psiModule, psiModule.GetSolution(), JsonNewLanguage.Instance)); }
public LexElementFactory([NotNull] IPsiModule module) : this(module, module.GetSolution()) { }