Skip to content

Show glyph on quick info #1

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

Open
wants to merge 1 commit into
base: vladima/classification
Choose a base branch
from
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 vsintegration/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<package id="Microsoft.VisualStudio.Shell.Design" version="14.3.25407" targetFramework="net46" />
<package id="Microsoft.VisualStudio.Settings.15.0" version="15.0.25824-RC" targetFramework="net46" />
<package id="Microsoft.VisualStudio.Utilities" version="14.3.25407" targetFramework="net46" />
<package id="Microsoft.VisualStudio.Language.Intellisense" version="14.3.25407" targetFramework="net46" />
<package id="Microsoft.VisualStudio.Language.StandardClassification" version="14.3.25407" targetFramework="net46" />
<package id="Microsoft.VisualStudio.Language.Intellisense" version="14.3.25407" targetFramework="net46" />
<package id="Microsoft.VisualStudio.Designer.Interfaces" version="1.1.4322" />
Expand Down
113 changes: 89 additions & 24 deletions vsintegration/src/FSharp.Editor/CommonHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -318,30 +318,6 @@ module internal Extensions =

isPrivate && declaredInTheFile

let glyphMajorToRoslynGlyph = function
| GlyphMajor.Class -> Glyph.ClassPublic
| GlyphMajor.Constant -> Glyph.ConstantPublic
| GlyphMajor.Delegate -> Glyph.DelegatePublic
| GlyphMajor.Enum -> Glyph.EnumPublic
| GlyphMajor.EnumMember -> Glyph.FieldPublic
| GlyphMajor.Event -> Glyph.EventPublic
| GlyphMajor.Exception -> Glyph.ClassPublic
| GlyphMajor.FieldBlue -> Glyph.FieldPublic
| GlyphMajor.Interface -> Glyph.InterfacePublic
| GlyphMajor.Method -> Glyph.MethodPublic
| GlyphMajor.Method2 -> Glyph.MethodPublic
| GlyphMajor.Module -> Glyph.ModulePublic
| GlyphMajor.NameSpace -> Glyph.Namespace
| GlyphMajor.Property -> Glyph.PropertyPublic
| GlyphMajor.Struct -> Glyph.StructurePublic
| GlyphMajor.Typedef -> Glyph.ClassPublic
| GlyphMajor.Type -> Glyph.ClassPublic
| GlyphMajor.Union -> Glyph.EnumPublic
| GlyphMajor.Variable -> Glyph.FieldPublic
| GlyphMajor.ValueType -> Glyph.StructurePublic
| GlyphMajor.Error -> Glyph.Error
| _ -> Glyph.None

type Async<'a> with
/// Creates an asynchronous workflow that runs the asynchronous workflow given as an argument at most once.
/// When the returned workflow is started for the second time, it reuses the result of the previous execution.
Expand All @@ -362,3 +338,92 @@ module internal Extensions =
let! result = input
return f result
}

[<AutoOpen>]
module internal TypedAstExtensionHelpers =
type FSharpEntity with
member this.TryGetFullName() =
match (try this.TryFullName with _ -> None) with
| Some x -> Some x
| None ->
try Some (String.Join(".", this.AccessPath, this.DisplayName))
with _ -> None

type FSharpMemberOrFunctionOrValue with
// FullType may raise exceptions (see https://github.com/fsharp/fsharp/issues/307).
member x.FullTypeSafe = try Some x.FullType with _ -> None

let (|Public|Internal|Protected|Private|) (a: FSharpAccessibility) =
if a.IsPublic then Public
elif a.IsInternal then Internal
elif a.IsPrivate then Private
else Protected

