public override ResolveResultWithInfo ResolveWithoutCache() { var psiServices = myOwner.GetPsiServices(); var specflowStepsDefinitionsCache = psiServices.GetComponent <SpecflowStepsDefinitionsCache>(); var stepKind = myOwner.EffectiveStepKind; var stepText = myOwner.GetStepText(); var psiModule = myOwner.GetPsiModule(); var containingScenario = myOwner.GetContainingNode <IGherkinScenario>(); if (containingScenario is GherkinScenarioOutline scenarioOutline) { stepText = myOwner.GetStepTextForExample(scenarioOutline.GetExampleData(0)); } foreach (var(sourceFile, cacheEntries) in specflowStepsDefinitionsCache.AllStepsPerFiles) { if (!psiModule.Equals(sourceFile.PsiModule) && !psiModule.References(sourceFile.PsiModule)) { continue; } foreach (var cacheEntry in cacheEntries.Where(c => c.StepKind == stepKind)) { if (cacheEntry.Regex?.IsMatch(stepText) == true) { var types = psiServices.Symbols.GetTypesAndNamespacesInFile(sourceFile); foreach (var decElement in types) { if (!(decElement is IClass cl)) { continue; } var method = cl.GetMembers().OfType <IMethod>().FirstOrDefault(x => x.ShortName == cacheEntry.MethodName); if (method == null) { continue; } var symbolInfo = new SymbolInfo(method); var resolveResult = ResolveResultFactory.CreateResolveResult(symbolInfo.GetDeclaredElement(), symbolInfo.GetSubstitution()); RegexPattern = cacheEntry.Regex; return(new ResolveResultWithInfo(resolveResult, ResolveErrorType.OK)); } } } } var assemblyStepDefinitionCache = psiServices.GetComponent <AssemblyStepDefinitionCache>(); var psiAssemblyFileLoader = psiServices.GetComponent <IPsiAssemblyFileLoader>(); foreach (var(psiAssembly, cacheEntries) in assemblyStepDefinitionCache.AllStepsPerAssembly) { // FIXME: Should use `assembly` from specflow.json instead if (!psiModule.Equals(psiAssembly.PsiModule) && !psiModule.References(psiAssembly.PsiModule)) { continue; } foreach (var cacheEntry in cacheEntries.Where(c => c.StepKind == stepKind)) { if (cacheEntry.Regex?.IsMatch(stepText) == true) { var assemblyFile = psiAssemblyFileLoader.GetOrLoadAssembly(psiAssembly, false); if (assemblyFile == null) { continue; } foreach (var decElement in assemblyFile.Types) { if (!(decElement is IClass cl)) { continue; } var method = cl.GetMembers().OfType <IMethod>().FirstOrDefault(x => x.ShortName == cacheEntry.MethodName); if (method == null) { continue; } var symbolInfo = new SymbolInfo(method); var resolveResult = ResolveResultFactory.CreateResolveResult(symbolInfo.GetDeclaredElement(), symbolInfo.GetSubstitution()); RegexPattern = cacheEntry.Regex; return(new ResolveResultWithInfo(resolveResult, ResolveErrorType.OK)); } } } } return(new ResolveResultWithInfo(EmptyResolveResult.Instance, ResolveErrorType.NOT_RESOLVED)); }
public override ResolveResultWithInfo ResolveWithoutCache() { var psiServices = myOwner.GetPsiServices(); var specflowStepsDefinitionsCache = psiServices.GetComponent <SpecflowStepsDefinitionsCache>(); var stepKind = myOwner.GetStepKind(); var stepText = myOwner.GetStepText(); var projectReferences = myOwner.GetProject()?.GetAllModuleReferences().OfType <SimpleProjectToProjectReference>().ToList(); foreach (var(sourceFile, cacheEntries) in specflowStepsDefinitionsCache.AllStepsPerFiles) { if (!ReferenceEquals(sourceFile.GetProject(), myOwner.GetProject())) { if (projectReferences?.Any(x => x.Name == sourceFile.GetProject()?.Name) != true) { continue; } } foreach (var cacheEntry in cacheEntries.Where(c => c.StepKind == stepKind)) { if (cacheEntry.Regex?.IsMatch(stepText) == true) { var types = psiServices.Symbols.GetTypesAndNamespacesInFile(sourceFile); foreach (var decElement in types) { if (!(decElement is IClass cl)) { continue; } var method = cl.GetMembers().OfType <IMethod>().FirstOrDefault(x => x.ShortName == cacheEntry.MethodName); if (method == null) { continue; } var symbolInfo = new SymbolInfo(method); var resolveResult = ResolveResultFactory.CreateResolveResult(symbolInfo.GetDeclaredElement(), symbolInfo.GetSubstitution()); return(new ResolveResultWithInfo(resolveResult, ResolveErrorType.OK)); } } } } return(new ResolveResultWithInfo(EmptyResolveResult.Instance, ResolveErrorType.NOT_RESOLVED)); }