Skip to content
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 @@ -103,6 +103,7 @@
<Compile Include="src\LanguageService\FSharpPsiProperties.fs" />
<Compile Include="src\LanguageService\FSharpProjectFileLanguageService.fs" />
<Compile Include="src\LanguageService\FSharpElementFactory.fs" />
<Compile Include="src\LanguageService\FSharpDeclaredElementPresenter.fs" />
<Compile Include="src\LanguageService\FSharpLanguageService.fs" />
<Compile Include="src\LanguageService\FSharpClrLanguage.fs" />
<Compile Include="src\LanguageService\FSharpBreadcrumbsHelper.fs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type NameSuggestionFromAsInstanceOfRule() =
isNotNull isInstType &&

let typeElement = isInstType.GetTypeElement()
isNotNull typeElement && typeElement.IsUnion()
isNotNull typeElement && typeElement.IsFSharpUnion()

collector.RemoveWhere(fun item ->
match item with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ open JetBrains.ReSharper.Plugins.FSharp.Psi
open JetBrains.ReSharper.Plugins.FSharp.Psi.Impl
open JetBrains.ReSharper.Plugins.FSharp.Psi.Impl.Cache2
open JetBrains.ReSharper.Plugins.FSharp.Psi.Impl.Cache2.Parts
open JetBrains.ReSharper.Plugins.FSharp.Psi.Impl.DeclaredElement
open JetBrains.ReSharper.Plugins.FSharp.Util
open JetBrains.ReSharper.Psi
open JetBrains.ReSharper.Psi.ExtensionsAPI.Caches2
Expand Down Expand Up @@ -68,7 +67,7 @@ type FSharpDeclaredElementIconProvider() =
PsiSymbolsThemedIcons.Class.Id

| :? TypeElement as typeElement when
typeElement.PresentationLanguage.Is<FSharpLanguage>() && typeElement.IsUnion() ->
typeElement.PresentationLanguage.Is<FSharpLanguage>() && typeElement.IsFSharpUnion() ->
PsiSymbolsThemedIcons.Enum.Id

| :? IFSharpFieldProperty as fieldProp ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace JetBrains.ReSharper.Plugins.FSharp.Psi.Features.LanguageService

open JetBrains.ReSharper.Plugins.FSharp.Psi
open JetBrains.ReSharper.Psi
open JetBrains.ReSharper.Psi.CSharp.Impl

type FSharpDeclaredElementPresenter() =
inherit CSharpDeclaredElementPresenter()

let unwrapGenerated (declaredElement: IDeclaredElement) =
match declaredElement with
| :? IFSharpGeneratedFromOtherElement as generatedElement ->
let originElement = generatedElement.OriginElement
if isNull originElement then declaredElement else originElement
| _ ->
declaredElement

static member val Instance = FSharpDeclaredElementPresenter()

override this.Format(style, declaredElement, substitution, marking) =
let element = unwrapGenerated declaredElement
base.Format(style, element, substitution, &marking)

override this.GetEntityKind(declaredElement) =
let element = unwrapGenerated declaredElement
let elementType =
match element with
| :? IFSharpDeclaredElement as fsDeclaredElement ->
let elementType = fsDeclaredElement.FSharpElementType
if isNotNull elementType then elementType else null

| _ -> null

match elementType with
| null -> base.GetEntityKind(declaredElement)
| elementType -> elementType.PresentableName
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ open JetBrains.ReSharper.Plugins.FSharp.Psi.Resolve
open JetBrains.ReSharper.Plugins.FSharp.Psi.Tree
open JetBrains.ReSharper.Plugins.FSharp.Psi.Util
open JetBrains.ReSharper.Psi
open JetBrains.ReSharper.Psi.CSharp.Impl
open JetBrains.ReSharper.Psi.Impl
open JetBrains.ReSharper.Psi.Modules
open JetBrains.ReSharper.Psi.Parsing
Expand Down Expand Up @@ -56,7 +55,7 @@ type FSharpLanguageService(languageType, constantValueService, cacheProvider: FS
| _ -> true

override x.TypePresenter = CLRTypePresenter.Instance
override x.DeclaredElementPresenter = CSharpDeclaredElementPresenter.Instance :> _ // todo: implement F# presenter
override x.DeclaredElementPresenter = FSharpDeclaredElementPresenter.Instance :> _

override x.FindTypeDeclarations _ = EmptyList.Instance :> _

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type NewRecordPostfixTemplate() =
match refExpr.Qualifier with
| :? IReferenceExpr as refExpr ->
let typeElement = refExpr.Reference.Resolve().DeclaredElement.As<ITypeElement>()
typeElement.IsRecord()
typeElement.IsFSharpRecord()
| _ -> false

override this.IsEnabled _ = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ type RecordCtorSearchFactory() =

override x.GetAllPossibleWordsInFile(declaredElement) =
match declaredElement with
| :? ITypeElement as typeElement when typeElement.IsRecord() -> typeElement.GetRecordFieldNames() :> _
| :? ITypeElement as typeElement when typeElement.IsFSharpRecord() -> typeElement.GetRecordFieldNames() :> _
| _ -> EmptyList.Instance :> _

override x.CreateReferenceSearcher(declaredElements, findCandidates) =
let recordTypeElements =
declaredElements.FilterByType<ITypeElement>()
|> Seq.filter (fun typeElement -> typeElement.IsRecord())
|> Seq.filter (fun typeElement -> typeElement.IsFSharpRecord())
|> Array.ofSeq

if recordTypeElements.IsEmpty() then null else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type GenerateMissingRecordFieldsFix(recordExpr: IRecordExpr) =

override x.ExecutePsiTransaction(_, _) =
let typeElement = recordExpr.Reference.Resolve().DeclaredElement :?> ITypeElement
Assertion.Assert(typeElement.IsRecord(), "Expecting record type")
Assertion.Assert(typeElement.IsFSharpRecord(), "Expecting record type")

let generatedBindings = RecordExprUtil.generateBindings typeElement recordExpr

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ type SingleUnionCaseRenameEvaluator() =

member x.CreateFromElement(initialElement, _, _) =
let isApplicable (typeElement: ITypeElement) =
typeElement.IsUnion() &&
typeElement.IsFSharpUnion() &&

let sourceName = typeElement.GetSourceName()
sourceName <> SharedImplUtil.MISSING_DECLARATION_NAME &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module NewObjPostfixTemplate =

let isApplicableType (typeElement: ITypeElement) =
(typeElement :? IClass || typeElement :? IInterface) &&
not (typeElement.IsRecord() || typeElement.IsUnion())
not (typeElement.IsFSharpRecord() || typeElement.IsFSharpUnion())

let isApplicableExpr (expr: IFSharpExpression) =
let reference = getReference expr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ let private generateUnorderedBindings recordExpr (existingBindings: TreeNodeColl
generateBindingsImpl recordExpr indexedBindings declaredFields

let generateBindings (recordTypeElement: ITypeElement) (recordExpr: IRecordExpr) : IRecordFieldBinding seq =
Assertion.Assert(recordTypeElement.IsRecord(), "Expecting record type")
Assertion.Assert(recordTypeElement.IsFSharpRecord(), "Expecting record type")

let fieldNames = recordTypeElement.GetRecordFieldNames()
let existingBindings = recordExpr.FieldBindings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace JetBrains.ReSharper.Plugins.FSharp.Psi
public interface IFSharpDeclaredElement : IClrDeclaredElement
{
string SourceName { get; }
[CanBeNull] DeclaredElementType FSharpElementType { get; }
}

public interface IFSharpTypeElement : IFSharpDeclaredElement, ITypeElement, ITypeMember
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,21 @@

namespace JetBrains.ReSharper.Plugins.FSharp.Psi.Impl.Cache2.Compiled
{
public class FSharpCompiledClassBase : Class, IFSharpCompiledTypeElement
public abstract class FSharpCompiledClassBase(
[CanBeNull] FSharpMetadataEntity entity,
[NotNull] ICompiledEntity parent,
[NotNull] IReflectionBuilder builder,
[NotNull] IMetadataTypeInfo info)
: Class(parent, builder, info), IFSharpCompiledTypeElement
{
[NotNull] private FSharpDeclaredName FSharpName { get; }
public FSharpCompiledTypeRepresentation Representation { get; }
public FSharpAccessRights FSharpAccessRights { get; }
[NotNull] private FSharpDeclaredName FSharpName { get; } = FSharpMetadataEntityModule.getCompiledModuleDeclaredName(entity);
public FSharpCompiledTypeRepresentation Representation { get; } = FSharpMetadataEntityModule.getRepresentation(entity);
public FSharpAccessRights FSharpAccessRights { get; } = entity.GetFSharpAccessRights();

public ICacheTrieNode AlternativeNameTrieNode { get; set; }

public FSharpCompiledClassBase([CanBeNull] FSharpMetadataEntity entity, [NotNull] ICompiledEntity parent,
[NotNull] IReflectionBuilder builder,
[NotNull] IMetadataTypeInfo info) : base(parent, builder, info)
{
FSharpName = FSharpMetadataEntityModule.getCompiledModuleDeclaredName(entity);
Representation = FSharpMetadataEntityModule.getRepresentation(entity);
FSharpAccessRights = entity.GetFSharpAccessRights();
}

public string SourceName => FSharpName.SourceName;
public virtual DeclaredElementType FSharpElementType => this.TryGetFSharpDeclaredElementType();
string IAlternativeNameOwner.AlternativeName => FSharpName.AlternativeName;
public virtual ModuleMembersAccessKind AccessKind => ModuleMembersAccessKind.Normal; // todo
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using JetBrains.Annotations;
using JetBrains.Metadata.Reader.API;
using JetBrains.ReSharper.Plugins.FSharp.Metadata;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.Caches.SymbolCache;
using JetBrains.ReSharper.Psi.Impl.Reflection2;
using JetBrains.ReSharper.Psi.Impl.reflection2.elements.Compiled;
Expand All @@ -27,5 +28,6 @@ public FSharpCompiledDelegate([CanBeNull] FSharpMetadataEntity entity, [NotNull]
public string SourceName => FSharpName.SourceName;
public string AlternativeName => FSharpName.AlternativeName;
public ModuleMembersAccessKind AccessKind => ModuleMembersAccessKind.Normal; // todo
public DeclaredElementType FSharpElementType => null;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using JetBrains.Annotations;
using JetBrains.Metadata.Reader.API;
using JetBrains.ReSharper.Plugins.FSharp.Metadata;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.Caches.SymbolCache;
using JetBrains.ReSharper.Psi.Impl.Reflection2;
using JetBrains.ReSharper.Psi.Impl.reflection2.elements.Compiled;
Expand All @@ -26,5 +27,6 @@ public FSharpCompiledEnum([CanBeNull] FSharpMetadataEntity entity, [NotNull] ICo
public string SourceName => FSharpName.SourceName;
public string AlternativeName => FSharpName.AlternativeName;
public ModuleMembersAccessKind AccessKind => ModuleMembersAccessKind.RequiresQualifiedAccess;
public DeclaredElementType FSharpElementType => null;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using JetBrains.Annotations;
using JetBrains.Metadata.Reader.API;
using JetBrains.ReSharper.Plugins.FSharp.Metadata;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.Caches.SymbolCache;
using JetBrains.ReSharper.Psi.Impl.Reflection2;
using JetBrains.ReSharper.Psi.Impl.reflection2.elements.Compiled;
Expand All @@ -27,5 +28,6 @@ public FSharpCompiledInterface([CanBeNull] FSharpMetadataEntity entity, [NotNull
public string SourceName => FSharpName.SourceName;
public string AlternativeName => FSharpName.AlternativeName;
public ModuleMembersAccessKind AccessKind => ModuleMembersAccessKind.Normal; // todo
public DeclaredElementType FSharpElementType => null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,7 @@ private ITypeElement TryGetAssociatedTypeElement()
bool HasSameName(ITypeElement typeElement) =>
!Equals(typeElement) && typeElement.TypeParametersCount == 0 && typeElement.GetSourceName() == sourceName;
}

public override DeclaredElementType FSharpElementType => FSharpDeclaredElementType.Module;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using JetBrains.Annotations;
using JetBrains.Metadata.Reader.API;
using JetBrains.ReSharper.Plugins.FSharp.Metadata;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.Caches.SymbolCache;
using JetBrains.ReSharper.Psi.Impl.Reflection2;
using JetBrains.ReSharper.Psi.Impl.reflection2.elements.Compiled;
Expand All @@ -26,5 +27,6 @@ public FSharpCompiledStruct([CanBeNull] FSharpMetadataEntity entity, [NotNull] I
public string SourceName => FSharpName.SourceName;
public string AlternativeName => FSharpName.AlternativeName;
public ModuleMembersAccessKind AccessKind => ModuleMembersAccessKind.Normal; // todo
public DeclaredElementType FSharpElementType => this.TryGetFSharpDeclaredElementType();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.ExtensionsAPI.Caches2;
using JetBrains.ReSharper.Psi.Tree;
using JetBrains.ReSharper.Psi.Xml.XmlDocComments;
using JetBrains.Util;

namespace JetBrains.ReSharper.Plugins.FSharp.Psi.Impl.Cache2
Expand All @@ -32,6 +31,7 @@ part is IClassPart and IFSharpTypePart typePart and not IModulePart &&

public virtual ModuleMembersAccessKind AccessKind => EnumerateParts().GetAccessKind();
public ITypeDeclaration DefiningDeclaration => this.GetDefiningDeclaration();
public virtual DeclaredElementType FSharpElementType => this.TryGetFSharpDeclaredElementType();

public override IClass GetSuperClass()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace JetBrains.ReSharper.Plugins.FSharp.Psi.Impl.Cache2
{
// todo: why provided type for simple union?
// type T = a
public class FSharpClassOrProvidedTypeAbbreviation([NotNull] Class.IClassPart part) : FSharpClass(part), ILanguageSpecificDeclaredElement
public class FSharpClassOrProvidedTypeAbbreviation([NotNull] Class.IClassPart part)
: FSharpClass(part), ILanguageSpecificDeclaredElement
{
// Triggers FCS resolve
private GenerativeMembersConverter<FSharpClassOrProvidedTypeAbbreviation> ProvidedClass =>
Expand Down Expand Up @@ -53,7 +54,14 @@ ProvidedClass is { } x
public override XmlNode GetXMLDoc(bool expand) =>
ProvidedClass is { } x ? x.GetXmlDoc(expand) : base.GetXMLDoc(expand);

bool ILanguageSpecificDeclaredElement.IsErased =>
internal bool IsTypeAbbreviation =>
Parts is TypeAbbreviationOrDeclarationPart { IsUnionCase: false, IsProvidedAndGenerated: false };

bool ILanguageSpecificDeclaredElement.IsErased => IsTypeAbbreviation;

public override DeclaredElementType FSharpElementType =>
IsTypeAbbreviation
? FSharpDeclaredElementType.TypeAbbreviation
: !IsProvidedAndGenerated ? FSharpDeclaredElementType.Union : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protected override bool AcceptsPart(TypePart part) =>

public ModuleMembersAccessKind AccessKind => ModuleMembersAccessKind.Normal;
public ITypeDeclaration DefiningDeclaration => this.GetDefiningDeclaration();
public DeclaredElementType FSharpElementType => null;

public override string ToString() => this.TestToString(BuildTypeParameterString());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Xml;
using JetBrains.ReSharper.Plugins.FSharp.Psi.Impl.Cache2.Parts;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.ExtensionsAPI.Caches2;
using JetBrains.ReSharper.Psi.Tree;

Expand All @@ -19,6 +20,7 @@ protected override bool AcceptsPart(TypePart part) =>

public ModuleMembersAccessKind AccessKind => ModuleMembersAccessKind.RequiresQualifiedAccess;
public ITypeDeclaration DefiningDeclaration => this.GetDefiningDeclaration();
public DeclaredElementType FSharpElementType => null;

public override string ToString() => this.TestToString(BuildTypeParameterString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public override IList<ITypeElement> GetSuperTypeElements()

public ModuleMembersAccessKind AccessKind => ModuleMembersAccessKind.Normal;
public ITypeDeclaration DefiningDeclaration => this.GetDefiningDeclaration();
public DeclaredElementType FSharpElementType => null;

public override string ToString() => this.TestToString(BuildTypeParameterString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ private string[] GetNames(Func<IModulePart, string[]> getter)
string IAlternativeNameOwner.AlternativeName => SourceName != ShortName ? SourceName : null;

public override string ToString() => this.TestToString(BuildTypeParameterString());
public override DeclaredElementType FSharpElementType => FSharpDeclaredElementType.Module;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ protected override bool AcceptsPart(TypePart part) =>
public AccessRights RepresentationAccessRights => AccessRights.PUBLIC;
public bool IsErased => true;

public override DeclaredElementType FSharpElementType => FSharpDeclaredElementType.ObjectExpression;

public override string ToString() => this.TestToString(BuildTypeParameterString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public override IList<ITypeElement> GetSuperTypeElements()

public ModuleMembersAccessKind AccessKind => EnumerateParts().GetAccessKind();
public ITypeDeclaration DefiningDeclaration => this.GetDefiningDeclaration();
public virtual DeclaredElementType FSharpElementType => this.TryGetFSharpDeclaredElementType();

public override string ToString() => this.TestToString(BuildTypeParameterString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ public class FSharpUnionCaseClass([NotNull] Class.IClassPart part) : FSharpClass
public IDeclaredElementPointer<IFSharpGeneratedFromOtherElement> CreatePointer() =>
new FSharpUnionCaseClassPointer(this);

public override DeclaredElementType FSharpElementType => FSharpDeclaredElementType.UnionCase;

public override string ToString() => this.TestToString(BuildTypeParameterString());
}
Loading
Loading