module internal Glyph =
let forSymbol (symbol: FSharpSymbol) =
match symbol with
| :? FSharpUnionCase as x ->
match x.Accessibility with
| Public -> Glyph.EnumPublic
| Internal -> Glyph.EnumInternal
| Protected -> Glyph.EnumProtected
| Private -> Glyph.EnumPrivate
| :? FSharpActivePatternCase -> Glyph.EnumPublic
| :? FSharpField as x ->
match x.Accessibility with
| Public -> Glyph.FieldPublic
| Internal -> Glyph.FieldInternal
| Protected -> Glyph.FieldProtected
| Private -> Glyph.FieldPrivate
| :? FSharpParameter -> Glyph.Parameter
| :? FSharpMemberOrFunctionOrValue as x ->
if x.IsExtensionMember then
match x.Accessibility with
| Public -> Glyph.ExtensionMethodPublic
| Internal -> Glyph.ExtensionMethodInternal
| Protected -> Glyph.ExtensionMethodProtected
| Private -> Glyph.ExtensionMethodPrivate
elif x.IsProperty || x.IsPropertyGetterMethod || x.IsPropertySetterMethod then
match x.Accessibility with
| Public -> Glyph.PropertyPublic
| Internal -> Glyph.PropertyInternal
| Protected -> Glyph.PropertyProtected
| Private -> Glyph.PropertyPrivate
elif x.IsEvent then
match x.Accessibility with
| Public -> Glyph.EventPublic
| Internal -> Glyph.EventInternal
| Protected -> Glyph.EventProtected
| Private -> Glyph.EventPrivate
else
match x.Accessibility with
| Public -> Glyph.MethodPublic
| Internal -> Glyph.MethodInternal
| Protected -> Glyph.MethodProtected
| Private -> Glyph.MethodPrivate
| :? FSharpEntity as x ->
if x.IsFSharpModule then
match x.Accessibility with
| Public -> Glyph.ModulePublic
| Internal -> Glyph.ModuleInternal
| Protected -> Glyph.ModuleProtected
| Private -> Glyph.ModulePrivate
elif x.IsEnum || x.IsFSharpUnion then
match x.Accessibility with
| Public -> Glyph.EnumPublic
| Internal -> Glyph.EnumInternal
| Protected -> Glyph.EnumProtected
| Private -> Glyph.EnumPrivate
elif x.IsInterface then
match x.Accessibility with
| Public -> Glyph.InterfacePublic
| Internal -> Glyph.InterfaceInternal
| Protected -> Glyph.InterfaceProtected
| Private -> Glyph.InterfacePrivate
else
match x.Accessibility with
| Public -> Glyph.ClassPublic
| Internal -> Glyph.ClassInternal
| Protected -> Glyph.ClassProtected
| Private -> Glyph.ClassPrivate
| _ -> Glyph.None
3 changes: 3 additions & 0 deletions vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@
<Reference Include="Microsoft.VisualStudio.Package.LanguageService.$(RoslynVSBinariesVersion), Version=$(RoslynVSBinariesVersion).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>$(FSharpSourcesRoot)\..\packages\Microsoft.VisualStudio.Package.LanguageService.$(RoslynVSBinariesVersion).$(RoslynVSPackagesVersion)\lib\Microsoft.VisualStudio.Package.LanguageService.$(RoslynVSBinariesVersion).dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.Language.Intellisense.$(RoslynVSBinariesVersion), Version=$(RoslynVSBinariesVersion).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>$(FSharpSourcesRoot)\..\packages\Microsoft.VisualStudio.Language.Intellisense.$(RoslynVSBinariesVersion).$(RoslynVSPackagesVersion)\lib\Microsoft.VisualStudio.Language.Intellisense.$(RoslynVSBinariesVersion).dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.Language.StandardClassification, Version=$(RoslynVSBinariesVersion).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>$(FSharpSourcesRoot)\..\packages\Microsoft.VisualStudio.Language.StandardClassification.$(RoslynVSPackagesVersion)\lib\net45\Microsoft.VisualStudio.Language.StandardClassification.dll</HintPath>
</Reference>
Expand Down
20 changes: 13 additions & 7 deletions vsintegration/src/FSharp.Editor/QuickInfo/QuickInfoProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ open Microsoft.VisualStudio.Text.Tagging
open Microsoft.VisualStudio.Text.Formatting
open Microsoft.VisualStudio.Shell
open Microsoft.VisualStudio.Shell.Interop
open Microsoft.VisualStudio.Language.Intellisense

open Microsoft.FSharp.Compiler
open Microsoft.FSharp.Compiler.Parser
Expand Down Expand Up @@ -65,7 +66,8 @@ type internal FSharpQuickInfoProvider
_classificationFormatMapService: IClassificationFormatMapService,
checkerProvider: FSharpCheckerProvider,
projectInfoManager: ProjectInfoManager,
typeMap: Shared.Utilities.ClassificationTypeMap
typeMap: Shared.Utilities.ClassificationTypeMap,
glyphService: IGlyphService
) =

let xmlMemberIndexService = serviceProvider.GetService(typeof<SVsXMLMemberIndexService>) :?> IVsXMLMemberIndexService
Expand Down Expand Up @@ -96,10 +98,14 @@ type internal FSharpQuickInfoProvider
match quickParseInfo with
| Some (islandColumn, qualifiers, textSpan) ->
let! res = checkFileResults.GetToolTipTextAlternate(textLineNumber, islandColumn, textLine.ToString(), qualifiers, FSharpTokenTag.IDENT)
return
match res with
| FSharpToolTipText [] -> None
| _ -> Some(res, textSpan)
match res with
| FSharpToolTipText [] -> return None
| _ ->
let! symbolUse = checkFileResults.GetSymbolUseAtLocation(textLineNumber, islandColumn, textLine.ToString(), qualifiers)
match symbolUse with
| Some symbolUse ->
return Some(res, textSpan, symbolUse.Symbol)
| None -> return None
| None -> return None
}

Expand All @@ -118,7 +124,7 @@ type internal FSharpQuickInfoProvider
let! textVersion = document.GetTextVersionAsync(cancellationToken) |> Async.AwaitTask
let! quickInfoResult = FSharpQuickInfoProvider.ProvideQuickInfo(checkerProvider.Checker, document.Id, sourceText, document.FilePath, position, options, textVersion.GetHashCode(), cancellationToken)
match quickInfoResult with
| Some(toolTipElement, textSpan) ->
| Some(toolTipElement, textSpan, symbol) ->
let mainDescription = Collections.Generic.List()
let documentation = Collections.Generic.List()
XmlDocumentation.BuildDataTipText(
Expand All @@ -130,7 +136,7 @@ type internal FSharpQuickInfoProvider
let content =
QuickInfoDisplayDeferredContent
(
symbolGlyph = null,//SymbolGlyphDeferredContent(),
symbolGlyph = SymbolGlyphDeferredContent(Glyph.forSymbol symbol, glyphService),
warningGlyph = null,
mainDescription = ClassifiableDeferredContent(mainDescription, typeMap),
documentation = ClassifiableDeferredContent(documentation, typeMap),
Expand Down