Skip to content

Commit

Permalink
port autoproperty fix from nightly branch
Browse files Browse the repository at this point in the history
  • Loading branch information
baronfel committed Aug 8, 2023
1 parent b36c808 commit a00de3f
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/FsAutoComplete/CodeFixes/AddMissingXmlDocumentation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ let title = "Add missing XML documentation"

let private tryGetExistingXmlDoc (pos: FSharp.Compiler.Text.Position) (xmlDoc: PreXmlDoc) =
let tryGetSummaryIfContainsPos (xd: PreXmlDoc) =
let d = xd.ToXmlDoc(false, None)

if rangeContainsPos d.Range pos then
if rangeContainsPos xd.Range pos then
let d = xd.ToXmlDoc(false, None)
if Array.isEmpty d.UnprocessedLines then
None
elif d.UnprocessedLines |> Array.exists (fun s -> s.Contains("<summary>")) then
Some(d.UnprocessedLines, d.Range)
Some(d.UnprocessedLines, xd.Range)
else
let lines =
match d.UnprocessedLines with
| [||] -> [| " <summary></summary>" |]
| [| c |] -> [| $" <summary>%s{c.Trim()}</summary>" |]
| cs -> [| yield " <summary>"; yield! cs; yield " </summary>" |]

Some(lines, d.Range)
Some(lines, xd.Range)
else
None

Expand All @@ -50,7 +50,7 @@ let private tryGetCommentsAndSymbolPos input pos =
| SynPat.LongIdent(longDotId = longDotId) -> longDotId.Range.End
| _ -> s.RangeOfHeadPattern.Start // for use statements

Some(docLines, docRange, symbolRange)
Some(docLines, docRange, symbolRange, false)
| None -> defaultTraverse synBinding

SyntaxTraversal.Traverse(
Expand Down Expand Up @@ -89,7 +89,7 @@ let private tryGetCommentsAndSymbolPos input pos =
let docAndDocRange = tryGetExistingXmlDoc pos xmlDoc

match docAndDocRange with
| Some(docLines, docRange) -> Some(docLines, docRange, ident.idRange.End)
| Some(docLines, docRange) -> Some(docLines, docRange, ident.idRange.End, true)
| _ -> None
| _ -> None)
| _ -> None)
Expand All @@ -115,7 +115,7 @@ let fix (getParseResultsForFile: GetParseResultsForFile) : CodeFix =
let commentsAndPos = tryGetCommentsAndSymbolPos parseAndCheck.GetAST fcsPos

match commentsAndPos with
| Some(docLines, docRange, symbolPos) ->
| Some(docLines, docRange, symbolPos, isAutoProperty) ->
let lineStrOfSymbol = _sourceText.GetLine symbolPos |> Option.defaultValue ""
let signatureData = parseAndCheck.TryGetSignatureData symbolPos lineStrOfSymbol

Expand All @@ -133,16 +133,21 @@ let fix (getParseResultsForFile: GetParseResultsForFile) : CodeFix =
|> List.tryFindIndexBack (fun s -> s.Contains("</param>") || s.Contains("</summary>"))

let missingParams =
match memberParameters with
| [] -> []
| parameters ->
parameters
|> List.concat
|> List.filter (fun (parameter, _) ->
docLines
|> List.exists (fun c -> c.Contains($"<param name=\"%s{parameter}\">"))
|> not)
|> List.mapi (fun _index parameter -> parameterSection parameter)
if isAutoProperty then
// An auto property has a setter symbol which takes a parameter.
// As the user didn't write this parameter, a missing parameter should not be returned.
[]
else
match memberParameters with
| [] -> []
| parameters ->
parameters
|> List.concat
|> List.filter (fun (parameter, _) ->
docLines
|> List.exists (fun c -> c.Contains($"<param name=\"%s{parameter}\">"))
|> not)
|> List.mapi (fun _index parameter -> parameterSection parameter)

match indexForParams with
| None -> List.append docLines missingParams
Expand Down

0 comments on commit a00de3f

Please sign in to comment.