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

Sync with the ultimate master #776

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ type ProjectFcsModuleReader(psiModule: IPsiModule, cache: FcsModuleReaderCommonC
let customAttrs =
let isExtension =
match method with
| :? IMethod as method -> method.IsExtensionMethod
| :? IMethod as method -> method.IsDefinedAsExtension
| _ -> false

let customAttributes = mkCustomAttributes method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ open System.Collections.Generic
open FSharp.Compiler.Symbols
open JetBrains.ProjectModel
open JetBrains.ReSharper.Plugins.FSharp.Psi
open JetBrains.ReSharper.Plugins.FSharp.Psi.Impl.Cache2.Compiled
open JetBrains.ReSharper.Plugins.FSharp.Psi.Metadata
open JetBrains.ReSharper.Plugins.FSharp.Psi.Tree
open JetBrains.ReSharper.Plugins.FSharp.Psi.Util
open JetBrains.ReSharper.Psi
open JetBrains.ReSharper.Psi.ExtensionsAPI.Caches2.ExtensionMethods
open JetBrains.ReSharper.Psi.ExtensionsAPI.Caches2.ExtensionMethods.Queries
open JetBrains.ReSharper.Psi.Modules
open JetBrains.ReSharper.Psi.Resolve
open JetBrains.ReSharper.Psi.Util

type FSharpRequest(psiModule, exprType: IType, name: string option) =
static let memberKinds = [ExtensionMemberKind.ExtensionMethod; FSharpExtensionMemberKind.FSharpExtensionMember]

let name = Option.toObj name

let baseTypes: IReadOnlyList<IType> =
Expand All @@ -32,6 +36,7 @@ type FSharpRequest(psiModule, exprType: IType, name: string option) =
member this.BaseExpressionTypes = baseTypes
member this.ExpressionType = exprType
member this.ForModule = psiModule
member this.Kinds = memberKinds

member this.IsCaseSensitive = true
member this.Namespaces = []
Expand Down Expand Up @@ -169,11 +174,29 @@ let getExtensionMembers (context: IFSharpTreeNode) (fcsType: FSharpType) (nameOp
| _ -> containingType.Module.AreInternalsVisibleTo(psiModule)

isTypeAccessible &&

match typeMember with
| FSharpExtensionMember _ -> true
| _ -> AccessUtil.IsSymbolAccessible(typeMember, accessContext)

let matchesName (typeMember: ITypeMember) =
match nameOpt with
| None -> true
| Some name ->

match typeMember with
| FSharpCompiledExtensionMember _ ->
let memberName = typeMember.ShortName
memberName = name ||
memberName = $"get_{name}" ||
memberName = $"set_{name}" ||

memberName.EndsWith($".{name}") ||
memberName.EndsWith($".get_{name}") ||
memberName.EndsWith($".set_{name}")

| _ -> typeMember.ShortName = name

let isApplicable (typeMember: ITypeMember) =
matchesName typeMember &&
not (isInScope typeMember) &&
Expand All @@ -182,6 +205,8 @@ let getExtensionMembers (context: IFSharpTreeNode) (fcsType: FSharpType) (nameOp

let query = ExtensionMethodsQuery(solution.GetPsiServices(), FSharpRequest(psiModule, exprType, nameOpt))

query.EnumerateMethods()
let methods = query.EnumerateMethods()

methods
|> Seq.filter isApplicable
|> List
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public FSharpGenerativeGenerativeProvidedMethod(ProvidedMethodInfo info, ITypeEl
public override IType ReturnType => Info.ReturnType.MapType(Module);
public override bool IsAbstract => Info.IsAbstract;
public override bool IsStatic => Info.IsStatic;
public bool IsExtensionMethod => false;
public bool IsDefinedAsExtension => false;
public bool IsAsync => false;
public bool IsVarArg => false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public override DeclaredElementType GetElementType() =>
MethodIdSubstitution.Create(this);

public bool IsXamlImplicitMethod => false;
public bool IsExtensionMethod => false;
public bool IsDefinedAsExtension => false;
public bool IsVarArg => false;
public bool IsAsync => false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public override bool Equals(object obj)

public override int GetHashCode() => ShortName.GetHashCode();

public bool IsExtensionMember => false;
public bool IsDefinedAsExtension => false;
public bool IsExtensionMethod => false;

public FSharpSymbol Symbol => null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override DeclaredElementType GetElementType() =>

public IType Type =>
FcsField is { } field
? field.FieldType.MapType(Reference.GetElement())
? @field.FieldType.MapType(Reference.GetElement())
: TypeFactory.CreateUnknownType(Module);

public IFSharpAnonRecordFieldProperty SetName(string newName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected FSharpMemberBase([NotNull] ITypeMemberDeclaration declaration) : base(

public FSharpMemberOrFunctionOrValue Mfv => Symbol as FSharpMemberOrFunctionOrValue;

public bool IsExtensionMember =>
public bool IsFSharpExtensionMember =>
GetContainingType() is IFSharpModule && GetDeclaration() is IMemberSignatureOrDeclaration;

protected override ITypeElement GetTypeElement(IDeclaration declaration)
Expand Down Expand Up @@ -59,7 +59,7 @@ public override AccessRights GetAccessRights()
// Workaround to hide extension methods from resolve in C#.
// todo: calc compiled names for extension members (it'll hide needed ones properly)
// todo: implement F# declared element presenter to hide compiled names in features/ui
if (IsExtensionMember && GetDeclaration() is IMemberSignatureOrDeclaration memberDeclaration)
if (IsFSharpExtensionMember && GetDeclaration() is IMemberSignatureOrDeclaration memberDeclaration)
if (!(this is IMethod && memberDeclaration.Attributes.GetCompiledName(out _)))
return AccessRights.INTERNAL;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ protected FSharpMethodBase([NotNull] ITypeMemberDeclaration declaration) : base(
public override DeclaredElementType GetElementType() =>
CLRDeclaredElementType.METHOD;

public bool IsExtensionMethod =>
public bool IsExtensionMethod => IsDefinedAsExtension;

public override bool IsDefinedAsExtension =>
Attributes.HasAttributeInstance(PredefinedType.EXTENSION_ATTRIBUTE_CLASS);

public bool IsAsync => false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public virtual AccessRights GetAccessRights() =>
public virtual bool IsExtern => false;
public virtual bool IsUnsafe => false;
public virtual bool IsVolatile => false;
public virtual bool IsDefinedAsExtension => false;

public string XMLDocId => XMLDocUtil.GetTypeMemberXmlDocId(this, ShortName);

Expand Down
Loading