Skip to content

Commit 146611d

Browse files
authored
Fix navigation for external enums, DUs and name resultion for members (#15270)
1 parent e3c395d commit 146611d

5 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/Compiler/Symbols/Symbols.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,10 @@ type FSharpUnionCase(cenv, v: UnionCaseRef) =
988988
checkIsResolved()
989989
v.Range
990990

991+
member _.DeclaringEntity =
992+
checkIsResolved()
993+
FSharpEntity(cenv, v.TyconRef)
994+
991995
member _.HasFields =
992996
if isUnresolved() then false else
993997
v.UnionCase.RecdFieldsArray.Length <> 0

src/Compiler/Symbols/Symbols.fsi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,9 @@ type FSharpUnionCase =
454454
/// Get the range of the name of the case
455455
member DeclarationLocation: range
456456

457+
/// Get the declaring entity of the case
458+
member DeclaringEntity: FSharpEntity
459+
457460
/// Indicates if the union case has field definitions
458461
member HasFields: bool
459462

tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ FSharp.Compiler.AbstractIL.IL+ILArgConvention: Boolean IsCDecl
2020
FSharp.Compiler.AbstractIL.IL+ILArgConvention: Boolean IsDefault
2121
FSharp.Compiler.AbstractIL.IL+ILArgConvention: Boolean IsFastCall
2222
FSharp.Compiler.AbstractIL.IL+ILArgConvention: Boolean IsStdCall
23-
FSharp.Compiler.AbstractIL.IL+ILArgConvention: Boolean IsThisCall
23+
FSharp.Compiler.AbstractIL.IL+ILArgConvention: Boolean IsThisCal
2424
FSharp.Compiler.AbstractIL.IL+ILArgConvention: Boolean IsVarArg
2525
FSharp.Compiler.AbstractIL.IL+ILArgConvention: Boolean get_IsCDecl()
2626
FSharp.Compiler.AbstractIL.IL+ILArgConvention: Boolean get_IsDefault()
@@ -5162,6 +5162,8 @@ FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Symbols.FSharpXmlDoc Xm
51625162
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Symbols.FSharpXmlDoc get_XmlDoc()
51635163
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Text.Range DeclarationLocation
51645164
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Text.Range get_DeclarationLocation()
5165+
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Symbols.FSharpEntity DeclaringEntity
5166+
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Symbols.FSharpEntity get_DeclaringEntity()
51655167
FSharp.Compiler.Symbols.FSharpUnionCase: Int32 GetHashCode()
51665168
FSharp.Compiler.Symbols.FSharpUnionCase: System.Collections.Generic.IList`1[FSharp.Compiler.Symbols.FSharpAttribute] Attributes
51675169
FSharp.Compiler.Symbols.FSharpUnionCase: System.Collections.Generic.IList`1[FSharp.Compiler.Symbols.FSharpAttribute] get_Attributes()

tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5162,6 +5162,8 @@ FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Symbols.FSharpXmlDoc Xm
51625162
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Symbols.FSharpXmlDoc get_XmlDoc()
51635163
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Text.Range DeclarationLocation
51645164
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Text.Range get_DeclarationLocation()
5165+
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Symbols.FSharpEntity DeclaringEntity
5166+
FSharp.Compiler.Symbols.FSharpUnionCase: FSharp.Compiler.Symbols.FSharpEntity get_DeclaringEntity()
51655167
FSharp.Compiler.Symbols.FSharpUnionCase: Int32 GetHashCode()
51665168
FSharp.Compiler.Symbols.FSharpUnionCase: System.Collections.Generic.IList`1[FSharp.Compiler.Symbols.FSharpAttribute] Attributes
51675169
FSharp.Compiler.Symbols.FSharpUnionCase: System.Collections.Generic.IList`1[FSharp.Compiler.Symbols.FSharpAttribute] get_Attributes()

vsintegration/src/FSharp.Editor/Navigation/GoToDefinition.fs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,18 @@ type internal GoToDefinition(metadataAsSource: FSharpMetadataAsSourceService) =
473473
| :? FSharpMemberOrFunctionOrValue as symbol ->
474474
symbol.ApparentEnclosingEntity.TryGetMetadataText()
475475
|> Option.map (fun text -> text, symbol.ApparentEnclosingEntity.DisplayName)
476+
| :? FSharpField as symbol ->
477+
match symbol.DeclaringEntity with
478+
| Some entity ->
479+
let text = entity.TryGetMetadataText()
480+
481+
match text with
482+
| Some text -> Some(text, entity.DisplayName)
483+
| None -> None
484+
| None -> None
485+
| :? FSharpUnionCase as symbol ->
486+
symbol.DeclaringEntity.TryGetMetadataText()
487+
|> Option.map (fun text -> text, symbol.DisplayName)
476488
| _ -> None
477489

478490
let result =
@@ -523,13 +535,24 @@ type internal GoToDefinition(metadataAsSource: FSharpMetadataAsSourceService) =
523535
symbol1.DisplayName = symbol2.DisplayName
524536
| (:? FSharpMemberOrFunctionOrValue as symbol1), (:? FSharpMemberOrFunctionOrValue as symbol2) ->
525537
symbol1.DisplayName = symbol2.DisplayName
538+
&& (match symbol1.DeclaringEntity, symbol2.DeclaringEntity with
539+
| Some e1, Some e2 -> e1.CompiledName = e2.CompiledName
540+
| _ -> false)
526541
&& symbol1.GenericParameters.Count = symbol2.GenericParameters.Count
527542
&& symbol1.CurriedParameterGroups.Count = symbol2.CurriedParameterGroups.Count
528543
&& ((symbol1.CurriedParameterGroups, symbol2.CurriedParameterGroups)
529544
||> Seq.forall2 (fun pg1 pg2 ->
530545
pg1.Count = pg2.Count
531546
&& ((pg1, pg2) ||> Seq.forall2 (fun p1 p2 -> areTypesEqual p1.Type p2.Type))))
532547
&& areTypesEqual symbol1.ReturnParameter.Type symbol2.ReturnParameter.Type
548+
| (:? FSharpField as symbol1), (:? FSharpField as symbol2) when x.IsFromDefinition ->
549+
symbol1.DisplayName = symbol2.DisplayName
550+
&& (match symbol1.DeclaringEntity, symbol2.DeclaringEntity with
551+
| Some e1, Some e2 -> e1.CompiledName = e2.CompiledName
552+
| _ -> false)
553+
| (:? FSharpUnionCase as symbol1), (:? FSharpUnionCase as symbol2) ->
554+
symbol1.DisplayName = symbol2.DisplayName
555+
&& symbol1.DeclaringEntity.CompiledName = symbol2.DeclaringEntity.CompiledName
533556
| _ -> false)
534557
|> Option.map (fun x -> x.Range)
535558

0 commit comments

Comments
 (0)