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

Commit4b23b22

Browse files
vasily-kirichenkoKevinRansom
authored andcommitted
Better semantic highlighting (dotnet#2348)
* wip* adjust color when color theme changes* highlight mutable record / struct fields* remove theme changing listener* fix typo in a test* address code review* black color for functions by default* try to fix false range for get, set auto properties
1 parent507ea9e commit4b23b22

File tree

18 files changed

+228
-80
lines changed

18 files changed

+228
-80
lines changed

‎src/fsharp/CheckFormatStrings.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ let parseFormatStringInternal (m:range) (g: TcGlobals) (source: string option) f
201201
specifierLocations.Add(
202202
Range.mkFileIndexRange m.FileIndex
203203
(Range.mkPos m.StartLine(startCol+ offset))
204-
(Range.mkPos m.StartLine(relCol+ offset)))
204+
(Range.mkPos m.StartLine(relCol+ offset+1)))
205205
|_->
206206
specifierLocations.Add(
207207
Range.mkFileIndexRange m.FileIndex
208208
(Range.mkPos(m.StartLine+ relLine) startCol)
209-
(Range.mkPos(m.StartLine+ relLine) relCol))
209+
(Range.mkPos(m.StartLine+ relLine)(relCol+1)))
210210

211211
letch= fmt.[i]
212212
match chwith

‎src/fsharp/TcGlobals.fs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
207207
letv_nativeptr_tcr= mk_MFCore_tcref fslibCcu"nativeptr`1"
208208
letv_ilsigptr_tcr= mk_MFCore_tcref fslibCcu"ilsigptr`1"
209209
letv_fastFunc_tcr= mk_MFCore_tcref fslibCcu"FSharpFunc`2"
210+
letv_refcell_tcr_canon= mk_MFCore_tcref fslibCcu"Ref`1"
211+
letv_refcell_tcr_nice= mk_MFCore_tcref fslibCcu"ref`1"
210212

211213
letdummyAssemblyNameCarryingUsefulErrorInformation path typeName=
212214
FSComp.SR.tcGlobalsSystemTypeNotFound(String.concat"." path+"."+ typeName)
@@ -347,6 +349,7 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
347349
letmk_hash_withc_sig ty=[[v_IEqualityComparer_ty];[ty]], v_int_ty
348350
letmkListTy ty= TType_app(v_list_tcr_nice,[ty])
349351
letmkSeqTy ty1= TType_app(v_seq_tcr,[ty1])
352+
letmkRefCellTy ty= TType_app(v_refcell_tcr_canon,[ty])
350353
letmkQuerySourceTy ty1 ty2= TType_app(v_querySource_tcr,[ty1; ty2])
351354
letv_tcref_System_Collections_IEnumerable= findSysTyconRef sysCollections"IEnumerable";
352355
letmkArrayType rank(ty:TType):TType=
@@ -596,10 +599,11 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
596599
letv_sprintf_info= makeIntrinsicValRef(fslib_MFExtraTopLevelOperators_nleref,"sprintf", None, Some"PrintFormatToStringThen",[vara],([[mk_format4_ty varaTy v_unit_ty v_string_ty v_string_ty]], varaTy))
597600
letv_lazy_force_info=
598601
// Lazy\Value for > 4.0
599-
makeIntrinsicValRef(fslib_MFLazyExtensions_nleref,"Force", Some"Lazy`1", None,[vara],([[mkLazyTy varaTy];[]], varaTy))
602+
makeIntrinsicValRef(fslib_MFLazyExtensions_nleref,"Force", Some"Lazy`1", None,[vara],([[mkLazyTy varaTy];[]], varaTy))
600603
letv_lazy_create_info= makeIntrinsicValRef(fslib_MFLazyExtensions_nleref,"Create", Some"Lazy`1", None,[vara],([[v_unit_ty--> varaTy]], mkLazyTy varaTy))
601604

602605
letv_seq_info= makeIntrinsicValRef(fslib_MFOperators_nleref,"seq", None, Some"CreateSequence",[vara],([[mkSeqTy varaTy]], mkSeqTy varaTy))
606+
letv_refcell_info= makeIntrinsicValRef(fslib_MFCore_nleref,"ref", Some"FSharpRef`1", None,[vara],([[mkRefCellTy varaTy];[]], varaTy))
603607
letv_splice_expr_info= makeIntrinsicValRef(fslib_MFExtraTopLevelOperators_nleref,"op_Splice", None, None,[vara],([[mkQuotedExprTy varaTy]], varaTy))
604608
letv_splice_raw_expr_info= makeIntrinsicValRef(fslib_MFExtraTopLevelOperators_nleref,"op_SpliceUntyped", None, None,[vara],([[mkRawQuotedExprTy]], varaTy))
605609
letv_new_decimal_info= makeIntrinsicValRef(fslib_MFIntrinsicFunctions_nleref,"MakeDecimal", None, None,[],([[v_int_ty];[v_int_ty];[v_int_ty];[v_bool_ty];[v_byte_ty]], v_decimal_ty))
@@ -772,13 +776,13 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
772776
member__.unionCaseRefEq x y= primUnionCaseRefEq compilingFslib fslibCcu x y
773777
member__.valRefEq x y= primValRefEq compilingFslib fslibCcu x y
774778
member__.fslibCcu= fslibCcu
775-
member valrefcell_tcr_canon=mk_MFCore_tcref fslibCcu"Ref`1"
779+
member valrefcell_tcr_canon=v_refcell_tcr_canon
776780
member valoption_tcr_canon= mk_MFCore_tcref fslibCcu"Option`1"
777781
member__.list_tcr_canon= v_list_tcr_canon
778782
member valset_tcr_canon= mk_MFCollections_tcref fslibCcu"Set`1"
779783
member valmap_tcr_canon= mk_MFCollections_tcref fslibCcu"Map`2"
780784
member__.lazy_tcr_canon= lazy_tcr
781-
member valrefcell_tcr_nice=mk_MFCore_tcref fslibCcu"ref`1"
785+
member valrefcell_tcr_nice=v_refcell_tcr_nice
782786
member valarray_tcr_nice= v_il_arr_tcr_map.[0]
783787
member__.option_tcr_nice= v_option_tcr_nice
784788
member__.list_tcr_nice= v_list_tcr_nice
@@ -1050,6 +1054,7 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
10501054
member__.new_decimal_info= v_new_decimal_info
10511055
member__.seq_info= v_seq_info
10521056
member valseq_vref=(ValRefForIntrinsic v_seq_info)
1057+
member valfsharpref_vref=(ValRefForIntrinsic v_refcell_info)
10531058
member valand_vref=(ValRefForIntrinsic v_and_info)
10541059
member valand2_vref=(ValRefForIntrinsic v_and2_info)
10551060
member valaddrof_vref=(ValRefForIntrinsic v_addrof_info)

‎src/fsharp/vs/ServiceDeclarations.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ module internal ItemDescriptionsImpl =
744744
|_->false
745745
with_->false
746746

747-
/// Outputathe description of a language item
747+
/// Output the description of a language item
748748
let recFormatItemDescriptionToToolTipElement isDecl(infoReader:InfoReader)m denv d=
749749
letg= infoReader.g
750750
letamap= infoReader.amap

‎src/fsharp/vs/ServiceLexing.fs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ module FSharpTokenTag =
7676
/// It is not clear it is a primary logical classification that should be being used in the
7777
/// more recent language service work.
7878
typeFSharpTokenColorKind=
79-
Default=0
79+
| Default=0
8080
| Text=0
8181
| Keyword=1
8282
| Comment=2
@@ -87,7 +87,6 @@ type FSharpTokenColorKind =
8787
| PreprocessorKeyword=8
8888
| Number=9
8989
| Operator=10
90-
| TypeName=11
9190

9291
/// Categorize an action the editor should take in response to a token, e.g. brace matching
9392
///

‎src/fsharp/vs/ServiceLexing.fsi‎

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

5756
/// Gives an indication of what should happen when the token is typed in an IDE
5857
typeinternalFSharpTokenTriggerClass=

‎src/fsharp/vs/service.fs‎

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,20 @@ type FSharpSymbolUse(g:TcGlobals, denv: DisplayEnv, symbol:FSharpSymbol, itemOcc
477477
member__.Range= Range.toZ range
478478
member__.RangeAlternate= range
479479

480+
[<RequireQualifiedAccess>]
481+
typeSemanticClassificationType=
482+
| ReferenceType
483+
| ValueType
484+
| UnionCase
485+
| Function
486+
| Property
487+
| MutableVar
488+
| Module
489+
| Printf
490+
| ComputationExpression
491+
| IntrinsicType
492+
| Enumeration
493+
480494
// A scope represents everything we get back from the typecheck of a file.
481495
// It acts like an in-memory database about the file.
482496
// It is effectively immutable and not updated: when we re-typecheck we just drop the previous
@@ -1399,7 +1413,7 @@ type TypeCheckInfo
13991413
sSymbolUses.GetFormatSpecifierLocations()
14001414

14011415
// Not, this does not have to be a SyncOp, it can be called from any thread
1402-
memberscope.GetExtraColorizations()=
1416+
memberscope.GetSemanticClassification():(range* SemanticClassificationType) []=
14031417
let(|LegitTypeOccurence|_|)=function
14041418
| ItemOccurence.UseInType
14051419
| ItemOccurence.UseInAttribute
@@ -1418,25 +1432,51 @@ type TypeCheckInfo
14181432
match cnrwith
14191433
// 'seq' in 'seq { ... }' gets colored as keywords
14201434
| CNR(_,(Item.Value vref), ItemOccurence.Use,_,_,_, m)when valRefEq g g.seq_vref vref->
1421-
Some(m, FSharpTokenColorKind.Keyword)
1435+
Some(m, SemanticClassificationType.ComputationExpression)
1436+
1437+
| CNR(_,(Item.Value vref),_,_,_,_, m)when isFunction g vref.Type->
1438+
if vref.IsPropertyGetterMethod|| vref.IsPropertySetterMethodthen
1439+
Some(m, SemanticClassificationType.Property)
1440+
elifnot(IsOperatorName vref.DisplayName)then
1441+
Some(m, SemanticClassificationType.Function)
1442+
else None
1443+
| CNR(_,(Item.Value vref),_,_,_,_, m)when vref.IsMutable->
1444+
Some(m, SemanticClassificationType.MutableVar)
1445+
// todo here we should check if a `vref` is of type `ref`1`
1446+
// (the commented code does not work)
1447+
1448+
//| CNR(_, (Item.Value vref), _, _, _, _, m) ->
1449+
// match vref.TauType with
1450+
// | TType.TType_app(tref, _) -> // g.refcell_tcr_canon.t _refcell_tcr_canon canon.Deref.type vref ->
1451+
// if g.refcell_tcr_canon.Deref.Stamp = tref.Deref.Stamp then
1452+
// Some (m, SemanticClassificationType.MutableVar)
1453+
// else None
1454+
// | _ -> None
1455+
| CNR(_, Item.RecdField rfinfo,_,_,_,_, m)when rfinfo.RecdField.IsMutable&& rfinfo.LiteralValue.IsNone->
1456+
Some(m, SemanticClassificationType.MutableVar)
1457+
| CNR(_, Item.MethodGroup(_,_,_),_,_,_,_, m)->
1458+
Some(m, SemanticClassificationType.Function)
14221459
// custom builders, custom operations get colored as keywords
14231460
| CNR(_,(Item.CustomBuilder_| Item.CustomOperation_), ItemOccurence.Use,_,_,_, m)->
1424-
Some(m,FSharpTokenColorKind.Keyword)
1461+
Some(m,SemanticClassificationType.ComputationExpression)
14251462
// well known type aliases get colored as keywords
14261463
| CNR(_,(Item.Types(n,_)),_,_,_,_, m)when keywordTypes.Contains(n)->
1427-
Some(m,FSharpTokenColorKind.Keyword)
1464+
Some(m,SemanticClassificationType.IntrinsicType)
14281465
// types get colored as types when they occur in syntactic types or custom attributes
14291466
// typevariables get colored as types when they occur in syntactic types custom builders, custom operations get colored as keywords
14301467
| CNR(_, Item.Types(_,[OptionalArgumentAttribute]), LegitTypeOccurence,_,_,_,_)-> None
14311468
| CNR(_, Item.CtorGroup(_,[MethInfo.FSMeth(_, OptionalArgumentAttribute,_,_)]), LegitTypeOccurence,_,_,_,_)-> None
14321469
| CNR(_, Item.Types_, LegitTypeOccurence,_,_,_, m)->
1433-
Some(m,FSharpTokenColorKind.TypeName)
1470+
Some(m,SemanticClassificationType.ReferenceType)
14341471
| CNR(_,(Item.TypeVar_| Item.UnqualifiedType_| Item.CtorGroup_), LegitTypeOccurence,_,_,_, m)->
1435-
Some(m,FSharpTokenColorKind.TypeName)
1472+
Some(m,SemanticClassificationType.ReferenceType)
14361473
| CNR(_, Item.ModuleOrNamespaces refs, LegitTypeOccurence,_,_,_, m)when refs|> List.exists(fun x-> x.IsModule)->
1437-
Some(m, FSharpTokenColorKind.TypeName)
1474+
Some(m, SemanticClassificationType.ReferenceType)
1475+
| CNR(_,(Item.ActivePatternCase_| Item.UnionCase_| Item.ActivePatternResult_),_,_,_,_, m)->
1476+
Some(m, SemanticClassificationType.UnionCase)
14381477
|_-> None)
14391478
|> Seq.toArray
1479+
|> Array.append(sSymbolUses.GetFormatSpecifierLocations()|> Array.map(fun m-> m, SemanticClassificationType.Printf))
14401480

14411481
memberx.ScopeResolutions= sResolutions
14421482
memberx.ScopeSymbolUses= sSymbolUses
@@ -2029,12 +2069,12 @@ type FSharpCheckFileResults(errors: FSharpErrorInfo[], scopeOptX: TypeCheckInfo
20292069
// This operation is not asynchronous - GetFormatSpecifierLocations can be run on the calling thread
20302070
scope.GetFormatSpecifierLocations())
20312071

2032-
memberinfo.GetExtraColorizationsAlternate()=
2072+
memberinfo.GetSemanticClassification()=
20332073
threadSafeOp
20342074
(fun()->[||])
20352075
(fun(scope,_builder,_reactor)->
20362076
// This operation is not asynchronous - GetExtraColorizations can be run on the calling thread
2037-
scope.GetExtraColorizations())
2077+
scope.GetSemanticClassification())
20382078

20392079
memberinfo.PartialAssemblySignature=
20402080
threadSafeOp
@@ -2202,7 +2242,7 @@ type BackgroundCompiler(referenceResolver, projectCacheSize, keepAssemblyContent
22022242
requiredToKeep=(fun(builderOpt,_,_)->match builderOptwith None->false| Some b-> b.IsBeingKeptAliveApartFromCacheEntry),
22032243
onDiscard=(fun(_,_,decrement)-> decrement.Dispose()))
22042244

2205-
letgetOrCreateBuilder(options,ct)=
2245+
letgetOrCreateBuilder(options,ct)=
22062246
match incrementalBuildersCache.TryGet optionswith
22072247
| Some b-> b
22082248
| None->
@@ -2482,7 +2522,7 @@ type BackgroundCompiler(referenceResolver, projectCacheSize, keepAssemblyContent
24822522
letexecWithReactorAsync action= reactor.EnqueueAndAwaitOpAsync("ParseAndCheckFileInProject"+ filename, action)
24832523
async{
24842524
let!ct= Async.CancellationToken
2485-
letbuilderOpt,creationErrors,_= getOrCreateBuilder(options, ct)// Q: Whis it it ok to ignore creationErrors in the build cache? A: These errors will be appended into the typecheck results
2525+
let!builderOpt,creationErrors,_= execWithReactorAsync<|fun _-> getOrCreateBuilder(options, ct)// Q: Whis it it ok to ignore creationErrors in the build cache? A: These errors will be appended into the typecheck results
24862526
use _unwind= IncrementalBuilder.KeepBuilderAlive builderOpt
24872527
match builderOptwith
24882528
| None->

‎src/fsharp/vs/service.fsi‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,20 @@ type internal FSharpSymbolUse =
147147
/// The range of text representing the reference to the symbol
148148
memberRangeAlternate:range
149149

150+
[<RequireQualifiedAccess>]
151+
type internal SemanticClassificationType=
152+
| ReferenceType
153+
| ValueType
154+
| UnionCase
155+
| Function
156+
| Property
157+
| MutableVar
158+
| Module
159+
| Printf
160+
| ComputationExpression
161+
| IntrinsicType
162+
| Enumeration
163+
150164
/// A handle to the results of CheckFileInProject.
151165
[<Sealed>]
152166
typeinternalFSharpCheckFileResults=
@@ -272,7 +286,7 @@ type internal FSharpCheckFileResults =
272286
memberGetSymbolUseAtLocation:line:int* colAtEndOfNames:int* lineText:string* names:string list-> Async<FSharpSymbolUse option>
273287

274288
///<summary>Get any extra colorization info that is available after the typecheck</summary>
275-
memberGetExtraColorizationsAlternate: unit->(range*FSharpTokenColorKind)[]
289+
memberGetSemanticClassification: unit->(range*SemanticClassificationType)[]
276290

277291
///<summary>Get the locations of format specifiers</summary>
278292
member GetFormatSpecifierLocations: unit-> range[]

‎tests/service/EditorTests.fs‎

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -430,22 +430,22 @@ let _ = sprintf @"%O\n%-5s" "1" "2" """
430430
typeCheckResults.Errors|> shouldEqual[||]
431431
typeCheckResults.GetFormatSpecifierLocations()
432432
|> Array.map(fun range-> range.StartLine, range.StartColumn, range.EndLine, range.EndColumn)
433-
|> shouldEqual[|(2,45,2,46);
434-
(3,23,3,24);
435-
(4,38,4,39);
436-
(5,29,5,30);
437-
(6,17,6,19);
438-
(7,17,7,21);
439-
(8,17,8,22);
440-
(9,18,9,21);
441-
(10,18,10,20);
442-
(12,12,12,14);
443-
(15,12,15,14);
444-
(16,28,16,29);
445-
(18,30,18,31);
446-
(19,30,19,31);
447-
(20,19,20,24);
448-
(21,18,21,19);(21,22,21,25)|]
433+
|> shouldEqual[|(2,45,2,47);
434+
(3,23,3,25);
435+
(4,38,4,40);
436+
(5,29,5,31);
437+
(6,17,6,20);
438+
(7,17,7,22);
439+
(8,17,8,23);
440+
(9,18,9,22);
441+
(10,18,10,21);
442+
(12,12,12,15);
443+
(15,12,15,15);
444+
(16,28,16,30);
445+
(18,30,18,32);
446+
(19,30,19,32);
447+
(20,19,20,25);
448+
(21,18,21,20);(21,22,21,26)|]
449449

450450
[<Test>]
451451
let``Printf specifiers for triple-quote strings``()=
@@ -465,10 +465,10 @@ let _ = List.iter(printfn \"\"\"%-A
465465
typeCheckResults.Errors|> shouldEqual[||]
466466
typeCheckResults.GetFormatSpecifierLocations()
467467
|> Array.map(fun range-> range.StartLine, range.StartColumn, range.EndLine, range.EndColumn)
468-
|> shouldEqual[|(2,19,2,21);
469-
(4,12,4,14);
470-
(6,29,6,31);
471-
(7,29,7,30);(7,33,7,34)|]
468+
|> shouldEqual[|(2,19,2,22);
469+
(4,12,4,15);
470+
(6,29,6,32);
471+
(7,29,7,31);(7,33,7,35)|]
472472

473473
[<Test>]
474474
let``Printf specifiers for user-defined functions``()=
@@ -485,9 +485,9 @@ let _ = debug "[LanguageService] Type checking fails for '%s' with content=%A an
485485
typeCheckResults.Errors|> shouldEqual[||]
486486
typeCheckResults.GetFormatSpecifierLocations()
487487
|> Array.map(fun range-> range.StartLine, range.StartColumn, range.EndLine, range.EndColumn)
488-
|> shouldEqual[|(3,24,3,25);
489-
(3,29,3,30);
490-
(4,58,4,59);(4,75,4,76);(4,82,4,83);(4,108,4,109)|]
488+
|> shouldEqual[|(3,24,3,26);
489+
(3,29,3,31);
490+
(4,58,4,60);(4,75,4,77);(4,82,4,84);(4,108,4,110)|]
491491

492492
[<Test>]
493493
let``should not report format specifiers for illformed format strings``()=

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp