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

Commitc8edcc3

Browse files
optimize GetBestEnvForPos by indexing nameres environments (scopes) by line number
1 parent4fc2f9b commitc8edcc3

File tree

3 files changed

+44
-26
lines changed

3 files changed

+44
-26
lines changed

‎src/fsharp/vs/service.fs‎

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -518,12 +518,13 @@ type TypeCheckInfo
518518
letncenv=new NameResolver(g,amap,infoReader,NameResolution.FakeInstantiationGenerator)
519519

520520
/// Find the most precise naming environment for the given line and column
521-
letGetBestEnvForPos cursorPos=
521+
letGetBestEnvForPos(envsByLine:ResizeArray<range*NameResolutionEnv*AccessorDomain>[])(cursorPos:pos)=
522522

523+
// Find all scopes those contain given position
523524
let mutablebestSoFar= None
524525

525526
// Find the most deeply nested enclosing scope that contains given position
526-
sResolutions.CapturedEnvs|> ResizeArray.iter(fun(possm,env,ad)->
527+
envsByLine.[cursorPos.Line]|> ResizeArray.iter(fun(possm,env,ad)->
527528
if rangeContainsPos possm cursorPosthen
528529
match bestSoFarwith
529530
| Some(bestm,_,_)->
@@ -540,36 +541,35 @@ type TypeCheckInfo
540541
// We guarantee to only refine to a more nested environment. It may not be strictly
541542
// the right environment, but will alwauys be at least as rich
542543

543-
letbestAlmostIncludedSoFar= ref None
544+
letmutablebestAlmostIncludedSoFar= None
544545

545-
sResolutions.CapturedEnvs|> ResizeArray.iter(fun(possm,env,ad)->
546+
envsByLine.[cursorPos.Line]|> ResizeArray.iter(fun(possm,env,ad)->
546547
// take only ranges that strictly do not include cursorPos (all ranges that touch cursorPos were processed during 'Strict Inclusion' part)
547-
ifrangeBeforePospossm cursorPos&&not(posEqpossm.End cursorPos)then
548+
ifnot(posEqpossm.End cursorPos)&&rangeBeforePospossm cursorPosthen
548549
letcontained=
549550
match mostDeeplyNestedEnclosingScopewith
550551
| Some(bestm,_,_)-> rangeContainsRange bestm possm
551552
| None->true
552553

553554
if containedthen
554-
match!bestAlmostIncludedSoFarwith
555-
| Some(rightm:range,_,_)->
555+
match bestAlmostIncludedSoFarwith
556+
| Some(rightm:range,_,_)->
556557
if posGt possm.End rightm.End||
557558
(posEq possm.End rightm.End&& posGt possm.Start rightm.Start)then
558-
bestAlmostIncludedSoFar:= Some(possm,env,ad)
559-
|_-> bestAlmostIncludedSoFar:= Some(possm,env,ad))
559+
bestAlmostIncludedSoFar<- Some(possm,env,ad)
560+
|_-> bestAlmostIncludedSoFar<- Some(possm,env,ad))
560561

561562
letresEnv=
562-
match!bestAlmostIncludedSoFarwith
563-
| Some(_m,env,ad)->
563+
match bestAlmostIncludedSoFarwith
564+
| Some(_,env,ad)->
564565
env,ad
565566
| None->
566567
match mostDeeplyNestedEnclosingScopewith
567-
| Some(_m,env,ad)->
568+
| Some(_,env,ad)->
568569
env,ad
569570
| None->
570-
(sFallback,AccessibleFromSomeFSharpCode)
571+
(sFallback,AccessibleFromSomeFSharpCode)
571572
letpm= mkRange mainInputFileName cursorPos cursorPos
572-
573573
resEnv,pm
574574

575575
/// The items that come back from ResolveCompletionsInType are a bit
@@ -789,9 +789,17 @@ type TypeCheckInfo
789789
if textChangedthen GetPreciseCompletionListFromExprTypingsResult.NoneBecauseTypecheckIsStaleAndTextChanged
790790
else GetPreciseCompletionListFromExprTypingsResult.None
791791

792+
letGetEnvsByLine():ResizeArray<range*NameResolutionEnv*AccessorDomain>[]=
793+
letmaxLine= sResolutions.CapturedEnvs|> Seq.maxBy(fun(m,_,_)-> m.EndLine)|>fun(m,_,_)-> m.EndLine
794+
letenvsByLine= Array.init(maxLine+1)(fun _-> ResizeArray())
795+
for(m,_,_)as envin sResolutions.CapturedEnvsdo
796+
for linein m.StartLine..m.EndLinedo
797+
envsByLine.[line].Add env
798+
envsByLine
799+
792800
/// Find items in the best naming environment.
793801
letGetEnvironmentLookupResolutions(cursorPos,plid,filterCtors,showObsolete)=
794-
let(nenv,ad),m= GetBestEnvForPos cursorPos
802+
let(nenv,ad),m= GetBestEnvForPos(GetEnvsByLine())cursorPos
795803
letitems= NameResolution.ResolvePartialLongIdent ncenv nenv(ConstraintSolver.IsApplicableMethApprox g amap m) m ad plid showObsolete
796804
letitems= items|> RemoveDuplicateItems g
797805
letitems= items|> RemoveExplicitlySuppressed g
@@ -801,7 +809,7 @@ type TypeCheckInfo
801809

802810
/// Find record fields in the best naming environment.
803811
letGetClassOrRecordFieldsEnvironmentLookupResolutions(cursorPos,plid,(_residue:string option))=
804-
let(nenv,ad),m= GetBestEnvForPos cursorPos
812+
let(nenv,ad),m= GetBestEnvForPos(GetEnvsByLine())cursorPos
805813
letitems= NameResolution.ResolvePartialLongIdentToClassOrRecdFields ncenv nenv m ad plidfalse
806814
letitems= items|> RemoveDuplicateItems g
807815
letitems= items|> RemoveExplicitlySuppressed g
@@ -994,7 +1002,7 @@ type TypeCheckInfo
9941002

9951003
/// Get the auto-complete items at a particular location.
9961004
letGetDeclItemsForNamesAtPosition(parseResultsOpt:FSharpParseFileResults option,origLongIdentOpt:string list option,residueOpt:string option,line:int,lineStr:string,colAtEndOfNamesAndResidue,filterCtors,resolveOverloads,hasTextChangedSinceLastTypecheck:(obj* range-> bool))=
997-
1005+
9981006
letloc=
9991007
match colAtEndOfNamesAndResiduewith
10001008
| pastEndOfLinewhen pastEndOfLine>= lineStr.Length-> lineStr.Length
@@ -1025,7 +1033,7 @@ type TypeCheckInfo
10251033

10261034
// Completion at ' { XXX = ... } "
10271035
| Some(CompletionContext.RecordField(RecordContext.New(plid, residue)))->
1028-
Some(GetClassOrRecordFieldsEnvironmentLookupResolutions(mkPos line loc, plid, residue))
1036+
Some(GetClassOrRecordFieldsEnvironmentLookupResolutions(mkPos line loc, plid, residue))
10291037

10301038
// Completion at ' { XXX = ... with ... } "
10311039
| Some(CompletionContext.RecordField(RecordContext.CopyOnUpdate(r,(plid, residue))))->
@@ -1112,16 +1120,18 @@ type TypeCheckInfo
11121120
else
11131121
items
11141122

1115-
11161123
static letkeywordTypes= Lexhelp.Keywords.keywordTypes
11171124

1125+
memberx.GetSortedNameResolutionEnvironments()= GetEnvsByLine()
1126+
11181127
memberx.GetVisibleNamespacesAndModulesAtPosition(cursorPos:pos):ModuleOrNamespaceRef list=
1119-
let(nenv,ad),m= GetBestEnvForPos cursorPos
1128+
let(nenv,ad),m= GetBestEnvForPos(GetEnvsByLine())cursorPos
11201129
NameResolution.GetVisibleNamespacesAndModulesAtPoint ncenv nenv m ad
11211130

1122-
memberx.IsRelativeNameResolvable(cursorPos:pos,plid:string list,item:Item):bool=
1131+
1132+
memberx.IsRelativeNameResolvable(cursorPos:pos,plid:string list,item:Item,envsByLine:ResizeArray<range*NameResolutionEnv*AccessorDomain>[]):bool=
11231133
/// Find items in the best naming environment.
1124-
let(nenv,ad),m= GetBestEnvForPos cursorPos
1134+
let(nenv,ad),m= GetBestEnvForPosenvsByLinecursorPos
11251135
NameResolution.IsItemResolvable ncenv nenv m ad plid item
11261136

11271137
//let items = NameResolution.ResolvePartialLongIdent ncenv nenv (fun _ _ -> true) m ad plid true
@@ -2057,8 +2067,11 @@ type FSharpCheckFileResults(errors: FSharpErrorInfo[], scopeOptX: TypeCheckInfo
20572067
memberinfo.GetVisibleNamespacesAndModulesAtPoint(pos:pos):Async<ModuleOrNamespaceRef[]>=
20582068
reactorOp"GetDeclarations"[||](fun scope-> scope.GetVisibleNamespacesAndModulesAtPosition(pos)|> List.toArray)
20592069

2060-
memberinfo.IsRelativeNameResolvable(pos:pos,plid:string list,item:Item):Async<bool>=
2061-
reactorOp"IsRelativeNameResolvable"true(fun scope-> scope.IsRelativeNameResolvable(pos, plid, item))
2070+
memberinfo.GetNameResolutionEnvironmentsByLine():Async<ResizeArray<range* NameResolutionEnv* AccessorDomain>[]>=
2071+
reactorOp"IsRelativeNameResolvable"[||](fun scope-> scope.GetSortedNameResolutionEnvironments())
2072+
2073+
memberinfo.IsRelativeNameResolvable(pos:pos,plid:string list,item:Item,nenvsByLine:ResizeArray<range*NameResolutionEnv*AccessorDomain>[]):Async<bool>=
2074+
reactorOp"IsRelativeNameResolvable"true(fun scope-> scope.IsRelativeNameResolvable(pos, plid, item, nenvsByLine))
20622075

20632076
//----------------------------------------------------------------------------
20642077
// BackgroundCompiler

‎src/fsharp/vs/service.fsi‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ open Microsoft.FSharp.Compiler.Range
1414
openMicrosoft.FSharp.Compiler.TcGlobals
1515
openMicrosoft.FSharp.Compiler.NameResolution
1616
openMicrosoft.FSharp.Compiler.CompileOps
17+
openMicrosoft.FSharp.Compiler.AccessibilityLogic
1718

1819
/// Represents one parameter for one method (or other item) in a group.
1920
[<Sealed>]
@@ -285,7 +286,9 @@ type internal FSharpCheckFileResults =
285286

286287
member GetVisibleNamespacesAndModulesAtPoint: pos-> Async<Tast.ModuleOrNamespaceRef[]>
287288

288-
member IsRelativeNameResolvable: cursorPos: pos* plid: string list* item: Item-> Async<bool>
289+
member IsRelativeNameResolvable: cursorPos: pos* plid: string list* item: Item* ResizeArray<range* NameResolutionEnv* AccessorDomain>[]-> Async<bool>
290+
291+
member GetNameResolutionEnvironmentsByLine: unit-> Async<ResizeArray<range* NameResolutionEnv* AccessorDomain>[]>
289292

290293
/// A handle to the results of CheckFileInProject.
291294
[<Sealed>]

‎vsintegration/src/FSharp.Editor/Diagnostics/SimplifyNameDiagnosticAnalyzer.fs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ type internal SimplifyNameDiagnosticAnalyzer() =
7575
|> Array.groupBy(fun(symbolUse,_,plidStartCol,_)-> symbolUse.RangeAlternate.StartLine, plidStartCol)
7676
|> Array.map(fun(_,xs)-> xs|> Array.maxBy(fun(symbolUse,_,_,_)-> symbolUse.RangeAlternate.EndColumn))
7777

78+
let!nenvsByLine= checkResults.GetNameResolutionEnvironmentsByLine()|> liftAsync
79+
7880
for symbolUse, plid, plidStartCol, namein symbolUsesdo
7981
ifnot symbolUse.IsFromDefinitionthen
8082
letposAtStartOfName=
@@ -88,7 +90,7 @@ type internal SimplifyNameDiagnosticAnalyzer() =
8890
match restwith
8991
|[]->return current
9092
| headIdent:: restPlid->
91-
let!res= checkResults.IsRelativeNameResolvable(posAtStartOfName, current, symbolUse.Symbol.Item)
93+
let!res= checkResults.IsRelativeNameResolvable(posAtStartOfName, current, symbolUse.Symbol.Item, nenvsByLine)
9294
if resthenreturn current
9395
elsereturn! loop restPlid(headIdent:: current)
9496
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp