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

Add ComiledName to members with F# specific naming #372

Merged
merged 4 commits into from
Dec 29, 2015
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
6 changes: 5 additions & 1 deletion misc/templates/reference/part-members.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
</a>
}
@it.Comment.FullText
@if (!String.IsNullOrEmpty(it.Details.FormatCompiledName))
{
@:<p>CompiledName: <code>@it.Details.FormatCompiledName</code></p>
}
</td>
</tr>
}
</tbody>
</table>
}
}
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