Skip to content

Commit 969616b

Browse files
committed
Only use embedded db on symbol index (if no storage path is provided)
1 parent 0f1012b commit 969616b

File tree

5 files changed

+14
-15
lines changed

5 files changed

+14
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class CompilerClassPath(private val config: CompilerConfiguration) : Closeable {
2121
private val javaSourcePath = mutableSetOf<Path>()
2222
private val buildScriptClassPath = mutableSetOf<Path>()
2323
val classPath = mutableSetOf<ClassPathEntry>()
24-
lateinit var db: Database
24+
var db: Database? = null
2525
val outputDirectory: File = Files.createTempDirectory("klsBuildOutput").toFile()
2626
val javaHome: String? = System.getProperty("java.home", null)
2727

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ public data class ExternalSourcesConfiguration(
4444
)
4545

4646

47-
fun setupServerDatabase(params: InitializeParams): Database {
48-
var db: Database? = null
47+
fun setupServerDatabase(params: InitializeParams): Database? {
4948
val dbName = "kls_database"
5049

5150
params.initializationOptions?.let { initializationOptions ->
@@ -54,12 +53,12 @@ fun setupServerDatabase(params: InitializeParams): Database {
5453

5554
options.storagePath?.let { storagePath ->
5655
if (Files.isDirectory(storagePath)) {
57-
db = Database.connect("jdbc:sqlite:${Path.of(storagePath.toString(), dbName)}.db")
56+
return Database.connect("jdbc:sqlite:${Path.of(storagePath.toString(), dbName)}.db")
5857
}
5958
}
6059
}
6160

62-
return db ?: Database.connect("jdbc:h2:mem:$dbName;DB_CLOSE_DELAY=-1", "org.h2.Driver")
61+
return null
6362
}
6463

6564
data class InitializationOptions(val storagePath: Path?)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
9292

9393
val db = setupServerDatabase(params)
9494

95-
sourcePath.index = SymbolIndex(db)
95+
sourcePath.index = if (db != null) SymbolIndex(db) else SymbolIndex()
9696
classPath.db = db
9797

9898
val clientCapabilities = params.capabilities

server/src/main/kotlin/org/javacs/kt/index/SymbolIndex.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class PositionEntity(id: EntityID<Int>) : IntEntity(id) {
8080
/**
8181
* A global view of all available symbols across all packages.
8282
*/
83-
class SymbolIndex(private val db: Database) {
83+
class SymbolIndex(private val db: Database = Database.connect("jdbc:h2:mem:symbolindex;DB_CLOSE_DELAY=-1", "org.h2.Driver")) {
8484
var progressFactory: Progress.Factory = Progress.Factory.None
8585

8686
init {

shared/src/main/kotlin/org/javacs/kt/classpath/DefaultClassPathResolver.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import java.nio.file.Path
66
import java.nio.file.PathMatcher
77
import java.nio.file.FileSystems
88

9-
fun defaultClassPathResolver(workspaceRoots: Collection<Path>, db: Database): ClassPathResolver =
10-
CachedClassPathResolver(
11-
WithStdlibResolver(
12-
ShellClassPathResolver.global(workspaceRoots.firstOrNull())
13-
.or(workspaceRoots.asSequence().flatMap { workspaceResolvers(it) }.joined)
14-
).or(BackupClassPathResolver),
15-
db
16-
)
9+
fun defaultClassPathResolver(workspaceRoots: Collection<Path>, db: Database? = null): ClassPathResolver {
10+
val childResolver = WithStdlibResolver(
11+
ShellClassPathResolver.global(workspaceRoots.firstOrNull())
12+
.or(workspaceRoots.asSequence().flatMap { workspaceResolvers(it) }.joined)
13+
).or(BackupClassPathResolver)
14+
15+
return if (db != null) CachedClassPathResolver(childResolver, db) else childResolver
16+
}
1717

1818
/** Searches the workspace for all files that could provide classpath info. */
1919
private fun workspaceResolvers(workspaceRoot: Path): Sequence<ClassPathResolver> {

0 commit comments

Comments
 (0)