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

update handling of langword and crefs in see xmldoc nodes #838

Merged
merged 1 commit into from
Oct 15, 2021
Merged
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
64 changes: 28 additions & 36 deletions src/FsAutoComplete.Core/TipFormatter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ module private Format =
else
Map.empty

type AttrLookup = Map<string, string> -> Option<string>

let private cref: AttrLookup = Map.tryFind "cref"
let private langword: AttrLookup = Map.tryFind "langword"
let private href: AttrLookup = Map.tryFind "href"
let private lang: AttrLookup = Map.tryFind "lang"
let private name: AttrLookup = Map.tryFind "name"

let rec private applyFormatter (info : FormatterInfo) text =
let pattern = tagPattern info.TagName
match Regex.Match(text, pattern, RegexOptions.IgnoreCase) with
Expand Down Expand Up @@ -159,7 +167,7 @@ module private Format =

| NonVoidElement (innerText, attributes) ->
let lang =
match Map.tryFind "lang" attributes with
match lang attributes with
| Some lang ->
lang

Expand Down Expand Up @@ -207,7 +215,7 @@ module private Format =

| NonVoidElement (innerText, attributes) ->
let href =
match Map.tryFind "href" attributes with
match href attributes with
| Some href ->
href

Expand Down Expand Up @@ -248,45 +256,33 @@ module private Format =
|> applyFormatter

let private see =
let getCRef (attributes : Map<string, string>) = Map.tryFind "cref" attributes
let formatFromAttributes (attrs: Map<string, string>) =
match cref attrs with
// crefs can have backticks in them, which mess with formatting.
// for safety we can just double-backtick and markdown is ok with that.
| Some cref -> Some $"``{extractMemberText cref}``"
| None ->
match langword attrs with
| Some langword -> Some $"`%s{langword}`"
| None -> None
{
TagName = "see"
Formatter =
function
| VoidElement attributes ->
match getCRef attributes with
| Some cref ->
// TODO: Add config to generates command
"`" + extractMemberText cref + "`"
|> Some

| None ->
None

| VoidElement attributes -> formatFromAttributes attributes
| NonVoidElement (innerText, attributes) ->
if String.IsNullOrWhiteSpace innerText then
match getCRef attributes with
| Some cref ->
// TODO: Add config to generates command
"`" + extractMemberText cref + "`"
|> Some

| None ->
None
else
"`" + innerText + "`"
|> Some
if String.IsNullOrWhiteSpace innerText then formatFromAttributes attributes
else Some $"`{innerText}`"
}
|> applyFormatter

let private xref =
let getHRef (attributes : Map<string, string>) = Map.tryFind "href" attributes
{
TagName = "xref"
Formatter =
function
| VoidElement attributes ->
match getHRef attributes with
match href attributes with
| Some href ->
// TODO: Add config to generates command
"`" + extractMemberText href + "`"
Expand All @@ -297,7 +293,7 @@ module private Format =

| NonVoidElement (innerText, attributes) ->
if String.IsNullOrWhiteSpace innerText then
match getHRef attributes with
match href attributes with
| Some href ->
// TODO: Add config to generates command
"`" + extractMemberText href + "`"
Expand All @@ -312,14 +308,12 @@ module private Format =
|> applyFormatter

let private paramRef =
let getName (attributes : Map<string, string>) = Map.tryFind "name" attributes

{
TagName = "paramref"
Formatter =
function
| VoidElement attributes ->
match getName attributes with
match name attributes with
| Some name ->
"`" + name + "`"
|> Some
Expand All @@ -329,7 +323,7 @@ module private Format =

| NonVoidElement (innerText, attributes) ->
if String.IsNullOrWhiteSpace innerText then
match getName attributes with
match name attributes with
| Some name ->
// TODO: Add config to generates command
"`" + name + "`"
Expand All @@ -345,14 +339,12 @@ module private Format =
|> applyFormatter

let private typeParamRef =
let getName (attributes : Map<string, string>) = Map.tryFind "name" attributes

{
TagName = "typeparamref"
Formatter =
function
| VoidElement attributes ->
match getName attributes with
match name attributes with
| Some name ->
"`" + name + "`"
|> Some
Expand All @@ -362,7 +354,7 @@ module private Format =

| NonVoidElement (innerText, attributes) ->
if String.IsNullOrWhiteSpace innerText then
match getName attributes with
match name attributes with
| Some name ->
// TODO: Add config to generates command
"`" + name + "`"
Expand Down