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

Hidden members should not be shown in QuickInfo #73

Closed
wants to merge 5 commits into from
Closed
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
3 changes: 2 additions & 1 deletion src/fsharp/NicePrint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,8 @@ module private TastDefinitionPrinting =
// Don't print individual methods forming interface implementations - these are currently never exported
not (isInterfaceTy denv.g oty)
| [] -> true)
|> List.filter (fun v -> denv.showObsoleteMembers || not (HasFSharpAttribute denv.g denv.g.attrib_SystemObsolete v.Attribs))
|> List.filter (fun v -> denv.showObsoleteMembers || not (Infos.AttributeChecking.CheckFSharpAttributesForObsolete denv.g v.Attribs))
|> List.filter (fun v -> denv.showHiddenMembers || not (Infos.AttributeChecking.CheckFSharpAttributesForHidden denv.g v.Attribs))
// sort
let sortKey (v:ValRef) = (not v.IsConstructor, // constructors before others
v.Id.idText, // sort by name
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/ast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type XmlDocCollector() =
lazy (savedLines.ToArray() |> Array.sortWith (fun (_,p1) (_,p2) -> posCompare p1 p2))

let check() =
assert (not savedLinesAsArray.IsValueCreated && "can't add more XmlDoc elements to XmlDocCOllector after extracting first XmlDoc from the overall results" <> "")
assert (not savedLinesAsArray.IsValueCreated && "can't add more XmlDoc elements to XmlDocCollector after extracting first XmlDoc from the overall results" <> "")

member x.AddGrabPoint(pos) =
check()
Expand Down
6 changes: 4 additions & 2 deletions src/fsharp/fsc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,13 @@ let runFromCommandLineToImportingAssemblies(displayPSTypeProviderSecurityDialogB
// Code from here on down is just used by fsc.exe
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

let BuildInitialDisplayEnvForDocGeneration tcGlobals =
let BuildInitialDisplayEnvForSigFileGeneration tcGlobals =
let denv = DisplayEnv.Empty tcGlobals
let denv =
{ denv with
showImperativeTyparAnnotations=true;
showHiddenMembers=true;
showObsoleteMembers=true;
showAttributes=true; }
denv.SetOpenPaths
[ FSharpLib.RootPath
Expand All @@ -577,7 +579,7 @@ module InterfaceFileWriter =
fprintfn os ""

for (TImplFile(_,_,mexpr,_,_)) in declaredImpls do
let denv = BuildInitialDisplayEnvForDocGeneration tcGlobals
let denv = BuildInitialDisplayEnvForSigFileGeneration tcGlobals
writeViaBufferWithEnvironmentNewLines os (fun os s -> Printf.bprintf os "%s\n\n" s)
(NicePrint.layoutInferredSigOfModuleExpr true denv infoReader AccessibleFromSomewhere range0 mexpr |> Layout.squashTo 80 |> Layout.showL)

Expand Down
31 changes: 19 additions & 12 deletions src/fsharp/infos.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2637,22 +2637,29 @@ module AttributeChecking =
let (AttribInfo(tref,_)) = g.attrib_SystemObsolete
isSome (TryDecodeILAttribute g tref (Some(tref.Scope)) cattrs)

/// Checks the attributes for CompilerMessageAttribute, which has an IsHidden argument that allows
/// items to be suppressed from intellisense.
let CheckFSharpAttributesForHidden g attribs =
nonNil attribs &&
(match TryFindFSharpAttribute g g.attrib_CompilerMessageAttribute attribs with
| Some(Attrib(_,_,[AttribStringArg _; AttribInt32Arg messageNumber],
ExtractAttribNamedArg "IsHidden" (AttribBoolArg v),_,_,_)) ->
// Message number 62 is for "ML Compatibility". Items labelled with this are visible in intellisense
// when mlCompatibility is set.
v && not (messageNumber = 62 && g.mlCompatibility)
| _ -> false)

/// Indicate if a list of F# attributes contains 'ObsoleteAttribute'. Used to suppress the item in intellisense.
let CheckFSharpAttributesForObsolete g attribs =
nonNil attribs && (HasFSharpAttribute g g.attrib_SystemObsolete attribs)

/// Indicate if a list of F# attributes contains 'ObsoleteAttribute'. Used to suppress the item in intellisense.
/// Also check the attributes for CompilerMessageAttribute, which has an IsHidden argument that allows
/// items to be suppressed from intellisense.
let CheckFSharpAttributesForUnseen g attribs _m =
nonNil attribs &&
(let isObsolete = isSome (TryFindFSharpAttribute g g.attrib_SystemObsolete attribs)
let isHidden =
(match TryFindFSharpAttribute g g.attrib_CompilerMessageAttribute attribs with
| Some(Attrib(_,_,[AttribStringArg _; AttribInt32Arg messageNumber],
ExtractAttribNamedArg "IsHidden" (AttribBoolArg v),_,_,_)) ->
// Message number 62 is for "ML Compatibility". Items labelled with this are visible in intellisense
// when mlCompatibility is set.
v && not (messageNumber = 62 && g.mlCompatibility)
| _ -> false)
isObsolete || isHidden
)
nonNil attribs &&
(CheckFSharpAttributesForObsolete g attribs ||
CheckFSharpAttributesForHidden g attribs)

#if EXTENSIONTYPING
/// Indicate if a list of provided attributes contains 'ObsoleteAttribute'. Used to suppress the item in intellisense.
Expand Down
4 changes: 3 additions & 1 deletion src/fsharp/tastops.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2354,6 +2354,7 @@ type DisplayEnv =
suppressNestedTypes: bool;
maxMembers : int option;
showObsoleteMembers: bool;
showHiddenMembers: bool;
showTyparBinding: bool;
showImperativeTyparAnnotations: bool;
suppressInlineKeyword: bool;
Expand Down Expand Up @@ -2384,7 +2385,8 @@ type DisplayEnv =
shortTypeNames=false;
suppressNestedTypes=false;
maxMembers=None;
showObsoleteMembers=true;
showObsoleteMembers=false;
showHiddenMembers=false;
showTyparBinding = false;
showImperativeTyparAnnotations=false;
suppressInlineKeyword=false;
Expand Down
1 change: 1 addition & 0 deletions src/fsharp/tastops.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ type DisplayEnv =
suppressNestedTypes: bool;
maxMembers : int option;
showObsoleteMembers: bool;
showHiddenMembers: bool;
showTyparBinding: bool;
showImperativeTyparAnnotations: bool;
suppressInlineKeyword:bool;
Expand Down
40 changes: 40 additions & 0 deletions vsintegration/src/unittests/Tests.LanguageService.QuickInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,46 @@ type QuickInfoTests() =
f = (fun ((text, _), _) -> printfn "actual %s" text; Assert.IsTrue(text.Contains "tooltip for operator"))
)

[<Test>]
member public this.``QuickInfo.HiddenMember``() =
// Tooltips showed hidden members - #50
let source = """
open System.ComponentModel

type TypeU = { Element : string }
with
[<EditorBrowsableAttribute(EditorBrowsableState.Never)>]
[<CompilerMessageAttribute("This method is intended for use in generated code only.", 10001, IsHidden=true, IsError=false)>]
member x._Print = x.Element.ToString()

let u = { Element = "abc" }
"""
this.CheckTooltip(
code = source,
marker = "ypeU =",
atStart = true,
f = (fun ((text, _), _) -> printfn "actual %s" text; Assert.IsFalse(text.Contains "member _Print"))
)

[<Test>]
member public this.``QuickInfo.ObsoleteMember``() =
// Tooltips showed obsolete members - #50
let source = """
type TypeU = { Element : string }
with
[<System.ObsoleteAttribute("This is replaced with Print2")>]
member x.Print1 = x.Element.ToString()
member x.Print2 = x.Element.ToString()

let u = { Element = "abc" }
"""
this.CheckTooltip(
code = source,
marker = "ypeU =",
atStart = true,
f = (fun ((text, _), _) -> printfn "actual %s" text; Assert.IsFalse(text.Contains "member Print1"))
)

[<Test>]
member public this.``QuickInfo.OverriddenMethods``() =
let source = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module internal XmlDocumentation =
"<root>" + xml + "</root>"
else xml

/// Provide Xml Documentatation
/// Provide Xml Documentation
type Provider(xmlIndexService:IVsXMLMemberIndexService) =
/// Index of assembly name to xml member index.
let mutable xmlCache = new AgedLookup<string,IVsXMLMemberIndex>(10,areSame=(fun (x,y) -> x = y))
Expand Down