Skip to content

Commit b99b7c6

Browse files
committed
Clean up compiled states in SourcePath during refresh
1 parent b10b633 commit b99b7c6

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

server/src/main/kotlin/org/javacs/kt/CompilerClassPath.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class CompilerClassPath(private val config: CompilerConfiguration) : Closeable {
4646
}
4747

4848
if (refreshCompiler) {
49+
LOG.info("Reinstantiating compiler")
4950
compiler.close()
5051
compiler = Compiler(javaSourcePath, classPath, buildScriptClassPath)
5152
updateCompilerConfiguration()

server/src/main/kotlin/org/javacs/kt/SourcePath.kt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ class SourcePath(
4545
content = newContent
4646
}
4747

48+
fun clean() {
49+
parsed = null
50+
compiledFile = null
51+
compiledContext = null
52+
compiledContainer = null
53+
}
54+
4855
fun parse() {
4956
// TODO: Create PsiFile using the stored language instead
5057
parsed = cp.compiler.createKtFile(content, path ?: Paths.get("sourceFile.virtual.$extension"), kind)
@@ -68,12 +75,6 @@ class SourcePath(
6875

6976
fun compile() = parse().apply { doCompile() }
7077

71-
fun compileIfInitialized() {
72-
if (parsed != null) {
73-
compile()
74-
}
75-
}
76-
7778
private fun doCompile() {
7879
LOG.debug("Compiling {}", path?.fileName)
7980

@@ -205,8 +206,12 @@ class SourcePath(
205206
* Recompiles all source files that are initialized.
206207
*/
207208
fun refresh() {
208-
LOG.info("Refreshing source path")
209-
files.values.forEach { it.compileIfInitialized() }
209+
val initialized = files.values.any { it.parsed != null }
210+
if (initialized) {
211+
LOG.info("Refreshing source path")
212+
files.values.forEach { it.clean() }
213+
files.values.forEach { it.compile() }
214+
}
210215
}
211216

212217
/**

0 commit comments

Comments
 (0)