Skip to content

Commit

Permalink
Add CompliedName to MemberOrValue
Browse files Browse the repository at this point in the history
  • Loading branch information
artyomszasa committed Dec 29, 2015
1 parent 25b9dec commit 33432ec
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/FSharp.MetadataFormat/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ type MemberOrValue =
Modifiers : string list
TypeArguments : string list
Signature : string
SourceLocation : string option }
SourceLocation : string option
CompiledName : string option }
member x.FormatUsage(maxLength) = x.Usage(maxLength)
member x.FormatTypeArguments = String.concat ", " x.TypeArguments
member x.FormatModifiers = String.concat " " x.Modifiers
member x.FormatSourceLocation = defaultArg x.SourceLocation ""
static member Create(usage, mods, typars, sign, location) =
member x.FormatCompiledName = defaultArg x.CompiledName ""
static member Create(usage, mods, typars, sign, location, compiledName) =
{ Usage = usage; Modifiers = mods; TypeArguments = typars;
Signature = sign; SourceLocation = location }
Signature = sign; SourceLocation = location; CompiledName = compiledName }

type MemberKind =
// In a module
Expand Down Expand Up @@ -190,6 +192,12 @@ module ValueReader =
CompilerOptions = compilerOptions
FormatAgent = formatAgent }

let inline private getCompiledName (s : ^a when ^a :> FSharpSymbol) =
let compiledName = (^a : (member CompiledName : string) (s))
match compiledName = s.DisplayName with
| true -> None
| _ -> Some compiledName

let formatSourceLocation (urlRangeHighlight : Uri -> int -> int -> string) (sourceFolderRepo : (string * string) option) (location : range option) =
location |> Option.bind (fun location ->
sourceFolderRepo |> Option.map (fun (baseFolder, repo) ->
Expand Down Expand Up @@ -408,7 +416,7 @@ module ValueReader =
// If there is a signature file, we should go for implementation file
let loc = tryGetLocation v
let location = formatSourceLocation ctx.UrlRangeHighlight ctx.SourceFolderRepository loc
MemberOrValue.Create(buildShortUsage, modifiers, typars, signature, location)
MemberOrValue.Create(buildShortUsage, modifiers, typars, signature, location, getCompiledName v)

(*
Expand Down Expand Up @@ -462,7 +470,7 @@ module ValueReader =
let signature = fields |> List.map (fun field -> formatType field.FieldType) |> String.concat " * "
let loc = tryGetLocation case
let location = formatSourceLocation ctx.UrlRangeHighlight ctx.SourceFolderRepository loc
MemberOrValue.Create(usage, modifiers, typeparams, signature, location)
MemberOrValue.Create(usage, modifiers, typeparams, signature, location, getCompiledName case)

let readFSharpField (ctx:ReadingContext) (field:FSharpField) =
let usage (maxLength:int) = field.Name
Expand All @@ -473,7 +481,7 @@ module ValueReader =
let signature = formatType field.FieldType
let loc = tryGetLocation field
let location = formatSourceLocation ctx.UrlRangeHighlight ctx.SourceFolderRepository loc
MemberOrValue.Create(usage, modifiers, typeparams, signature, location)
MemberOrValue.Create(usage, modifiers, typeparams, signature, location, if field.Name <> field.DisplayName then Some field.Name else None)

let getFSharpStaticParamXmlSig (typeProvider:FSharpEntity) parameterName =
"SP:" + typeProvider.AccessPath + "." + typeProvider.LogicalName + "." + parameterName
Expand All @@ -485,7 +493,7 @@ module ValueReader =
let signature = formatType staticParam.Kind + (if staticParam.IsOptional then sprintf " (optional, default = %A)" staticParam.DefaultValue else "")
let loc = tryGetLocation staticParam
let location = formatSourceLocation ctx.UrlRangeHighlight ctx.SourceFolderRepository loc
MemberOrValue.Create(usage, modifiers, typeparams, signature, location)
MemberOrValue.Create(usage, modifiers, typeparams, signature, location, if staticParam.Name <> staticParam.DisplayName then Some staticParam.Name else None)

module Reader =
open FSharp.Markdown
Expand Down

1 comment on commit 33432ec

@artyomszasa
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be usefull to display the compiled name of documented entries.
It is important when one dealing with reflection or using library from different .NET language.

Please sign in to comment.