Skip to content

Commit

Permalink
Members hidden from IntelliSense are now also omitted in QuickInfo - f…
Browse files Browse the repository at this point in the history
…ixes #50

closes #73

commit e127dfa
Author: Steffen Forkmann <steffen.forkmann@msu-solutions.de>
Date:   Wed Jan 21 10:52:10 2015 +0100

    fix typos in XmlDocumentation.fs and ast.fs

commit 6f99029
Author: Steffen Forkmann <steffen.forkmann@msu-solutions.de>
Date:   Wed Jan 21 12:17:58 2015 +0100

    Obsolete members are now also omitted in QuickInfo - references #50

commit ae54746
Author: Steffen Forkmann <steffen.forkmann@msu-solutions.de>
Date:   Wed Jan 21 12:17:16 2015 +0100

    Capturing broken QuickTip for obsolete methods in test - references #50

commit 1e38a8a
Author: Steffen Forkmann <steffen.forkmann@msu-solutions.de>
Date:   Wed Jan 21 10:51:23 2015 +0100

    Members hidden from IntelliSense are now also omitted in QuickInfo - fixes #50

commit 5f27136
Author: Steffen Forkmann <steffen.forkmann@msu-solutions.de>
Date:   Sun Jan 18 10:49:41 2015 +0100

    Capturing broken QuickTips for hidden methods in test - references #50
  • Loading branch information
forki authored and latkin committed Jan 22, 2015
1 parent a932a13 commit ac55622
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/fsharp/NicePrint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,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 @@ -2660,22 +2660,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 @@ -2344,6 +2344,7 @@ type DisplayEnv =
suppressNestedTypes: bool;
maxMembers : int option;
showObsoleteMembers: bool;
showHiddenMembers: bool;
showTyparBinding: bool;
showImperativeTyparAnnotations: bool;
suppressInlineKeyword: bool;
Expand Down Expand Up @@ -2374,7 +2375,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 @@ -587,6 +587,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

0 comments on commit ac55622

Please sign in to comment.