Add Qt doc map

This commit is contained in:
2022-09-06 19:52:52 +08:00
parent 89d6038c9f
commit c340f971d1
4 changed files with 61 additions and 19 deletions

View File

@ -1,5 +1,5 @@
plugins { plugins {
val kotlinVersion = "1.6.10" val kotlinVersion = "1.7.10"
kotlin("jvm") version kotlinVersion kotlin("jvm") version kotlinVersion
kotlin("plugin.serialization") version kotlinVersion kotlin("plugin.serialization") version kotlinVersion
@ -7,7 +7,7 @@ plugins {
} }
group = "top.jie65535" group = "top.jie65535"
version = "0.2.0" version = "0.3.0"
repositories { repositories {
maven("https://maven.aliyun.com/repository/public") // 阿里云国内代理仓库 maven("https://maven.aliyun.com/repository/public") // 阿里云国内代理仓库

Binary file not shown.

View File

@ -1,5 +0,0 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -14,13 +14,14 @@ object JCppReferencePlugin : KotlinPlugin(
JvmPluginDescription( JvmPluginDescription(
id = "top.jie65535.mirai-console-jcr-plugin", id = "top.jie65535.mirai-console-jcr-plugin",
name = "J Cpp Reference Plugin", name = "J Cpp Reference Plugin",
version = "0.2.0" version = "0.3.0"
) { ) {
author("jie65535") author("jie65535")
info("cppreference.com 帮助插件") info("C++ 参考搜索插件")
} }
) { ) {
private const val cppreferencePrefix = "https://zh.cppreference.com/w/" private const val cppreferencePrefix = "https://zh.cppreference.com/w/"
private const val qtDocPrefix = "https://doc.qt.io/qt-5/"
private fun loadMap(path: String): Map<String, String> { private fun loadMap(path: String): Map<String, String> {
val map = mutableMapOf<String, String>() val map = mutableMapOf<String, String>()
@ -28,21 +29,47 @@ object JCppReferencePlugin : KotlinPlugin(
if (stream == null) { if (stream == null) {
logger.error("资源文件为空") logger.error("资源文件为空")
} else { } else {
val br = BufferedReader(InputStreamReader(stream)) stream.use {
while (br.ready()) { val br = BufferedReader(InputStreamReader(stream))
val line = br.readLine() while (br.ready()) {
val s = line.indexOf('\t') val line = br.readLine()
if (s > 0) { val s = line.indexOf('\t')
map[line.substring(0, s)] = line.substring(s+1) if (s > 0) {
val key = line.substring(0, s)
val url = line.substring(s+1)
map.putIfAbsent(key, url)
val lowerKey = key.lowercase()
map.putIfAbsent(lowerKey, url)
}
} }
} }
splitKeys(map)
} }
logger.info("\"$path\" ${map.size} keywords loaded") logger.info("\"$path\" ${map.size} keywords loaded")
return map return map
} }
private fun splitKeys(map: MutableMap<String, String>) {
val subMap = mutableMapOf<String, String>()
for (item in map) {
val s = item.key.indexOf("::")
if (s >= 0) {
val sub = item.key.substring(s+2)
if (!map.containsKey(sub)) {
subMap[sub] = item.value
}
}
}
if (subMap.isNotEmpty()) {
splitKeys(subMap)
for (item in subMap) {
map.putIfAbsent(item.key, item.value)
}
}
}
private val indexC by lazy { loadMap("/devhelp-index-c.txt") } private val indexC by lazy { loadMap("/devhelp-index-c.txt") }
// private val indexCpp by lazy { loadMap("/devhelp-index-cpp.txt") } private val indexQt by lazy { loadMap("/qt-5.13.0.txt") }
override fun onEnable() { override fun onEnable() {
logger.info { "Plugin loaded" } logger.info { "Plugin loaded" }
@ -51,12 +78,18 @@ object JCppReferencePlugin : KotlinPlugin(
val eventChannel = GlobalEventChannel.parentScope(this) val eventChannel = GlobalEventChannel.parentScope(this)
eventChannel.subscribeMessages { eventChannel.subscribeMessages {
startsWith("c ") { keyword -> startsWith("c ") { keyword ->
if (keyword.isEmpty()) return@startsWith if (keyword.isEmpty()) return@startsWith
logger.info("check c \"$keyword\"") logger.info("check c \"$keyword\"")
val link = indexC[keyword] var cLink = indexC[keyword]
if (link != null) { if (cLink != null) {
subject.sendMessage(message.quote() + cppreferencePrefix + link) subject.sendMessage(message.quote() + cppreferencePrefix + cLink)
} else {
cLink = indexC[keyword.lowercase()]
if (cLink != null) {
subject.sendMessage(message.quote() + cppreferencePrefix + cLink)
}
} }
} }
@ -68,6 +101,20 @@ object JCppReferencePlugin : KotlinPlugin(
subject.sendMessage(message.quote() + cppreferencePrefix + index.link) subject.sendMessage(message.quote() + cppreferencePrefix + index.link)
} }
} }
startsWith("qt ") { keyword ->
if (keyword.isEmpty()) return@startsWith
logger.info("check qt \"$keyword\"")
var qtLink = indexQt[keyword]
if (qtLink != null) {
subject.sendMessage(message.quote() + qtDocPrefix + qtLink)
} else {
qtLink = indexQt[keyword.lowercase()]
if (qtLink != null) {
subject.sendMessage(message.quote() + qtDocPrefix + qtLink)
}
}
}
} }
} }
} }