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

Commitd824008

Browse files
vasily-kirichenkoKevinRansom
authored andcommitted
Optimize semantic classification (dotnet#2402)
* filter out uninterested Items earlier during syntax highlighting* remove classification span filtering as unneeded* fix a typo
1 parent3125a05 commitd824008

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

‎src/fsharp/vs/service.fs‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ type TypeCheckInfo
14211421
sSymbolUses.GetFormatSpecifierLocations()
14221422

14231423
// Not, this does not have to be a SyncOp, it can be called from any thread
1424-
memberscope.GetSemanticClassification():(range* SemanticClassificationType) []=
1424+
memberscope.GetSemanticClassification(range:range option):(range* SemanticClassificationType) []=
14251425
let(|LegitTypeOccurence|_|)=function
14261426
| ItemOccurence.UseInType
14271427
| ItemOccurence.UseInAttribute
@@ -1435,7 +1435,15 @@ type TypeCheckInfo
14351435
| TType.TType_app(tref,_)when tref.Stamp= g.attrib_OptionalArgumentAttribute.TyconRef.Stamp-> Some()
14361436
|_-> None
14371437

1438-
sResolutions.CapturedNameResolutions
1438+
letresolutions=
1439+
match rangewith
1440+
| Some range->
1441+
sResolutions.CapturedNameResolutions
1442+
|> Seq.filter(fun cnr-> rangeContainsPos range cnr.Range.Start|| rangeContainsPos range cnr.Range.End)
1443+
| None->
1444+
sResolutions.CapturedNameResolutions:> seq<_>
1445+
1446+
resolutions
14391447
|> Seq.choose(fun cnr->
14401448
match cnrwith
14411449
// 'seq' in 'seq { ... }' gets colored as keywords
@@ -2085,12 +2093,12 @@ type FSharpCheckFileResults(errors: FSharpErrorInfo[], scopeOptX: TypeCheckInfo
20852093
// This operation is not asynchronous - GetFormatSpecifierLocations can be run on the calling thread
20862094
scope.GetFormatSpecifierLocations())
20872095

2088-
memberinfo.GetSemanticClassification()=
2096+
memberinfo.GetSemanticClassification(range:range option)=
20892097
threadSafeOp
20902098
(fun()->[||])
20912099
(fun(scope,_builder,_reactor)->
20922100
// This operation is not asynchronous - GetExtraColorizations can be run on the calling thread
2093-
scope.GetSemanticClassification())
2101+
scope.GetSemanticClassification(range))
20942102

20952103
memberinfo.PartialAssemblySignature=
20962104
threadSafeOp

‎src/fsharp/vs/service.fsi‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ type internal FSharpCheckFileResults =
287287
memberGetSymbolUseAtLocation:line:int* colAtEndOfNames:int* lineText:string* names:string list-> Async<FSharpSymbolUse option>
288288

289289
///<summary>Get any extra colorization info that is available after the typecheck</summary>
290-
member GetSemanticClassification:unit->(range* SemanticClassificationType)[]
290+
member GetSemanticClassification:range option->(range* SemanticClassificationType)[]
291291

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

‎vsintegration/src/FSharp.Editor/Classification/ColorizationService.fs‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ type internal FSharpColorizationService
4141
let!sourceText= document.GetTextAsync(cancellationToken)
4242
let!_,_,checkResults= checkerProvider.Checker.ParseAndCheckDocument(document, options, sourceText= sourceText, allowStaleResults=false)
4343
// it's crucial to not return duplicated or overlapping `ClassifiedSpan`s because Find Usages service crashes.
44-
letcolorizationData= checkResults.GetSemanticClassification()|> Array.distinctBy fst
44+
lettargetRange= CommonRoslynHelpers.TextSpanToFSharpRange(document.FilePath, textSpan, sourceText)
45+
letcolorizationData= checkResults.GetSemanticClassification(Some targetRange)|> Array.distinctBy fst
46+
4547
for(range, classificationType)in colorizationDatado
4648
letspan= CommonHelpers.fixupSpan(sourceText, CommonRoslynHelpers.FSharpRangeToTextSpan(sourceText, range))
47-
if textSpan.Contains(span.Start)|| textSpan.Contains(span.End-1)|| span.Contains(textSpan)then
48-
result.Add(ClassifiedSpan(span, FSharpClassificationTypes.getClassificationTypeName(classificationType)))
49-
}|> Async.Ignore|> CommonRoslynHelpers.StartAsyncUnitAsTask cancellationToken
49+
result.Add(ClassifiedSpan(span, FSharpClassificationTypes.getClassificationTypeName(classificationType)))
50+
}
51+
|> Async.Ignore|> CommonRoslynHelpers.StartAsyncUnitAsTask cancellationToken
5052

5153
// Do not perform classification if we don't have project options (#defines matter)
5254
memberthis.AdjustStaleClassification(_:SourceText,classifiedSpan:ClassifiedSpan):ClassifiedSpan= classifiedSpan

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ module internal CommonRoslynHelpers =
3030
//Assert.Exception(e)
3131
None
3232

33+
letTextSpanToFSharpRange(fileName:string,textSpan:TextSpan,sourceText:SourceText):range=
34+
letstartLine= sourceText.Lines.GetLineFromPosition textSpan.Start
35+
letendLine= sourceText.Lines.GetLineFromPosition textSpan.End
36+
mkRange
37+
fileName
38+
(Pos.fromZ startLine.LineNumber(textSpan.Start- startLine.Start))
39+
(Pos.fromZ endLine.LineNumber(textSpan.End- endLine.Start))
40+
3341
letGetCompletedTaskResult(task:Task<'TResult>)=
3442
if task.Status= TaskStatus.RanToCompletionthen
3543
task.Result

‎vsintegration/src/FSharp.LanguageService/Intellisense.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,6 @@ type internal FSharpIntellisenseInfo
563563

564564
// This is called on the UI thread after fresh full typecheck results are available
565565
memberthis.OnParseFileOrCheckFileComplete(source:IFSharpSource)=
566-
for linein colorizer.Value.SetExtraColorizations(typedResults.GetSemanticClassification())do
566+
for linein colorizer.Value.SetExtraColorizations(typedResults.GetSemanticClassification None)do
567567
source.RecolorizeLine line
568568

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp