Skip to content
Open
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
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/11.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* Fix box instruction for literal upcasts. (Issue [#18319](https://github.com/dotnet/fsharp/issues/18319), [PR #19338](https://github.com/dotnet/fsharp/pull/19338))
* Fix Decimal Literal causes InvalidProgramException in Debug builds. (Issue [#18956](https://github.com/dotnet/fsharp/issues/18956), [PR #19338](https://github.com/dotnet/fsharp/pull/19338))
* Fix `AttributeUsage.AllowMultiple` not being inherited for attributes subclassed in C#. ([Issue #17107](https://github.com/dotnet/fsharp/issues/17107), [PR #19315](https://github.com/dotnet/fsharp/pull/19315))
* Fix methods being tagged as `Member` instead of `Method` in tooltips. ([Issue #10540](https://github.com/dotnet/fsharp/issues/10540), [PR #19507](https://github.com/dotnet/fsharp/pull/19507))

### Added

Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/Checking/NicePrint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,8 @@ module PrintTastMemberOrVals =
let resL =
if short then tauL
else
let nameL = layoutMemberName denv vref niceMethodTypars argInfos tagMember vref.DisplayNameCoreMangled true
let tag = if isNil argInfos then tagMember else tagMethod
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you also check properties with parameters and indexers?

let nameL = layoutMemberName denv vref niceMethodTypars argInfos tag vref.DisplayNameCoreMangled true
let nameL = if short then nameL else mkInlineL denv vref.Deref nameL
stat --- ((nameL |> addColonL) ^^ tauL)
prettyTyparInst, resL
Expand Down
17 changes: 16 additions & 1 deletion src/Compiler/TypedTree/TypedTreeOps.FreeVars.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,22 @@ module internal MemberRepresentation =
| SynMemberKind.PropertyGetSet -> tagProperty vref.DisplayName
| SynMemberKind.ClassConstructor
| SynMemberKind.Constructor -> tagMethod vref.DisplayName
| SynMemberKind.Member -> tagMember vref.DisplayName
| SynMemberKind.Member ->
match vref.ValReprInfo with
| Some valReprInfo ->
let numArgGroups = valReprInfo.ArgInfos.Length

let isMethod =
if memberInfo.MemberFlags.IsInstance then
numArgGroups > 1
else
numArgGroups > 0

if isMethod then
tagMethod vref.DisplayName
else
tagMember vref.DisplayName
| None -> tagMember vref.DisplayName

match fullNameOfParentOfValRefAsLayout vref with
| ValueNone -> wordL n
Expand Down
118 changes: 118 additions & 0 deletions tests/FSharp.Compiler.Service.Tests/TooltipTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,17 @@ let assertAndGetSingleToolTipText items =
let text,_xml,_remarks = assertAndExtractTooltip items
text

let getMainDescriptionTags (ToolTipText(items)) =
match items with
| ToolTipElement.Group [ singleElement ] :: _ -> singleElement.MainDescription
| _ -> failwith $"Expected single group in tooltip, got {items}"

let assertNameTagInTooltip expectedTag expectedName (tooltip: ToolTipText) =
let tags = getMainDescriptionTags tooltip
let found = tags |> Array.exists (fun t -> t.Tag = expectedTag && t.Text = expectedName)
let desc = tags |> Array.map (fun t -> sprintf "(%A, %s)" t.Tag t.Text) |> String.concat ", "
Assert.True(found, sprintf "Expected tag %A with text '%s' in tooltip, but found: %s" expectedTag expectedName desc)

let normalize (s: string) = s.Replace("\r\n", "\n").Replace("\n\n", "\n")

[<Fact>]
Expand Down Expand Up @@ -602,3 +613,110 @@ let normaliz{caret}e' x = x + 1
"""

testXmlDocFallbackToSigFileWhileInImplFile sigSource implSource "Normalize with a prime"

// https://github.com/dotnet/fsharp/issues/10540
[<Fact>]
let ``Instance method should be tagged as Method in tooltip`` () =
Checker.getTooltip """
type T() =
member x.Metho{caret}d() = ()
"""
|> assertNameTagInTooltip TextTag.Method "Method"

// https://github.com/dotnet/fsharp/issues/10540
[<Fact>]
let ``Instance method with parameters should be tagged as Method in tooltip`` () =
Checker.getTooltip """
type T() =
member x.Ad{caret}d(a: int, b: int) = a + b
"""
|> assertNameTagInTooltip TextTag.Method "Add"

// https://github.com/dotnet/fsharp/issues/10540
[<Fact>]
let ``Static method should be tagged as Method in tooltip`` () =
Checker.getTooltip """
type T() =
static member Creat{caret}e() = T()
"""
|> assertNameTagInTooltip TextTag.Method "Create"

// https://github.com/dotnet/fsharp/issues/10540
[<Fact>]
let ``Property-like member should be tagged as Property`` () =
Checker.getTooltip """
type T() =
member x.Valu{caret}e = 42
"""
|> assertNameTagInTooltip TextTag.Property "Value"

// https://github.com/dotnet/fsharp/issues/10540
[<Fact>]
let ``Auto property should be tagged as Property`` () =
Checker.getTooltip """
namespace Foo

type Bar() =
member val Fo{caret}o = "bla" with get, set
"""
|> assertNameTagInTooltip TextTag.Property "Foo"

// https://github.com/dotnet/fsharp/issues/10540
[<Fact>]
let ``Indexer should be tagged as Property`` () =
Checker.getTooltip """
type T() =
member x.Ite{caret}m with get(i: int) = i
"""
|> assertNameTagInTooltip TextTag.Property "Item"

// https://github.com/dotnet/fsharp/issues/10540
[<Fact>]
let ``Indexer with getter and setter should be tagged as Property`` () =
Checker.getTooltip """
type T() =
let mutable data = [| 0; 1; 2 |]
member x.Ite{caret}m
with get(i: int) = data.[i]
and set (i: int) (v: int) = data.[i] <- v
"""
|> assertNameTagInTooltip TextTag.Property "Item"

// https://github.com/dotnet/fsharp/issues/10540
[<Fact>]
let ``Property with explicit getter should be tagged as Property`` () =
Checker.getTooltip """
type T() =
member x.Valu{caret}e with get() = 42
"""
|> assertNameTagInTooltip TextTag.Property "Value"

// https://github.com/dotnet/fsharp/issues/10540
[<Fact>]
let ``Static property should be tagged as Property`` () =
Checker.getTooltip """
type T() =
static member Defaul{caret}t = T()
"""
|> assertNameTagInTooltip TextTag.Property "Default"

// https://github.com/dotnet/fsharp/issues/10540
[<Fact>]
let ``Named indexed property with getter should be tagged as Property`` () =
Checker.getTooltip """
type T() =
member x.Valu{caret}e with get(key: string) = key
"""
|> assertNameTagInTooltip TextTag.Property "Value"

// https://github.com/dotnet/fsharp/issues/10540
[<Fact>]
let ``Named indexed property with getter and setter should be tagged as Property`` () =
Checker.getTooltip """
type T() =
let mutable store = Map.empty<string, int>
member x.Valu{caret}e
with get(key: string) = store.[key]
and set (key: string) (v: int) = store <- store.Add(key, v)
"""
|> assertNameTagInTooltip TextTag.Property "Value"
Loading