mirror of
https://github.com/latex-lsp/texlab.git
synced 2025-12-23 09:19:21 +00:00
Make MetadataProvider suspendable
This commit is contained in:
parent
97f6df5e35
commit
eecd78b94b
3 changed files with 9 additions and 4 deletions
|
|
@ -4,7 +4,7 @@ import org.eclipse.lsp4j.MarkupContent
|
|||
import org.eclipse.lsp4j.MarkupKind
|
||||
|
||||
object BibtexEntryTypeMetadataProvider : MetadataProvider {
|
||||
override fun getMetadata(name: String): Metadata? {
|
||||
override suspend fun getMetadata(name: String): Metadata? {
|
||||
val markdown = DOCUMENTATION_BY_NAME[name] ?: return null
|
||||
val documentation = MarkupContent().apply {
|
||||
kind = MarkupKind.MARKDOWN
|
||||
|
|
|
|||
|
|
@ -4,15 +4,20 @@ import com.fasterxml.jackson.databind.DeserializationFeature
|
|||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||
import com.fasterxml.jackson.module.kotlin.readValue
|
||||
import com.overzealous.remark.Remark
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.eclipse.lsp4j.MarkupContent
|
||||
import org.eclipse.lsp4j.MarkupKind
|
||||
import java.io.IOException
|
||||
import java.net.URL
|
||||
|
||||
object LatexComponentMetadataProvider : MetadataProvider {
|
||||
override fun getMetadata(name: String): Metadata? {
|
||||
override suspend fun getMetadata(name: String): Metadata? {
|
||||
return try {
|
||||
val json = URL("https://ctan.org/json/2.0/pkg/$name").readText()
|
||||
val json = withContext(Dispatchers.IO) {
|
||||
URL("https://ctan.org/json/2.0/pkg/$name").readText()
|
||||
}
|
||||
|
||||
val mapper = jacksonObjectMapper()
|
||||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
val result = mapper.readValue<Component>(json)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
package texlab.metadata
|
||||
|
||||
interface MetadataProvider {
|
||||
fun getMetadata(name: String): Metadata?
|
||||
suspend fun getMetadata(name: String): Metadata?
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue