Skip to content

Commit

Permalink
feat: removes the symbol resolver property and adds explicit definiti…
Browse files Browse the repository at this point in the history
…on and references capability flags, as suggested in #69

Signed-off-by: Lorenzo Addazi <[email protected]>
  • Loading branch information
loradd committed Mar 7, 2024
1 parent 24d927e commit fc6084f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ import kotlin.reflect.jvm.javaField
import kotlin.reflect.typeOf
import kotlin.system.exitProcess

open class KolasuServer<T : Node>(protected open val parser: ASTParser<T>?, protected open val language: String = "", protected open val extensions: List<String> = listOf(), protected open val symbolResolver: SymbolResolver? = null, protected open val generator: CodeGenerator<T>? = null) : LanguageServer, TextDocumentService, WorkspaceService, LanguageClientAware {
open class KolasuServer<T : Node>(
protected open val parser: ASTParser<T>?,
protected open val language: String = "",
protected open val extensions: List<String> = listOf(),
protected open val enableDefinitionCapability: Boolean = false,
protected open val enableReferencesCapability: Boolean = false,
protected open val generator: CodeGenerator<T>? = null
) : LanguageServer, TextDocumentService, WorkspaceService, LanguageClientAware {

protected open lateinit var client: LanguageClient
protected open var configuration: JsonObject = JsonObject()
Expand Down Expand Up @@ -134,11 +141,8 @@ open class KolasuServer<T : Node>(protected open val parser: ASTParser<T>?, prot

capabilities.setTextDocumentSync(TextDocumentSyncOptions().apply { openClose = true; change = TextDocumentSyncKind.Full })
capabilities.setDocumentSymbolProvider(true)

if (symbolResolver != null) {
capabilities.setDefinitionProvider(true)
capabilities.setReferencesProvider(true)
}
capabilities.setDefinitionProvider(this.enableDefinitionCapability)
capabilities.setReferencesProvider(this.enableReferencesCapability)

return CompletableFuture.completedFuture(InitializeResult(capabilities))
}
Expand Down Expand Up @@ -211,7 +215,6 @@ open class KolasuServer<T : Node>(protected open val parser: ASTParser<T>?, prot
if (!::indexWriter.isInitialized) return

val parsingResult = parser?.parse(text) ?: return
symbolResolver?.resolveSymbols(parsingResult.root, uri)
files[uri] = parsingResult

val tree = parsingResult.root ?: return
Expand Down
6 changes: 3 additions & 3 deletions testing/src/main/kotlin/testing/TestKolasuServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package testing
import com.google.gson.JsonObject
import com.strumenta.kolasu.languageserver.CodeGenerator
import com.strumenta.kolasu.languageserver.KolasuServer
import com.strumenta.kolasu.languageserver.SymbolResolver
import com.strumenta.kolasu.model.Node
import com.strumenta.kolasu.parsing.ASTParser
import org.eclipse.lsp4j.DefinitionParams
Expand Down Expand Up @@ -33,7 +32,8 @@ import kotlin.system.measureNanoTime

open class TestKolasuServer<T : Node>(
protected open var parser: ASTParser<T>? = null,
protected open var symbolResolver: SymbolResolver? = null,
protected open var enableDefinitionCapability: Boolean = false,
protected open var enableReferencesCapability: Boolean = false,
protected open var codeGenerator: CodeGenerator<T>? = null,
protected open var language: String = "languageserver",
protected open var fileExtensions: List<String> = listOf(),
Expand All @@ -48,7 +48,7 @@ open class TestKolasuServer<T : Node>(
}

protected open fun initializeServer() {
server = KolasuServer(parser, language, fileExtensions, symbolResolver, codeGenerator)
server = KolasuServer(parser, language, fileExtensions, enableDefinitionCapability, enableReferencesCapability, codeGenerator)
expectDiagnostics(0)

val workspace = workspacePath.toUri().toString()
Expand Down

0 comments on commit fc6084f

Please sign in to comment.