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

Fix navigation for external enums, DUs and name resultion for members #15270

Merged
merged 4 commits into from
May 29, 2023
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
4 changes: 4 additions & 0 deletions src/Compiler/Symbols/Symbols.fs
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,10 @@ type FSharpUnionCase(cenv, v: UnionCaseRef) =
checkIsResolved()
v.Range

member _.DeclaringEntity =
checkIsResolved()
FSharpEntity(cenv, v.TyconRef)

member _.HasFields =
if isUnresolved() then false else
v.UnionCase.RecdFieldsArray.Length <> 0
Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/Symbols/Symbols.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ type FSharpUnionCase =
/// Get the range of the name of the case
member DeclarationLocation: range

/// Get the declaring entity of the case
member DeclaringEntity: FSharpEntity

/// Indicates if the union case has field definitions
member HasFields: bool

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ FSharp.Compiler.AbstractIL.IL+ILArgConvention: Boolean IsCDecl
FSharp.Compiler.AbstractIL.IL+ILArgConvention: Boolean IsDefault
FSharp.Compiler.AbstractIL.IL+ILArgConvention: Boolean IsFastCall
FSharp.Compiler.AbstractIL.IL+ILArgConvention: Boolean IsStdCall
FSharp.Compiler.AbstractIL.IL+ILArgConvention: Boolean IsThisCall
FSharp.Compiler.AbstractIL.IL+ILArgConvention: Boolean IsThisCal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, that is weird. Not sure where did it come from. Will fix it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

FSharp.Compiler.AbstractIL.IL+ILArgConvention: Boolean IsVarArg
FSharp.Compiler.AbstractIL.IL+ILArgConvention: Boolean get_IsCDecl()
FSharp.Compiler.AbstractIL.IL+ILArgConvention: Boolean get_IsDefault()
Expand Down Expand Up @@ -5130,6 +5130,8 @@ FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Symbols.FSharpXmlDoc Xm
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Symbols.FSharpXmlDoc get_XmlDoc()
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Text.Range DeclarationLocation
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Text.Range get_DeclarationLocation()
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Symbols.FSharpEntity DeclaringEntity
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Symbols.FSharpEntity get_DeclaringEntity()
FSharp.Compiler.Symbols.FSharpUnionCase: Int32 GetHashCode()
FSharp.Compiler.Symbols.FSharpUnionCase: System.Collections.Generic.IList`1[FSharp.Compiler.Symbols.FSharpAttribute] Attributes
FSharp.Compiler.Symbols.FSharpUnionCase: System.Collections.Generic.IList`1[FSharp.Compiler.Symbols.FSharpAttribute] get_Attributes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5130,6 +5130,8 @@ FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Symbols.FSharpXmlDoc Xm
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Symbols.FSharpXmlDoc get_XmlDoc()
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Text.Range DeclarationLocation
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Text.Range get_DeclarationLocation()
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Symbols.FSharpEntity DeclaringEntity
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Symbols.FSharpEntity get_DeclaringEntity()
FSharp.Compiler.Symbols.FSharpUnionCase: Int32 GetHashCode()
FSharp.Compiler.Symbols.FSharpUnionCase: System.Collections.Generic.IList`1[FSharp.Compiler.Symbols.FSharpAttribute] Attributes
FSharp.Compiler.Symbols.FSharpUnionCase: System.Collections.Generic.IList`1[FSharp.Compiler.Symbols.FSharpAttribute] get_Attributes()
Expand Down
23 changes: 23 additions & 0 deletions vsintegration/src/FSharp.Editor/Navigation/GoToDefinition.fs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,18 @@ type internal GoToDefinition(metadataAsSource: FSharpMetadataAsSourceService) =
| :? FSharpMemberOrFunctionOrValue as symbol ->
symbol.ApparentEnclosingEntity.TryGetMetadataText()
|> Option.map (fun text -> text, symbol.ApparentEnclosingEntity.DisplayName)
| :? FSharpField as symbol ->
match symbol.DeclaringEntity with
| Some entity ->
let text = entity.TryGetMetadataText()

match text with
| Some text -> Some(text, entity.DisplayName)
| None -> None
| None -> None
| :? FSharpUnionCase as symbol ->
symbol.DeclaringEntity.TryGetMetadataText()
|> Option.map (fun text -> text, symbol.DisplayName)
| _ -> None

let result =
Expand Down Expand Up @@ -523,13 +535,24 @@ type internal GoToDefinition(metadataAsSource: FSharpMetadataAsSourceService) =
symbol1.DisplayName = symbol2.DisplayName
| (:? FSharpMemberOrFunctionOrValue as symbol1), (:? FSharpMemberOrFunctionOrValue as symbol2) ->
symbol1.DisplayName = symbol2.DisplayName
&& (match symbol1.DeclaringEntity, symbol2.DeclaringEntity with
| Some e1, Some e2 -> e1.CompiledName = e2.CompiledName
| _ -> false)
&& symbol1.GenericParameters.Count = symbol2.GenericParameters.Count
&& symbol1.CurriedParameterGroups.Count = symbol2.CurriedParameterGroups.Count
&& ((symbol1.CurriedParameterGroups, symbol2.CurriedParameterGroups)
||> Seq.forall2 (fun pg1 pg2 ->
pg1.Count = pg2.Count
&& ((pg1, pg2) ||> Seq.forall2 (fun p1 p2 -> areTypesEqual p1.Type p2.Type))))
&& areTypesEqual symbol1.ReturnParameter.Type symbol2.ReturnParameter.Type
| (:? FSharpField as symbol1), (:? FSharpField as symbol2) when x.IsFromDefinition ->
symbol1.DisplayName = symbol2.DisplayName
&& (match symbol1.DeclaringEntity, symbol2.DeclaringEntity with
| Some e1, Some e2 -> e1.CompiledName = e2.CompiledName
| _ -> false)
| (:? FSharpUnionCase as symbol1), (:? FSharpUnionCase as symbol2) ->
symbol1.DisplayName = symbol2.DisplayName
&& symbol1.DeclaringEntity.CompiledName = symbol2.DeclaringEntity.CompiledName
| _ -> false)
|> Option.map (fun x -> x.Range)

Expand Down