@@ -23,19 +23,19 @@ class CompilerCachingSuite extends BasePCSuite:
23
23
24
24
val timeout = 5 .seconds
25
25
26
- private def checkCompilationCount (params : VirtualFileParams , expected : Int ): Unit =
26
+ private def checkCompilationCount (expected : Int ): Unit =
27
27
presentationCompiler match
28
28
case pc : ScalaPresentationCompiler =>
29
- val compilations = pc.compilerAccess.withNonInterruptableCompiler(Some (params) )(- 1 , EmptyCancelToken ) { driver =>
29
+ val compilations = pc.compilerAccess.withNonInterruptableCompiler(None )(- 1 , EmptyCancelToken ) { driver =>
30
30
driver.compiler().currentCtx.runId
31
31
}.get(timeout.length, timeout.unit)
32
32
assertEquals(expected, compilations, s " Expected $expected compilations but got $compilations" )
33
33
case _ => throw IllegalStateException (" Presentation compiler should always be of type of ScalaPresentationCompiler" )
34
34
35
- private def getContext (params : VirtualFileParams ): Context =
35
+ private def getContext (): Context =
36
36
presentationCompiler match
37
37
case pc : ScalaPresentationCompiler =>
38
- pc.compilerAccess.withNonInterruptableCompiler(Some (params) )(null , EmptyCancelToken ) { driver =>
38
+ pc.compilerAccess.withNonInterruptableCompiler(None )(null , EmptyCancelToken ) { driver =>
39
39
driver.compiler().currentCtx
40
40
}.get(timeout.length, timeout.unit)
41
41
case _ => throw IllegalStateException (" Presentation compiler should always be of type of ScalaPresentationCompiler" )
@@ -44,76 +44,73 @@ class CompilerCachingSuite extends BasePCSuite:
44
44
def beforeEach : Unit =
45
45
presentationCompiler.restart()
46
46
47
- // We want to run art least one compilation, so runId points at 3.
47
+ // We want to run at least one compilation, so runId points at 3.
48
48
// This will ensure that we use the same driver, not recreate fresh one on each call
49
49
val dryRunParams = CompilerOffsetParams (Paths .get(" Test.scala" ).toUri(), " dryRun" , 1 , EmptyCancelToken )
50
- checkCompilationCount(dryRunParams, 2 )
51
- val freshContext = getContext(dryRunParams )
50
+ checkCompilationCount(2 )
51
+ val freshContext = getContext()
52
52
presentationCompiler.complete(dryRunParams).get(timeout.length, timeout.unit)
53
- checkCompilationCount(dryRunParams, 3 )
54
- val dryRunContext = getContext(dryRunParams )
53
+ checkCompilationCount(3 )
54
+ val dryRunContext = getContext()
55
55
assert(freshContext != dryRunContext)
56
56
57
57
58
58
@ Test
59
59
def `cursor-compilation-does-not-corrupt-cache` : Unit =
60
+ val contextPreCompilation = getContext()
60
61
61
- val fakeParamsCursor = CompilerOffsetParams (Paths .get(" Test.scala" ).toUri(), " def hello = new" , 15 , EmptyCancelToken )
62
62
val fakeParams = CompilerOffsetParams (Paths .get(" Test.scala" ).toUri(), " def hello = ne" , 14 , EmptyCancelToken )
63
-
64
- val contextPreCompilation = getContext(fakeParams)
65
-
66
63
presentationCompiler.complete(fakeParams).get(timeout.length, timeout.unit)
67
- val contextPostFirst = getContext(fakeParams )
64
+ val contextPostFirst = getContext()
68
65
assert(contextPreCompilation != contextPostFirst)
69
- checkCompilationCount(fakeParams, 4 )
66
+ checkCompilationCount(4 )
70
67
68
+ val fakeParamsCursor = CompilerOffsetParams (Paths .get(" Test.scala" ).toUri(), " def hello = new" , 15 , EmptyCancelToken )
71
69
presentationCompiler.complete(fakeParamsCursor).get(timeout.length, timeout.unit)
72
- val contextPostCursor = getContext(fakeParamsCursor )
70
+ val contextPostCursor = getContext()
73
71
assert(contextPreCompilation != contextPostCursor)
74
72
assert(contextPostFirst == contextPostCursor)
75
- checkCompilationCount(fakeParamsCursor, 4 )
73
+ checkCompilationCount(4 )
76
74
77
75
presentationCompiler.complete(fakeParams).get(timeout.length, timeout.unit)
78
- val contextPostSecond = getContext(fakeParams )
76
+ val contextPostSecond = getContext()
79
77
assert(contextPreCompilation != contextPostSecond)
80
78
assert(contextPostFirst == contextPostCursor)
81
79
assert(contextPostCursor == contextPostSecond)
82
- checkCompilationCount(fakeParamsCursor, 4 )
80
+ checkCompilationCount(4 )
83
81
84
82
@ Test
85
83
def `compilation-for-same-snippet-is-cached` : Unit =
86
- val fakeParams = CompilerOffsetParams (Paths .get(" Test.scala" ).toUri(), " def hello = ne" , 14 , EmptyCancelToken )
87
-
88
- val contextPreCompilation = getContext(fakeParams)
84
+ val contextPreCompilation = getContext()
89
85
86
+ val fakeParams = CompilerOffsetParams (Paths .get(" Test.scala" ).toUri(), " def hello = ne" , 14 , EmptyCancelToken )
90
87
presentationCompiler.complete(fakeParams).get(timeout.length, timeout.unit)
91
- val contextPostFirst = getContext(fakeParams )
88
+ val contextPostFirst = getContext()
92
89
assert(contextPreCompilation != contextPostFirst)
93
- checkCompilationCount(fakeParams, 4 )
90
+ checkCompilationCount(4 )
94
91
95
92
presentationCompiler.complete(fakeParams).get(timeout.length, timeout.unit)
96
- val contextPostSecond = getContext(fakeParams )
93
+ val contextPostSecond = getContext()
97
94
assert(contextPreCompilation != contextPostFirst)
98
95
assert(contextPostSecond == contextPostFirst)
99
- checkCompilationCount(fakeParams, 4 )
96
+ checkCompilationCount(4 )
100
97
101
98
@ Test
102
99
def `compilation-for-different-snippet-is-not-cached` : Unit =
103
100
104
- val fakeParams = CompilerOffsetParams (Paths .get(" Test.scala" ).toUri(), " def hello = prin" , 16 , EmptyCancelToken )
105
- val fakeParams2 = CompilerOffsetParams (Paths .get(" Test2.scala" ).toUri(), " def hello = prin" , 16 , EmptyCancelToken )
106
- val fakeParams3 = CompilerOffsetParams (Paths .get(" Test2.scala" ).toUri(), " def hello = print" , 17 , EmptyCancelToken )
107
101
108
- checkCompilationCount(fakeParams, 3 )
102
+ checkCompilationCount(3 )
103
+ val fakeParams = CompilerOffsetParams (Paths .get(" Test.scala" ).toUri(), " def hello = prin" , 16 , EmptyCancelToken )
109
104
presentationCompiler.complete(fakeParams).get(timeout.length, timeout.unit)
110
- checkCompilationCount(fakeParams, 4 )
105
+ checkCompilationCount(4 )
111
106
107
+ val fakeParams2 = CompilerOffsetParams (Paths .get(" Test2.scala" ).toUri(), " def hello = prin" , 16 , EmptyCancelToken )
112
108
presentationCompiler.complete(fakeParams2).get(timeout.length, timeout.unit)
113
- checkCompilationCount(fakeParams2, 5 )
109
+ checkCompilationCount(5 )
114
110
111
+ val fakeParams3 = CompilerOffsetParams (Paths .get(" Test2.scala" ).toUri(), " def hello = print" , 17 , EmptyCancelToken )
115
112
presentationCompiler.complete(fakeParams3).get(timeout.length, timeout.unit)
116
- checkCompilationCount(fakeParams3, 6 )
113
+ checkCompilationCount(6 )
117
114
118
115
119
116
private val testFunctions : List [OffsetParams => CompletableFuture [_]] = List (
@@ -137,14 +134,14 @@ class CompilerCachingSuite extends BasePCSuite:
137
134
@ Test
138
135
def `different-api-calls-reuse-cache` : Unit =
139
136
val fakeParams = CompilerOffsetParams (Paths .get(" Test.scala" ).toUri(), " def hello = ne" , 13 , EmptyCancelToken )
140
-
141
137
presentationCompiler.complete(fakeParams).get(timeout.length, timeout.unit)
142
- val contextBefore = getContext(fakeParams)
138
+
139
+ val contextBefore = getContext()
143
140
144
141
val differentContexts = testFunctions.map: f =>
145
142
f(fakeParams).get(timeout.length, timeout.unit)
146
- checkCompilationCount(fakeParams, 4 )
147
- getContext(fakeParams )
143
+ checkCompilationCount(4 )
144
+ getContext()
148
145
.toSet
149
146
150
147
assert(differentContexts == Set (contextBefore))
@@ -155,12 +152,12 @@ class CompilerCachingSuite extends BasePCSuite:
155
152
import scala .concurrent .ExecutionContext .Implicits .global
156
153
157
154
val fakeParams = CompilerOffsetParams (Paths .get(" Test.scala" ).toUri(), " def hello = ne" , 13 , EmptyCancelToken )
158
-
159
155
presentationCompiler.complete(fakeParams).get(timeout.length, timeout.unit)
160
- val contextBefore = getContext(fakeParams)
156
+
157
+ val contextBefore = getContext()
161
158
162
159
val futures = testFunctions.map: f =>
163
- f(fakeParams).asScala.map(_ => getContext(fakeParams ))
160
+ f(fakeParams).asScala.map(_ => getContext())
164
161
165
162
val res = Await .result(Future .sequence(futures), timeout).toSet
166
163
assert(res == Set (contextBefore))
0 commit comments