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

Commit4b945e7

Browse files
authored
Merge pull requestdotnet#2452 from cloudRoutine/colorization
Colorize Type Arguments and Punctuation
2 parents29e66ee +1ed1bb5 commit4b945e7

File tree

19 files changed

+104
-57
lines changed

19 files changed

+104
-57
lines changed

‎src/fsharp/PrettyNaming.fs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,19 @@ module internal Microsoft.FSharp.Compiler.PrettyNaming
386386
// by the call to String.forall; it is a fast check used to avoid the call if possible.
387387
||(s.[0]='~'&& String.forall(fun c-> c='~') s)
388388

389+
letIsPunctuation s=
390+
if System.String.IsNullOrEmpty sthenfalseelse
391+
match swith
392+
|","|";"|"|"|":"|"."|"*"
393+
|"("|")"
394+
|"["|"]"
395+
|"{"|"}"
396+
|"<"|">"
397+
|"[|"|"|]"
398+
|"[<"|">]"
399+
->true
400+
|_->false
401+
389402
letIsTernaryOperator s=
390403
(DecompileOpName s= qmarkSet)
391404

‎src/fsharp/TastOps.fs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2501,8 +2501,7 @@ let fullNameOfEntityRef nmF xref =
25012501
| Some pathText-> pathText+.+ nmF xref
25022502

25032503
lettagEntityRefName(xref:EntityRef)name=
2504-
if Set.contains name Lexhelp.Keywords.keywordTypesthen tagKeyword name
2505-
elif xref.IsNamespacethen tagNamespace name
2504+
if xref.IsNamespacethen tagNamespace name
25062505
elif xref.IsModulethen tagModule name
25072506
elif xref.IsTypeAbbrevthen tagAlias name
25082507
elif xref.IsFSharpDelegateTyconthen tagDelegate name

‎src/fsharp/TcGlobals.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,7 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
942942
member valtcref_System_IComparable= findSysTyconRef sys"IComparable"
943943
member valtcref_System_IStructuralComparable= findSysTyconRef sysCollections"IStructuralComparable"
944944
member valtcref_System_IStructuralEquatable= findSysTyconRef sysCollections"IStructuralEquatable"
945+
member valtcref_System_IDisposable= findSysTyconRef sys"IDisposable"
945946

946947
member valtcref_LanguagePrimitives= mk_MFCore_tcref fslibCcu"LanguagePrimitives"
947948

‎src/fsharp/lexhelp.fs‎

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

301-
letkeywordTypes= StructuredFormat.TaggedTextOps.keywordTypes
302-
303301
letkeywordTable=
304302
lettab= System.Collections.Generic.Dictionary<string,token>(100)
305303
for_,keyword,tokenin keywordListdo

‎src/fsharp/lexhelp.fsi‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,5 @@ module Keywords =
7070
valQuoteIdentifierIfNeeded:string->string
7171
valNormalizeIdentifierBackticks:string->string
7272
valkeywordNames:string list
73-
valkeywordTypes:Set<string>
7473
/// Keywords paired with their descriptions. Used in completion and quick info.
7574
valkeywordsWithDescription:(string* string)list

‎src/fsharp/vs/ServiceLexing.fs‎

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ module FSharpTokenTag =
6868
letCOLON_EQUALS= tagOfToken COLON_EQUALS
6969
letBAR_BAR= tagOfToken BAR_BAR
7070
letRARROW= tagOfToken RARROW
71+
letLARROW= tagOfToken LARROW
7172
letQUOTE= tagOfToken QUOTE
7273

7374

@@ -88,14 +89,15 @@ type FSharpTokenColorKind =
8889
| PreprocessorKeyword=8
8990
| Number=9
9091
| Operator=10
92+
| Punctuation=11
9193

9294
/// Categorize an action the editor should take in response to a token, e.g. brace matching
9395
///
9496
/// NOTE: This corresponds to a token categorization originally used in Visual Studio 2003 and the original Babel source code.
9597
/// It is not clear it is a primary logical classification that should be being used in the
9698
/// more recent language service work.
9799
typeFSharpTokenTriggerClass=
98-
None=0x00000000
100+
| None=0x00000000
99101
| MemberSelect=0x00000001
100102
| MatchBraces=0x00000002
101103
| ChoiceSelect=0x00000004
@@ -111,7 +113,7 @@ type FSharpTokenTriggerClass =
111113
/// It is not clear it is a primary logical classification that should be being used in the
112114
/// more recent language service work.
113115
typeFSharpTokenCharKind=
114-
Default=0x00000000
116+
| Default=0x00000000
115117
| Text=0x00000000
116118
| Keyword=0x00000001
117119
| Identifier=0x00000002
@@ -126,13 +128,13 @@ type FSharpTokenCharKind =
126128

127129
/// Information about a particular token from the tokenizer
128130
typeFSharpTokenInfo={
129-
LeftColumn:int;
130-
RightColumn:int;
131-
ColorClass:FSharpTokenColorKind;
132-
CharClass:FSharpTokenCharKind;
133-
FSharpTokenTriggerClass:FSharpTokenTriggerClass;
131+
LeftColumn:int
132+
RightColumn:int
133+
ColorClass:FSharpTokenColorKind
134+
CharClass:FSharpTokenCharKind
135+
FSharpTokenTriggerClass:FSharpTokenTriggerClass
134136
Tag:int
135-
TokenName:string;
137+
TokenName:string
136138
FullMatchedLength:int}
137139

138140
//----------------------------------------------------------------------------
@@ -161,7 +163,7 @@ module internal TokenClassifications =
161163

162164
// 'in' when used in a 'join' in a query expression
163165
| JOIN_IN->
164-
(FSharpTokenColorKind.Identifier,FSharpTokenCharKind.Identifier,FSharpTokenTriggerClass.None)
166+
(FSharpTokenColorKind.Identifier,FSharpTokenCharKind.Identifier,FSharpTokenTriggerClass.None)
165167
| DECIMAL_
166168
| BIGNUM_| INT8_| UINT8_| INT16_| UINT16_| INT32_| UINT32_| INT64_| UINT64_
167169
| UNATIVEINT_| NATIVEINT_| IEEE32_| IEEE64_
@@ -180,14 +182,14 @@ module internal TokenClassifications =
180182
| DOLLAR| COLON_GREATER| COLON_COLON
181183
| PERCENT_OP_| PLUS_MINUS_OP_| PREFIX_OP_| COLON_QMARK_GREATER
182184
| AMP| AMP_AMP| BAR_BAR| QMARK| QMARK_QMARK| COLON_QMARK
183-
|QUOTE| STAR|HIGH_PRECEDENCE_TYAPP
184-
|COLON|COLON_EQUALS| LARROW| EQUALS| RQUOTE_DOT_
185+
| HIGH_PRECEDENCE_TYAPP
186+
| COLON_EQUALS| EQUALS| RQUOTE_DOT_
185187
| MINUS| ADJACENT_PREFIX_OP_
186188
->(FSharpTokenColorKind.Operator,FSharpTokenCharKind.Operator,FSharpTokenTriggerClass.None)
187-
189+
188190
| INFIX_COMPARE_OP_// This is a whole family: .< .> .= .!= .$
189191
| FUNKY_OPERATOR_NAME_// This is another whole family, including: .[] and .()
190-
| INFIX_AT_HAT_OP_
192+
//| INFIX_AT_HAT_OP _
191193
| INFIX_STAR_STAR_OP_
192194
| INFIX_AMP_OP_
193195
| INFIX_BAR_OP_
@@ -200,48 +202,51 @@ module internal TokenClassifications =
200202
(FSharpTokenColorKind.Operator,FSharpTokenCharKind.Operator,FSharpTokenTriggerClass.MemberSelect)
201203

202204
| COMMA
203-
->(FSharpTokenColorKind.Text,FSharpTokenCharKind.Delimiter,FSharpTokenTriggerClass.ParamNext)
205+
->(FSharpTokenColorKind.Punctuation,FSharpTokenCharKind.Delimiter,FSharpTokenTriggerClass.ParamNext)
204206

205207
| DOT
206-
->(FSharpTokenColorKind.Operator,FSharpTokenCharKind.Delimiter,FSharpTokenTriggerClass.MemberSelect)
208+
->(FSharpTokenColorKind.Punctuation,FSharpTokenCharKind.Delimiter,FSharpTokenTriggerClass.MemberSelect)
207209

208210
| BAR
209-
->(FSharpTokenColorKind.Text,FSharpTokenCharKind.Delimiter,FSharpTokenTriggerClass.None(* FSharpTokenTriggerClass.ChoiceSelect*))
210-
211-
| HASH| UNDERSCORE
212-
| SEMICOLON| SEMICOLON_SEMICOLON
213-
->(FSharpTokenColorKind.Text,FSharpTokenCharKind.Delimiter,FSharpTokenTriggerClass.None)
211+
->(FSharpTokenColorKind.Punctuation,FSharpTokenCharKind.Delimiter,FSharpTokenTriggerClass.None(* FSharpTokenTriggerClass.ChoiceSelect*))
212+
213+
| HASH| STAR| SEMICOLON| SEMICOLON_SEMICOLON| COLON
214+
->(FSharpTokenColorKind.Punctuation,FSharpTokenCharKind.Delimiter,FSharpTokenTriggerClass.None)
215+
216+
| QUOTE| UNDERSCORE
217+
| INFIX_AT_HAT_OP_
218+
->(FSharpTokenColorKind.Identifier,FSharpTokenCharKind.Identifier,FSharpTokenTriggerClass.None)
214219

215220
| LESS_
216-
->(FSharpTokenColorKind.Operator,FSharpTokenCharKind.Operator,FSharpTokenTriggerClass.ParamStart)// for type provider static arguments
221+
->(FSharpTokenColorKind.Punctuation,FSharpTokenCharKind.Operator,FSharpTokenTriggerClass.ParamStart)// for type provider static arguments
217222
| GREATER_
218-
->(FSharpTokenColorKind.Operator,FSharpTokenCharKind.Operator,FSharpTokenTriggerClass.ParamEnd)// for type provider static arguments
223+
->(FSharpTokenColorKind.Punctuation,FSharpTokenCharKind.Operator,FSharpTokenTriggerClass.ParamEnd)// for type provider static arguments
219224

220225
| LPAREN
221226
// We need 'ParamStart' to trigger the 'GetDeclarations' method to show param info automatically
222227
// this is needed even if we don't use MPF for determining information about params
223-
->(FSharpTokenColorKind.Text,FSharpTokenCharKind.Delimiter, FSharpTokenTriggerClass.ParamStart||| FSharpTokenTriggerClass.MatchBraces)
228+
->(FSharpTokenColorKind.Punctuation,FSharpTokenCharKind.Delimiter, FSharpTokenTriggerClass.ParamStart||| FSharpTokenTriggerClass.MatchBraces)
224229

225230
| RPAREN| RPAREN_COMING_SOON| RPAREN_IS_HERE
226-
->(FSharpTokenColorKind.Text,FSharpTokenCharKind.Delimiter, FSharpTokenTriggerClass.ParamEnd||| FSharpTokenTriggerClass.MatchBraces)
231+
->(FSharpTokenColorKind.Punctuation,FSharpTokenCharKind.Delimiter, FSharpTokenTriggerClass.ParamEnd||| FSharpTokenTriggerClass.MatchBraces)
227232

228233
| LBRACK_LESS| LBRACE_LESS
229-
->(FSharpTokenColorKind.Text,FSharpTokenCharKind.Delimiter,FSharpTokenTriggerClass.None)
234+
->(FSharpTokenColorKind.Punctuation,FSharpTokenCharKind.Delimiter,FSharpTokenTriggerClass.None)
230235

231236
| LQUOTE_| LBRACK| LBRACE| LBRACK_BAR
232-
->(FSharpTokenColorKind.Text,FSharpTokenCharKind.Delimiter,FSharpTokenTriggerClass.MatchBraces)
237+
->(FSharpTokenColorKind.Punctuation,FSharpTokenCharKind.Delimiter,FSharpTokenTriggerClass.MatchBraces)
233238

234239
| GREATER_RBRACE| GREATER_RBRACK| GREATER_BAR_RBRACK
235-
->(FSharpTokenColorKind.Text,FSharpTokenCharKind.Delimiter,FSharpTokenTriggerClass.None)
240+
->(FSharpTokenColorKind.Punctuation,FSharpTokenCharKind.Delimiter,FSharpTokenTriggerClass.None)
236241

237242
| RQUOTE_| RBRACK| RBRACE| RBRACE_COMING_SOON| RBRACE_IS_HERE| BAR_RBRACK
238-
->(FSharpTokenColorKind.Text,FSharpTokenCharKind.Delimiter,FSharpTokenTriggerClass.MatchBraces)
243+
->(FSharpTokenColorKind.Punctuation,FSharpTokenCharKind.Delimiter,FSharpTokenTriggerClass.MatchBraces)
239244

240245
| PUBLIC| PRIVATE| INTERNAL| BASE| GLOBAL
241246
| CONSTRAINT| INSTANCE| DELEGATE| INHERIT|CONSTRUCTOR|DEFAULT|OVERRIDE|ABSTRACT|CLASS
242247
| MEMBER| STATIC| NAMESPACE
243248
| OASSERT| OLAZY| ODECLEND| OBLOCKSEP| OEND| OBLOCKBEGIN| ORIGHT_BLOCK_END| OBLOCKEND| OBLOCKEND_COMING_SOON| OBLOCKEND_IS_HERE| OTHEN| OELSE| OLET(_)| OBINDER_| BINDER_| ODO| OWITH| OFUNCTION| OFUN| ORESET| ODUMMY_| DO_BANG| ODO_BANG| YIELD_| YIELD_BANG_| OINTERFACE_MEMBER
244-
| ELIF| RARROW| SIG| STRUCT
249+
| ELIF| RARROW|LARROW|SIG| STRUCT
245250
| UPCAST| DOWNCAST| NULL| RESERVED| MODULE| AND| AS| ASSERT| ASR
246251
| DOWNTO| EXCEPTION| FALSE| FOR| FUN| FUNCTION
247252
| FINALLY| LAZY| MATCH| MUTABLE| NEW| OF| OPEN| OR| VOID| EXTERN

‎src/fsharp/vs/ServiceLexing.fsi‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type internal FSharpTokenColorKind =
5252
| PreprocessorKeyword=8
5353
| Number=9
5454
| Operator=10
55+
| Punctuation=11
5556

5657
/// Gives an indication of what should happen when the token is typed in an IDE
5758
typeinternalFSharpTokenTriggerClass=
@@ -166,6 +167,8 @@ module internal FSharpTokenTag =
166167
valBAR_BAR:int
167168
/// Indicates the token is a `->`
168169
valRARROW:int
170+
/// Indicates the token is a `<-`
171+
valLARROW:int
169172
/// Indicates the token is a `"`
170173
valQUOTE:int
171174

‎src/fsharp/vs/Symbols.fs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,11 @@ and FSharpEntity(cenv:cenv, entity:EntityRef) =
403403
letty= generalizedTyconRef entity
404404
Infos.ExistsHeadTypeInEntireHierarchy cenv.g cenv.amap range0 ty cenv.g.tcref_System_Attribute
405405

406+
memberx.IsDisposableType=
407+
if isUnresolved()thenfalseelse
408+
letty= generalizedTyconRef entity
409+
Infos.ExistsHeadTypeInEntireHierarchy cenv.g cenv.amap range0 ty cenv.g.tcref_System_IDisposable
410+
406411
memberx.BaseType=
407412
checkIsResolved()
408413
GetSuperTypeOfType cenv.g cenv.amap range0(generalizedTyconRef entity)

‎src/fsharp/vs/service.fs‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,12 @@ type SemanticClassificationType =
498498
| Module
499499
| Printf
500500
| ComputationExpression
501-
| IntrinsicType
502501
| IntrinsicFunction
503502
| Enumeration
504503
| Interface
504+
| TypeArgument
505+
| Operator
506+
| Disposable
505507

506508
// A scope represents everything we get back from the typecheck of a file.
507509
// It acts like an in-memory database about the file.
@@ -1140,8 +1142,6 @@ type TypeCheckInfo
11401142
items
11411143

11421144

1143-
static letkeywordTypes= Lexhelp.Keywords.keywordTypes
1144-
11451145
memberx.IsRelativeNameResolvable(cursorPos:pos,plid:string list,item:Item):bool=
11461146
/// Determines if a long ident is resolvable at a specific point.
11471147
ErrorScope.Protect
@@ -1461,6 +1461,9 @@ type TypeCheckInfo
14611461
| None->
14621462
sResolutions.CapturedNameResolutions:> seq<_>
14631463

1464+
letisDisposableTy(ty:TType)=
1465+
Infos.ExistsHeadTypeInEntireHierarchy g amap range0 ty g.tcref_System_IDisposable
1466+
14641467
resolutions
14651468
|> Seq.choose(fun cnr->
14661469
match cnrwith
@@ -1474,19 +1477,16 @@ type TypeCheckInfo
14741477
| CNR(_,(Item.Value vref),_,_,_,_, m)when isFunction g vref.Type->
14751478
if vref.IsPropertyGetterMethod|| vref.IsPropertySetterMethodthen
14761479
Some(m, SemanticClassificationType.Property)
1477-
elifnot(IsOperatorName vref.DisplayName)then
1478-
Some(m, SemanticClassificationType.Function)
1479-
elseNone
1480+
elif IsOperatorName vref.DisplayNamethen
1481+
Some(m, SemanticClassificationType.Operator)
1482+
elseSome(m, SemanticClassificationType.Function)
14801483
| CNR(_, Item.RecdField rfinfo,_,_,_,_, m)when rfinfo.RecdField.IsMutable&& rfinfo.LiteralValue.IsNone->
14811484
Some(m, SemanticClassificationType.MutableVar)
14821485
| CNR(_, Item.MethodGroup(_,_,_),_,_,_,_, m)->
14831486
Some(m, SemanticClassificationType.Function)
14841487
// custom builders, custom operations get colored as keywords
14851488
| CNR(_,(Item.CustomBuilder_| Item.CustomOperation_), ItemOccurence.Use,_,_,_, m)->
14861489
Some(m, SemanticClassificationType.ComputationExpression)
1487-
// well known type aliases get colored as keywords
1488-
| CNR(_,(Item.Types(n,_)),_,_,_,_, m)when keywordTypes.Contains(n)->
1489-
Some(m, SemanticClassificationType.IntrinsicType)
14901490
// types get colored as types when they occur in syntactic types or custom attributes
14911491
// typevariables get colored as types when they occur in syntactic types custom builders, custom operations get colored as keywords
14921492
| CNR(_, Item.Types(_,[OptionalArgumentAttribute]), LegitTypeOccurence,_,_,_,_)-> None
@@ -1495,9 +1495,13 @@ type TypeCheckInfo
14951495
Some(m, SemanticClassificationType.Interface)
14961496
| CNR(_, Item.Types(_, types), LegitTypeOccurence,_,_,_, m)when types|> List.exists(isStructTy g)->
14971497
Some(m, SemanticClassificationType.ValueType)
1498+
| CNR(_, Item.Types(_, types), LegitTypeOccurence,_,_,_, m)when types|> List.exists isDisposableTy->
1499+
Some(m, SemanticClassificationType.Disposable)
14981500
| CNR(_, Item.Types_, LegitTypeOccurence,_,_,_, m)->
14991501
Some(m, SemanticClassificationType.ReferenceType)
1500-
| CNR(_,(Item.TypeVar_| Item.UnqualifiedType_| Item.CtorGroup_), LegitTypeOccurence,_,_,_, m)->
1502+
| CNR(_,(Item.TypeVar_), LegitTypeOccurence,_,_,_, m)->
1503+
Some(m, SemanticClassificationType.TypeArgument)
1504+
| CNR(_,(Item.UnqualifiedType_| Item.CtorGroup_), LegitTypeOccurence,_,_,_, m)->
15011505
Some(m, SemanticClassificationType.ReferenceType)
15021506
| CNR(_, Item.ModuleOrNamespaces refs, LegitTypeOccurence,_,_,_, m)when refs|> List.exists(fun x-> x.IsModule)->
15031507
Some(m, SemanticClassificationType.ReferenceType)

‎src/fsharp/vs/service.fsi‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,12 @@ type internal SemanticClassificationType =
159159
| Module
160160
| Printf
161161
| ComputationExpression
162-
| IntrinsicType
163162
| IntrinsicFunction
164163
| Enumeration
165164
| Interface
165+
| TypeArgument
166+
| Operator
167+
| Disposable
166168

167169
/// A handle to the results of CheckFileInProject.
168170
[<Sealed>]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp