-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement folding ranges, starting work on the logger, general improv…
…ements
- Loading branch information
1 parent
e1e0b5b
commit 4e8982e
Showing
13 changed files
with
170 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...lsp/server/DeclarativeWorkspaceService.kt → ...rative/lsp/DeclarativeWorkspaceService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
lsp/src/main/kotlin/org/gradle/declarative/lsp/logging/LspAppender.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.gradle.declarative.lsp.logging | ||
|
||
import ch.qos.logback.classic.spi.ILoggingEvent | ||
import ch.qos.logback.core.AppenderBase | ||
import org.eclipse.lsp4j.MessageParams | ||
import org.eclipse.lsp4j.MessageType | ||
import org.eclipse.lsp4j.services.LanguageClient | ||
|
||
class LspAppender(private val client: LanguageClient): AppenderBase<ILoggingEvent>() { | ||
|
||
override fun append(eventObject: ILoggingEvent?) { | ||
eventObject?.let { | ||
val message = it.formattedMessage | ||
val type = when(it.level.toInt()) { | ||
10000 -> MessageType.Error | ||
20000 -> MessageType.Warning | ||
30000 -> MessageType.Info | ||
else -> MessageType.Log | ||
} | ||
|
||
val messageParams = MessageParams(type, message) | ||
client.logMessage(messageParams) | ||
} | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
lsp/src/main/kotlin/org/gradle/declarative/lsp/storage/VersionedDocumentStore.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.gradle.declarative.lsp.storage | ||
|
||
import org.gradle.internal.declarativedsl.dom.DeclarativeDocument | ||
import java.net.URI | ||
|
||
class VersionedDocumentStore { | ||
|
||
private val store = mutableMapOf<URI, DocumentStoreEntry>() | ||
|
||
operator fun get(uri: URI): DeclarativeDocument? { | ||
return store[uri]?.document | ||
} | ||
|
||
fun storeInitial(uri: URI, document: DeclarativeDocument) { | ||
store(uri, DocumentStoreEntry.Initial(document)) | ||
} | ||
|
||
fun storeVersioned(uri: URI, version: Int, document: DeclarativeDocument) { | ||
store(uri, DocumentStoreEntry.Versioned(version, document)) | ||
} | ||
|
||
/** | ||
* Stores a versioned document. | ||
* If the document is already stored, the version must be greater than the stored version. | ||
* | ||
* @return `true` if the document was stored, `false` otherwise. | ||
*/ | ||
private fun store(uri: URI, entry: DocumentStoreEntry) { | ||
return when (val storedEntry = store[uri]) { | ||
null -> store[uri] = entry | ||
is DocumentStoreEntry.Initial -> { | ||
when (entry) { | ||
is DocumentStoreEntry.Initial -> throw IllegalArgumentException("Cannot store an initial document when an initial document is already stored.") | ||
is DocumentStoreEntry.Versioned -> store[uri] = entry | ||
} | ||
} | ||
|
||
is DocumentStoreEntry.Versioned -> { | ||
when (entry) { | ||
is DocumentStoreEntry.Initial -> throw IllegalArgumentException("Cannot store an initial document when a versioned document is already stored.") | ||
is DocumentStoreEntry.Versioned -> { | ||
if (storedEntry.version >= entry.version) { | ||
store[uri] = entry | ||
} else { | ||
throw IllegalArgumentException("Cannot store a versioned document with a version less than the stored version.") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
sealed class DocumentStoreEntry { | ||
abstract val document: DeclarativeDocument | ||
|
||
data class Initial(override val document: DeclarativeDocument) : DocumentStoreEntry() | ||
data class Versioned(val version: Int, override val document: DeclarativeDocument) : DocumentStoreEntry() | ||
} |
2 changes: 1 addition & 1 deletion
2
...larative/lsp/tooling/ConnectionHandler.kt → ...declarative/lsp/tapi/ConnectionHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...lsp/modelutils/LocationMatchingVisitor.kt → ...ve/lsp/visitor/LocationMatchingVisitor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<configuration> | ||
<appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender"> | ||
<target>System.err</target> | ||
<encoder> | ||
<pattern>%date [%thread] - 5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<logger name="org.apache" level="INFO "> | ||
<appender-ref ref="STDERR"/> | ||
</logger> | ||
</configuration> |