Skip to content

Commit b3f6501

Browse files
dungpaKevinRansom
authored andcommitted
Color built-in types as keywords in signature help and quick info (dotnet#2162)
1 parent 43dc891 commit b3f6501

File tree

6 files changed

+40
-34
lines changed

6 files changed

+40
-34
lines changed

src/fsharp/TastOps.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2517,7 +2517,8 @@ let fullNameOfEntityRef nmF xref =
25172517
| Some pathText -> pathText +.+ nmF xref
25182518

25192519
let tagEntityRefName (xref: EntityRef) name =
2520-
if xref.IsNamespace then tagNamespace name
2520+
if Set.contains name Lexhelp.Keywords.keywordTypes then tagKeyword name
2521+
else if xref.IsNamespace then tagNamespace name
25212522
else if xref.IsModule then tagModule name
25222523
else if xref.IsTypeAbbrev then tagAlias name
25232524
else if xref.IsFSharpDelegateTycon then tagDelegate name

src/fsharp/lexhelp.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ module Keywords =
298298
let keywordNames =
299299
keywordList |> List.map (fun (_, w, _) -> w)
300300

301+
let keywordTypes = StructuredFormat.TaggedTextOps.keywordTypes
302+
301303
let keywordTable =
302304
let tab = System.Collections.Generic.Dictionary<string,token>(100)
303305
for _,keyword,token in keywordList do

src/fsharp/lexhelp.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ module Keywords =
6868
val IdentifierToken : lexargs -> UnicodeLexing.Lexbuf -> string -> Parser.token
6969
val QuoteIdentifierIfNeeded : string -> string
7070
val keywordNames : string list
71+
val keywordTypes : Set<string>

src/fsharp/vs/service.fs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,36 +1112,7 @@ type TypeCheckInfo
11121112
else
11131113
items
11141114

1115-
let keywordTypes =
1116-
[
1117-
"array";
1118-
"bigint";
1119-
"bool";
1120-
"byref";
1121-
"byte";
1122-
"char";
1123-
"decimal";
1124-
"double";
1125-
"float";
1126-
"float32";
1127-
"int";
1128-
"int16";
1129-
"int32";
1130-
"int64";
1131-
"list";
1132-
"nativeint";
1133-
"obj";
1134-
"sbyte";
1135-
"seq";
1136-
"single";
1137-
"string";
1138-
"unit";
1139-
"uint";
1140-
"uint16";
1141-
"uint32";
1142-
"uint64";
1143-
"unativeint"
1144-
] |> Set.ofSeq
1115+
static let keywordTypes = Lexhelp.Keywords.keywordTypes
11451116

11461117
/// Get the auto-complete items at a location
11471118
member x.GetDeclarations (parseResultsOpt, line, lineStr, colAtEndOfNamesAndResidue, qualifyingNames, partialName, hasTextChangedSinceLastTypecheck) =

src/utils/sformat.fs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,37 @@ namespace Microsoft.FSharp.Text.StructuredFormat
194194
module TaggedTextOps =
195195
#endif
196196
let tagAlias = TaggedText.Alias
197-
let tagClass = TaggedText.Class
197+
let keywordTypes =
198+
[
199+
"array";
200+
"bigint";
201+
"bool";
202+
"byref";
203+
"byte";
204+
"char";
205+
"decimal";
206+
"double";
207+
"float";
208+
"float32";
209+
"int";
210+
"int16";
211+
"int32";
212+
"int64";
213+
"list";
214+
"nativeint";
215+
"obj";
216+
"sbyte";
217+
"seq";
218+
"single";
219+
"string";
220+
"unit";
221+
"uint";
222+
"uint16";
223+
"uint32";
224+
"uint64";
225+
"unativeint";
226+
] |> Set.ofList
227+
let tagClass name = if Set.contains name keywordTypes then TaggedText.Keyword name else TaggedText.Class name
198228
let tagUnionCase = TaggedText.UnionCase
199229
let tagDelegate = TaggedText.Delegate
200230
let tagEnum = TaggedText.Enum
@@ -216,7 +246,7 @@ namespace Microsoft.FSharp.Text.StructuredFormat
216246
let tagProperty = TaggedText.Property
217247
let tagSpace = TaggedText.Space
218248
let tagStringLiteral = TaggedText.StringLiteral
219-
let tagStruct = TaggedText.Struct
249+
let tagStruct name = if Set.contains name keywordTypes then TaggedText.Keyword name else TaggedText.Struct name
220250
let tagTypeParameter = TaggedText.TypeParameter
221251
let tagText = TaggedText.Text
222252
let tagPunctuation = TaggedText.Punctuation
@@ -1390,5 +1420,5 @@ namespace Microsoft.FSharp.Text.StructuredFormat
13901420

13911421
#if COMPILER
13921422
/// Called
1393-
let fsi_any_to_layout opts x = anyL ShowTopLevelBinding BindingFlags.Public opts x
1423+
let fsi_any_to_layout opts x = anyL ShowTopLevelBinding BindingFlags.Public opts x
13941424
#endif

src/utils/sformat.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ namespace Microsoft.FSharp.Text.StructuredFormat
126126
#else
127127
#endif
128128
TaggedTextOps =
129+
val keywordTypes : Set<string>
129130
val tagAlias : string -> TaggedText
130131
val tagClass : string -> TaggedText
131132
val tagUnionCase : string -> TaggedText

0 commit comments

Comments
 (0)