Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit70ef698

Browse files
vasily-kirichenkoKevinRansom
authored andcommitted
Quick Info: proper glyphs for namespaces, structures and operators (dotnet#2282)
* show proper glyphs for namespaces and structures* glyphs for literals and delegates* fix layout for struct records and unions* proto does not like Option.defaultValue* show [<Struct>] in layout instead of "struct" for struct records and DUs* show proper glyph for operators in QuickInfo* fix test compilation* layout `Measure` and `Struct` special attributes as typesprettier records layout* fix a test* Revert records layout change* fix TypeChecker* do not print [<Struct>] for ordinary structures
1 parent3b91f24 commit70ef698

File tree

10 files changed

+128
-91
lines changed

10 files changed

+128
-91
lines changed

‎src/fsharp/NicePrint.fs‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ module private PrintTypes =
710710
PrintIL.layoutILType denv[] ty++ argsL
711711

712712
/// Layout '[<attribs>]' above another block
713-
andlayoutAttribs denv kind attrs restL=
713+
andlayoutAttribs denvtykind attrs restL=
714714

715715
if denv.showAttributesthen
716716
// Don't display DllImport attributes in generated signatures
@@ -722,14 +722,18 @@ module private PrintTypes =
722722
letattrs= attrs|> List.filter(IsMatchingFSharpAttribute denv.g denv.g.attrib_ReflectedDefinitionAttribute>>not)
723723
letattrs= attrs|> List.filter(IsMatchingFSharpAttribute denv.g denv.g.attrib_StructLayoutAttribute>>not)
724724
letattrs= attrs|> List.filter(IsMatchingFSharpAttribute denv.g denv.g.attrib_AutoSerializableAttribute>>not)
725+
725726
match attrswith
726727
|[]-> restL
727728
|_-> squareAngleL(sepListL(rightL(tagPunctuation";"))(List.map(layoutAttrib denv) attrs))@@
728729
restL
729-
else
730-
match kindwith
731-
| TyparKind.Type-> restL
732-
| TyparKind.Measure-> squareAngleL(wordL(tagText"Measure"))@@ restL
730+
elif Tastops.isStructRecordOrUnionTyconTy denv.g ty||
731+
((Tastops.isUnionTy denv.g ty|| Tastops.isRecdTy denv.g ty)&& HasFSharpAttribute denv.g denv.g.attrib_StructAttribute attrs)then
732+
squareAngleL(wordL(tagClass"Struct"))@@ restL
733+
else
734+
match kindwith
735+
| TyparKind.Type-> restL
736+
| TyparKind.Measure-> squareAngleL(wordL(tagClass"Measure"))@@ restL
733737

734738
andlayoutTyparAttribs denv kind attrs restL=
735739
match attrs, kindwith
@@ -1184,7 +1188,7 @@ module private PrintTastMemberOrVals =
11841188
layoutNonMemberVal denv(ptps,v,ptau,cxs)
11851189
| Some_->
11861190
layoutMember denv v
1187-
layoutAttribs denv TyparKind.Type v.Attribs vL
1191+
layoutAttribs denvv.TypeTyparKind.Type v.Attribs vL
11881192

11891193
letlayoutMemberSig denv x= x|> PrintTypes.layoutMemberSig denv
11901194
letlayoutTyparConstraint denv x= x|> PrintTypes.layoutTyparConstraint denv
@@ -1591,9 +1595,9 @@ module private TastDefinitionPrinting =
15911595
let_,ty= generalizeTyconRef(mkLocalTyconRef tycon)
15921596
letstart,name=
15931597
letn= tycon.DisplayName
1594-
ifisClassTy g tythen(if simplifiedthen NoneelseSome"class"), tagClass n
1598+
ifisStructTy g tythen Some"struct", tagStruct n
15951599
elif isInterfaceTy g tythen Some"interface", tagInterface n
1596-
elifisStructTy g tythen Some"struct", tagStruct n
1600+
elifisClassTy g tythen(if simplifiedthen NoneelseSome"class"), tagClass n
15971601
else None, tagUnknownType n
15981602
letnameL= layoutAccessibility denv tycon.Accessibility(wordL name)
15991603
letdenv= denv.AddAccessibility tycon.Accessibility
@@ -1746,7 +1750,7 @@ module private TastDefinitionPrinting =
17461750
addMembersAsWithEnd(lhsL^^ WordL.equals)
17471751
| Some a->
17481752
(lhsL^^ WordL.equals)---(layoutType{ denvwith shortTypeNames=false} a)
1749-
layoutAttribs denv tycon.TypeOrMeasureKind tycon.Attribs reprL
1753+
layoutAttribs denvtytycon.TypeOrMeasureKind tycon.Attribs reprL
17501754

17511755
// Layout: exception definition
17521756
letlayoutExnDefn denv(exnc:Entity)=
@@ -1773,7 +1777,7 @@ module private TastDefinitionPrinting =
17731777
|[]-> emptyL
17741778
|[h]when h.IsExceptionDecl-> layoutExnDefn denv h
17751779
| h:: t->
1776-
letx= layoutTycon denv infoReader ad mfalse(WordL.keywordType) h
1780+
letx= layoutTycon denv infoReader ad mfalse WordL.keywordType h
17771781
letxs= List.map(layoutTycon denv infoReader ad mfalse(wordL(tagKeyword"and"))) t
17781782
aboveListL(x::xs)
17791783

@@ -1929,8 +1933,8 @@ let layoutILTypeRef denv x = x |> PrintIL.layoutILTypeRef denv
19291933
letoutputExnDef denv os x= x|> TastDefinitionPrinting.layoutExnDefn denv|> bufferL os
19301934
letlayoutExnDef denv x= x|> TastDefinitionPrinting.layoutExnDefn denv
19311935
letstringOfTyparConstraints denv x= x|> PrintTypes.layoutConstraintsWithInfo denv SimplifyTypes.typeSimplificationInfo0|> showL
1932-
letoutputTycon denv infoReader ad m(* width*)os x= TastDefinitionPrinting.layoutTycon denv infoReader ad mtrue(WordL.keywordType) x(* |> Layout.squashTo width*)|> bufferL os
1933-
letlayoutTycon denv infoReader ad m(* width*)x= TastDefinitionPrinting.layoutTycon denv infoReader ad mtrue(wordL(tagKeyword"type")) x(* |> Layout.squashTo width*)
1936+
letoutputTycon denv infoReader ad m(* width*)os x= TastDefinitionPrinting.layoutTycon denv infoReader ad mtrue WordL.keywordType x(* |> Layout.squashTo width*)|> bufferL os
1937+
letlayoutTycon denv infoReader ad m(* width*)x= TastDefinitionPrinting.layoutTycon denv infoReader ad mtrueWordL.keywordType x(* |> Layout.squashTo width*)
19341938
letlayoutUnionCases denv x= x|> TastDefinitionPrinting.layoutUnionCaseFields denvtrue
19351939
letoutputUnionCases denv os x= x|> TastDefinitionPrinting.layoutUnionCaseFields denvtrue|> bufferL os
19361940
/// Pass negative number as pos in case of single cased discriminated unions

‎src/fsharp/TastOps.fs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,8 +1596,11 @@ let isStructOrEnumTyconTy g ty =
15961596
| Some tcref-> tcref.Deref.IsStructOrEnumTycon
15971597
|_->false
15981598

1599+
letisStructRecordOrUnionTyconTy g ty= isAppTy g ty&&(tyconOfAppTy g ty).IsStructRecordOrUnionTycon
1600+
15991601
letisStructTy g ty= isStructOrEnumTyconTy g ty|| isStructTupleTy g ty
16001602

1603+
16011604
letisRefTy g ty=
16021605
not(isStructOrEnumTyconTy g ty)&&
16031606
(

‎src/fsharp/TastOps.fsi‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,17 +1014,18 @@ val rankOfArrayTy : TcGlobals -> TType -> int
10141014

10151015
valisInterfaceTyconRef:TyconRef->bool
10161016

1017-
valisDelegateTy:TcGlobals->TType->bool
1018-
valisInterfaceTy:TcGlobals->TType->bool
1019-
valisRefTy:TcGlobals->TType->bool
1020-
valisSealedTy:TcGlobals->TType->bool
1021-
valisComInteropTy:TcGlobals->TType->bool
1022-
valunderlyingTypeOfEnumTy:TcGlobals->TType->TType
1023-
valnormalizeEnumTy:TcGlobals->TType->TType
1024-
valisStructTy:TcGlobals->TType->bool
1025-
valisUnmanagedTy:TcGlobals->TType->bool
1026-
valisClassTy:TcGlobals->TType->bool
1027-
valisEnumTy:TcGlobals->TType->bool
1017+
valisDelegateTy:TcGlobals->TType->bool
1018+
valisInterfaceTy:TcGlobals->TType->bool
1019+
valisRefTy:TcGlobals->TType->bool
1020+
valisSealedTy:TcGlobals->TType->bool
1021+
valisComInteropTy:TcGlobals->TType->bool
1022+
valunderlyingTypeOfEnumTy:TcGlobals->TType->TType
1023+
valnormalizeEnumTy:TcGlobals->TType->TType
1024+
valisStructTy:TcGlobals->TType->bool
1025+
valisUnmanagedTy:TcGlobals->TType->bool
1026+
valisClassTy:TcGlobals->TType->bool
1027+
valisEnumTy:TcGlobals->TType->bool
1028+
valisStructRecordOrUnionTyconTy:TcGlobals->TType->bool
10281029

10291030
/// For "type Class as self", 'self' is fixed up after initialization. To support this,
10301031
/// it is converted behind the scenes to a ref. This function strips off the ref and

‎tests/fsharpqa/Source/Printing/BindingsWithValues01.fsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Bldg = House | Museum | Office
3232
leta=1// int - val a : int = 1
3333
letB="Hello"// reference type - val B : string = "Hello"
3434

35-
letc'={ Name="F#"}// record - val c' : RecT = {Name = "F#";}
35+
letc'={ Name="F#"}// record - val c' : RecT = {Name = "F#"}
3636

3737
let_d= Office// disc unioin - val _d : Bldg = Office
3838

@@ -49,7 +49,7 @@ let getPointF (x, y) = System.Drawing.PointF(x, y)
4949

5050
leth= getPointF(1.5f,-1.5f)// PointF structure - val h : System.Drawing.PointF = {X=1.5, Y=-1.5}
5151

52-
leti=(1, c',_d)// tuple - val i : int * RecT * Bldg = (1, {Name = "F#";}, Office)
52+
leti=(1, c',_d)// tuple - val i : int * RecT * Bldg = (1, {Name = "F#"}, Office)
5353

5454
letJ_=[|1;2;3;|]// array - val J_ : int array = [|1; 2; 3|]
5555
letj_'= Array.create21.0// another array - val j_' : float array = [|1.0; 1.0|]

‎vsintegration/src/FSharp.Editor/Common/CommonRoslynHelpers.fs‎

Lines changed: 89 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -147,73 +147,103 @@ module internal CommonRoslynHelpers =
147147
elif a.IsPrivatethen Private
148148
else Protected
149149

150-
letGetGlyphForSymbol(symbol:FSharpSymbol)=
151-
match symbolwith
152-
|:? FSharpUnionCaseas x->
153-
match x.Accessibilitywith
154-
| Public-> Glyph.EnumPublic
155-
| Internal-> Glyph.EnumInternal
156-
| Protected-> Glyph.EnumProtected
157-
| Private-> Glyph.EnumPrivate
158-
|:? FSharpActivePatternCase-> Glyph.EnumPublic
159-
|:? FSharpFieldas x->
160-
match x.Accessibilitywith
161-
| Public-> Glyph.FieldPublic
162-
| Internal-> Glyph.FieldInternal
163-
| Protected-> Glyph.FieldProtected
164-
| Private-> Glyph.FieldPrivate
165-
|:? FSharpParameter-> Glyph.Parameter
166-
|:? FSharpMemberOrFunctionOrValueas x->
167-
if x.IsExtensionMemberthen
168-
match x.Accessibilitywith
169-
| Public-> Glyph.ExtensionMethodPublic
170-
| Internal-> Glyph.ExtensionMethodInternal
171-
| Protected-> Glyph.ExtensionMethodProtected
172-
| Private-> Glyph.ExtensionMethodPrivate
173-
elif x.IsProperty|| x.IsPropertyGetterMethod|| x.IsPropertySetterMethodthen
174-
match x.Accessibilitywith
175-
| Public-> Glyph.PropertyPublic
176-
| Internal-> Glyph.PropertyInternal
177-
| Protected-> Glyph.PropertyProtected
178-
| Private-> Glyph.PropertyPrivate
179-
elif x.IsEventthen
180-
match x.Accessibilitywith
181-
| Public-> Glyph.EventPublic
182-
| Internal-> Glyph.EventInternal
183-
| Protected-> Glyph.EventProtected
184-
| Private-> Glyph.EventPrivate
185-
else
186-
match x.Accessibilitywith
187-
| Public-> Glyph.MethodPublic
188-
| Internal-> Glyph.MethodInternal
189-
| Protected-> Glyph.MethodProtected
190-
| Private-> Glyph.MethodPrivate
191-
|:? FSharpEntityas x->
192-
if x.IsFSharpModulethen
193-
match x.Accessibilitywith
194-
| Public-> Glyph.ModulePublic
195-
| Internal-> Glyph.ModuleInternal
196-
| Protected-> Glyph.ModuleProtected
197-
| Private-> Glyph.ModulePrivate
198-
elif x.IsEnum|| x.IsFSharpUnionthen
150+
letGetGlyphForSymbol(symbol:FSharpSymbol,kind:LexerSymbolKind)=
151+
match kindwith
152+
| LexerSymbolKind.Operator-> Glyph.Operator
153+
|_->
154+
match symbolwith
155+
|:? FSharpUnionCaseas x->
199156
match x.Accessibilitywith
200157
| Public-> Glyph.EnumPublic
201158
| Internal-> Glyph.EnumInternal
202159
| Protected-> Glyph.EnumProtected
203160
| Private-> Glyph.EnumPrivate
204-
elif x.IsInterfacethen
161+
|:? FSharpActivePatternCase-> Glyph.EnumPublic
162+
|:? FSharpFieldas x->
163+
if x.IsLiteralthen
205164
match x.Accessibilitywith
206-
| Public-> Glyph.InterfacePublic
207-
| Internal-> Glyph.InterfaceInternal
208-
| Protected-> Glyph.InterfaceProtected
209-
| Private-> Glyph.InterfacePrivate
165+
| Public-> Glyph.ConstantPublic
166+
| Internal-> Glyph.ConstantInternal
167+
| Protected-> Glyph.ConstantProtected
168+
| Private-> Glyph.ConstantPrivate
210169
else
211170
match x.Accessibilitywith
212-
| Public-> Glyph.ClassPublic
213-
| Internal-> Glyph.ClassInternal
214-
| Protected-> Glyph.ClassProtected
215-
| Private-> Glyph.ClassPrivate
216-
|_-> Glyph.None
171+
| Public-> Glyph.FieldPublic
172+
| Internal-> Glyph.FieldInternal
173+
| Protected-> Glyph.FieldProtected
174+
| Private-> Glyph.FieldPrivate
175+
|:? FSharpParameter-> Glyph.Parameter
176+
|:? FSharpMemberOrFunctionOrValueas x->
177+
if x.LiteralValue.IsSomethen
178+
match x.Accessibilitywith
179+
| Public-> Glyph.ConstantPublic
180+
| Internal-> Glyph.ConstantInternal
181+
| Protected-> Glyph.ConstantProtected
182+
| Private-> Glyph.ConstantPrivate
183+
elif x.IsExtensionMemberthen
184+
match x.Accessibilitywith
185+
| Public-> Glyph.ExtensionMethodPublic
186+
| Internal-> Glyph.ExtensionMethodInternal
187+
| Protected-> Glyph.ExtensionMethodProtected
188+
| Private-> Glyph.ExtensionMethodPrivate
189+
elif x.IsProperty|| x.IsPropertyGetterMethod|| x.IsPropertySetterMethodthen
190+
match x.Accessibilitywith
191+
| Public-> Glyph.PropertyPublic
192+
| Internal-> Glyph.PropertyInternal
193+
| Protected-> Glyph.PropertyProtected
194+
| Private-> Glyph.PropertyPrivate
195+
elif x.IsEventthen
196+
match x.Accessibilitywith
197+
| Public-> Glyph.EventPublic
198+
| Internal-> Glyph.EventInternal
199+
| Protected-> Glyph.EventProtected
200+
| Private-> Glyph.EventPrivate
201+
else
202+
match x.Accessibilitywith
203+
| Public-> Glyph.MethodPublic
204+
| Internal-> Glyph.MethodInternal
205+
| Protected-> Glyph.MethodProtected
206+
| Private-> Glyph.MethodPrivate
207+
|:? FSharpEntityas x->
208+
if x.IsValueTypethen
209+
match x.Accessibilitywith
210+
| Public-> Glyph.StructurePublic
211+
| Internal-> Glyph.StructureInternal
212+
| Protected-> Glyph.StructureProtected
213+
| Private-> Glyph.StructurePrivate
214+
elif x.IsFSharpModulethen
215+
match x.Accessibilitywith
216+
| Public-> Glyph.ModulePublic
217+
| Internal-> Glyph.ModuleInternal
218+
| Protected-> Glyph.ModuleProtected
219+
| Private-> Glyph.ModulePrivate
220+
elif x.IsEnum|| x.IsFSharpUnionthen
221+
match x.Accessibilitywith
222+
| Public-> Glyph.EnumPublic
223+
| Internal-> Glyph.EnumInternal
224+
| Protected-> Glyph.EnumProtected
225+
| Private-> Glyph.EnumPrivate
226+
elif x.IsInterfacethen
227+
match x.Accessibilitywith
228+
| Public-> Glyph.InterfacePublic
229+
| Internal-> Glyph.InterfaceInternal
230+
| Protected-> Glyph.InterfaceProtected
231+
| Private-> Glyph.InterfacePrivate
232+
elif x.IsDelegatethen
233+
match x.Accessibilitywith
234+
| Public-> Glyph.DelegatePublic
235+
| Internal-> Glyph.DelegateInternal
236+
| Protected-> Glyph.DelegateProtected
237+
| Private-> Glyph.DelegatePrivate
238+
elif x.IsNamespacethen
239+
Glyph.Namespace
240+
else
241+
match x.Accessibilitywith
242+
| Public-> Glyph.ClassPublic
243+
| Internal-> Glyph.ClassInternal
244+
| Protected-> Glyph.ClassProtected
245+
| Private-> Glyph.ClassPrivate
246+
|_-> Glyph.None
217247

218248
letRangeToLocation(r:range,sourceText:SourceText,filePath:string):Location=
219249
letlinePositionSpan= LinePositionSpan(LinePosition(Line.toZ r.StartLine, r.StartColumn), LinePosition(Line.toZ r.EndLine, r.EndColumn))

‎vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
<CompileInclude="Common\AssemblyInfo.fs" />
3434
<CompileInclude="Common\Pervasive.fs" />
3535
<CompileInclude="Common\CommonConstants.fs" />
36-
<CompileInclude="Common\CommonRoslynHelpers.fs" />
3736
<CompileInclude="Common\Logging.fs" />
3837
<CompileInclude="Common\CommonHelpers.fs" />
38+
<CompileInclude="Common\CommonRoslynHelpers.fs" />
3939
<CompileInclude="Common\ContentType.fs" />
4040
<CompileInclude="Common\LanguageService.fs" />
4141
<CompileInclude="Common\SymbolHelpers.fs" />

‎vsintegration/src/FSharp.Editor/Navigation/FindUsagesService.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type internal FSharpFindUsagesService
5757
let!symbol= CommonHelpers.getSymbolAtPosition(document.Id, sourceText, position, document.FilePath, defines, SymbolLookupKind.Greedy)
5858
let!symbolUse= checkFileResults.GetSymbolUseAtLocation(lineNumber, symbol.Ident.idRange.EndColumn, textLine, symbol.FullIsland)
5959
let!declaration= checkFileResults.GetDeclarationLocationAlternate(lineNumber, symbol.Ident.idRange.EndColumn, textLine, symbol.FullIsland,false)|> liftAsync
60-
lettags= GlyphTags.GetTags(CommonRoslynHelpers.GetGlyphForSymbol symbolUse.Symbol)
60+
lettags= GlyphTags.GetTags(CommonRoslynHelpers.GetGlyphForSymbol(symbolUse.Symbol, symbol.Kind))
6161

6262
letdeclarationRange=
6363
match declarationwith

‎vsintegration/src/FSharp.Editor/QuickInfo/QuickInfoProvider.fs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type internal FSharpQuickInfoProvider
4747
| FSharpToolTipText[FSharpStructuredToolTipElement.None]->return! None
4848
|_->
4949
let!symbolUse= checkFileResults.GetSymbolUseAtLocation(textLineNumber, symbol.Ident.idRange.EndColumn, textLine.ToString(), symbol.FullIsland)
50-
return! Some(res, CommonRoslynHelpers.FSharpRangeToTextSpan(sourceText, symbol.Range), symbolUse.Symbol)
50+
return! Some(res, CommonRoslynHelpers.FSharpRangeToTextSpan(sourceText, symbol.Range), symbolUse.Symbol, symbol.Kind)
5151
}
5252

5353
interface IQuickInfoProviderwith
@@ -58,7 +58,7 @@ type internal FSharpQuickInfoProvider
5858
let!_= CommonHelpers.getSymbolAtPosition(document.Id, sourceText, position, document.FilePath, defines, SymbolLookupKind.Precise)
5959
let!options= projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document)
6060
let!textVersion= document.GetTextVersionAsync(cancellationToken)
61-
let!toolTipElement,textSpan,symbol=
61+
let!toolTipElement,textSpan,symbol,symbolKind=
6262
FSharpQuickInfoProvider.ProvideQuickInfo(checkerProvider.Checker, document.Id, sourceText, document.FilePath, position, options, textVersion.GetHashCode())
6363
letmainDescription= Collections.Generic.List()
6464
letdocumentation= Collections.Generic.List()
@@ -71,7 +71,7 @@ type internal FSharpQuickInfoProvider
7171
letcontent=
7272
QuickInfoDisplayDeferredContent
7373
(
74-
symbolGlyph= SymbolGlyphDeferredContent(CommonRoslynHelpers.GetGlyphForSymbol(symbol), glyphService),
74+
symbolGlyph= SymbolGlyphDeferredContent(CommonRoslynHelpers.GetGlyphForSymbol(symbol, symbolKind), glyphService),
7575
warningGlyph=null,
7676
mainDescription= ClassifiableDeferredContent(mainDescription, typeMap),
7777
documentation= ClassifiableDeferredContent(documentation, typeMap),

‎vsintegration/src/FSharp.LanguageService.Base/Interfaces.cs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
namespaceMicrosoft.VisualStudio.FSharp.LanguageService
2424
{
25-
2625
enumRequireFreshResults
2726
{
2827
Yes=1,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp