Skip to content

Commit

Permalink
Fix navigation for external enums, DUs and name resultion for members (
Browse files Browse the repository at this point in the history
  • Loading branch information
vzarytovskii authored May 29, 2023
1 parent e3c395d commit 146611d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
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
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 @@ -5162,6 +5162,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 @@ -5162,6 +5162,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

0 comments on commit 146611d

Please sign in to comment.