Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI-CACHE #5

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix
  • Loading branch information
DedSec256 committed Oct 25, 2020
commit c066b84973d15a973a4cf90c48b8844faf483d50
25 changes: 20 additions & 5 deletions ReSharper.FSharp/src/FSharp.Psi/src/Impl/Cache2/Parts/EnumPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,26 @@ public IType GetUnderlyingType()
return TypeFactory.CreateUnknownType(GetPsiModule());
}

public IList<IField> Fields =>
ProcessSubDeclaration<IField, IEnumMemberDeclaration>(input =>
GetDeclaration() is IFSharpTypeDeclaration decl && decl.TypeRepresentation is IEnumRepresentation repr
? repr.EnumMembers
: EmptyList<IEnumMemberDeclaration>.InstanceList);
public IEnumerable<IField> Fields
{
get
{
var declaration = GetDeclaration();
if (declaration != null)
{
var subDeclarationMembers = GetDeclaration() is IFSharpTypeDeclaration decl &&
decl.TypeRepresentation is IEnumRepresentation repr
? repr.EnumMembers
: EmptyList<IEnumMemberDeclaration>.InstanceList;

foreach (var memberDeclaration in subDeclarationMembers)
{
var field = (IField) memberDeclaration.DeclaredElement;
if (field != null) yield return field;
}
}
}
}

protected override byte SerializationTag => (byte) FSharpPartKind.Enum;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using JetBrains.Metadata.Reader.API;
Expand Down Expand Up @@ -44,6 +45,18 @@ public IClrTypeName GetClrName() =>
public INamespace GetContainingNamespace() =>
Union.GetContainingNamespace();

public bool HasMemberWithName(string shortName, bool ignoreCase)
{
var comparisonRule = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;

foreach (var name in MemberNames)
{
if (string.Equals(name, shortName, comparisonRule)) return true;
}

return false;
}

public IPsiSourceFile GetSingleOrDefaultSourceFile() =>
Union.GetSingleOrDefaultSourceFile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ public INamespace GetContainingNamespace() =>
Method.GetContainingType()?.GetContainingNamespace() ??
Module.GetSymbolScope().GlobalNamespace;

public bool HasMemberWithName(string shortName, bool ignoreCase) => false;

public IPsiSourceFile GetSingleOrDefaultSourceFile() => null;

public IList<ITypeElement> NestedTypes => EmptyList<ITypeElement>.InstanceList;
public IEnumerable<IField> Constants => EmptyList<IField>.Instance;
public IEnumerable<IField> Fields => EmptyList<IField>.Instance;
public IEnumerable<IConstructor> Constructors => EmptyList<IConstructor>.Instance;
public IEnumerable<IOperator> Operators => EmptyList<IOperator>.Instance;
public IEnumerable<IMethod> Methods => EmptyList<IMethod>.Instance;
Expand All @@ -59,6 +63,7 @@ public INamespace GetContainingNamespace() =>
public IEnumerable<string> MemberNames => EmptyList<string>.InstanceList;

public TypeParameterNullability Nullability => TypeParameterNullability.Unknown;

public TypeParameterNullability GetNullability(ISubstitution explicitInheritorSubstitution) =>
TypeParameterNullability.Unknown;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using FSharp.Compiler.SourceCodeServices;
using JetBrains.Annotations;
using JetBrains.ReSharper.Plugins.FSharp.Psi.Impl;
Expand Down Expand Up @@ -34,7 +35,8 @@ public FSharpSearcherFactory(SearchDomainFactory searchDomainFactory,

public override bool IsCompatibleWithLanguage(PsiLanguageType languageType) => languageType.Is<FSharpLanguage>();

public override IDomainSpecificSearcher CreateReferenceSearcher(IDeclaredElementsSet elements, bool findCandidates) =>
public override IDomainSpecificSearcher
CreateReferenceSearcher(IDeclaredElementsSet elements, bool findCandidates) =>
new FSharpReferenceSearcher(elements, findCandidates);

public override IEnumerable<string> GetAllPossibleWordsInFile(IDeclaredElement element) =>
Expand Down Expand Up @@ -101,7 +103,7 @@ public override IEnumerable<RelatedDeclaredElement> GetRelatedDeclaredElements(I
private static IEnumerable<RelatedDeclaredElement> GetUnionCaseRelatedElements([NotNull] IUnionCase unionCase) =>
unionCase.GetGeneratedMembers().Select(member => new RelatedDeclaredElement(member));

public override Tuple<ICollection<IDeclaredElement>, bool> GetNavigateToTargets(IDeclaredElement element)
public override NavigateTargets GetNavigateToTargets(IDeclaredElement element)
{
if (element is ResolvedFSharpSymbolElement resolvedSymbolElement &&
resolvedSymbolElement.Symbol is FSharpActivePatternCase activePatternCase)
Expand All @@ -111,14 +113,14 @@ public override Tuple<ICollection<IDeclaredElement>, bool> GetNavigateToTargets(
var entityOption = activePattern.DeclaringEntity;
var patternNameOption = activePattern.Name;
if (entityOption == null || patternNameOption == null)
return null;
return NavigateTargets.Empty;

var typeElement = FSharpElementsUtil.GetTypeElement(entityOption.Value, resolvedSymbolElement.Module);
var pattern = typeElement.EnumerateMembers(patternNameOption.Value, true).FirstOrDefault() as IDeclaredElement;
if (pattern is IFSharpTypeMember)
{
if (!(pattern.GetDeclarations().FirstOrDefault() is IFSharpDeclaration patternDecl))
return null;
return NavigateTargets.Empty;

var caseElement = patternDecl.GetActivePatternByIndex(activePatternCase.Index);
if (caseElement != null)
Expand All @@ -132,14 +134,14 @@ public override Tuple<ICollection<IDeclaredElement>, bool> GetNavigateToTargets(
return CreateTarget(origin);

if (!(element is IFSharpTypeMember fsTypeMember) || fsTypeMember.CanNavigateTo)
return null;
return NavigateTargets.Empty;

return fsTypeMember.GetContainingType() is IDeclaredElement containingType
? CreateTarget(containingType)
: null;
: NavigateTargets.Empty;
}

private static Tuple<ICollection<IDeclaredElement>, bool> CreateTarget(IDeclaredElement element) =>
new Tuple<ICollection<IDeclaredElement>, bool>(new[] {element}, false);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static NavigateTargets CreateTarget(IDeclaredElement element) => new NavigateTargets(element, false);
}
}