Skip to content

Commit

Permalink
0.6.7 修复:Bugs in translation #6
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonKnightOfBreeze committed Aug 7, 2022
1 parent 412ef91 commit c637cd7
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 43 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
* [ ] 实现对`*.gui`文件中的GUI定义的UI预览(参考IDEA的Markdown插件的实现)
* [ ] 实现对`*.txt`文件中的定义的UI预览(参考游戏中的效果以及灰机Wiki的实现)

## 0.6 > 0.6.6
## 0.6 > 0.6.7

* [X] 更新cwt规则到最新版本(`stellaris v3.4`)(发布时始终处于最新版本)
* [X] 将CWT配置移动到项目根目录下`cwt`目录中,以便随远程GIT仓库更新CWT配置
* BUG修复:
* [X] 修复:[.${gameType} file is ignored #3](https://github.com/DragonKnightOfBreeze/Paradox-Language-Support/issues/3)
* [X] 修复:[Cyan color support in localisation #4](https://github.com/DragonKnightOfBreeze/Paradox-Language-Support/issues/4)
* [X] 修复:[Bugs in translation #6](https://github.com/DragonKnightOfBreeze/Paradox-Language-Support/issues/6)
* [X] 修复:对声明的查找使用的结果不完整(定义,本地化,参数等)
* [ ] 尝试修复:访问缓存(CachedValue)时导致的PsiInvalidElementAccessException
* [X] 尝试修复:访问缓存(CachedValue)时导致的PsiInvalidElementAccessException(限制太多,暂时避免使用)
* 代码优化:
* [X] 提供方法以及检查代码:当需要获取定义或代码块的属性/值的时候,可以获取参数表达式中的属性/值
* [X] 检查代码:同一代码块(block)中允许同时存在属性和值,且可以同时被CWT规则校验
Expand Down Expand Up @@ -113,7 +114,7 @@
* [X] 支持匹配和提示参数名(`some_effect = { PARAM = xxx }`中的`PARAM`
* [X] 优化:支持匹配、提示和解析参数,以及显示参数信息 (当可用时)
* [X] 本地化文件:支持提示和解析本地化命令作用域(commandScope)
* [ ] 优化:提示modifier时排除不匹配supported_scopes的,提示scope时排除不匹配input_scopes和output_scope的
* [X] 优化:提示modifier时排除不匹配supported_scopes的,提示scope时排除不匹配input_scopes和output_scope的
* [ ] 支持基于CWT规则校验脚本结构(仅限定义元素)
* ~~不再内置CWT配置文件,改为需要以库的方式添加到项目和模块中(Cwt Config,CWT配置)~~(没有必要提供)
* 可以通过内置的Github链接从网络下载需要的CWT配置文件(使用Git克隆远程仓库,然后保存到本地)
Expand Down
6 changes: 2 additions & 4 deletions src/main/kotlin/icu/windea/pls/StdlibExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,7 @@ data class ReversibleMap<K, V>(val map: Map<K, V>, val notReversed: Boolean = fa

fun <K, V> Map<K, V>.toReversibleMap(notReversed: Boolean) = ReversibleMap(this, notReversed)

inline fun <T> List<T>.pinned(predicate: (T) -> Boolean): List<T> {
if(this.isEmpty() || this.size == 1) return this
inline fun <T> Iterable<T>.pinned(predicate: (T) -> Boolean): List<T> {
val result = mutableListOf<T>()
var elementToPin: T? = null
for(e in this) {
Expand All @@ -810,8 +809,7 @@ inline fun <T> List<T>.pinned(predicate: (T) -> Boolean): List<T> {
return result
}

inline fun <T> List<T>.pinnedLast(predicate: (T) -> Boolean): List<T> {
if(this.isEmpty() || this.size == 1) return this
inline fun <T> Iterable<T>.pinnedLast(predicate: (T) -> Boolean): List<T> {
val result = mutableListOf<T>()
var elementToPin: T? = null
for(e in this) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/icu/windea/pls/config/cwt/CwtConfigHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ object CwtConfigHandler {
fun ProcessingContext.completeScope(result: CompletionResultSet) {
//TODO 进一步匹配scope
val lookupElements = mutableSetOf<LookupElement>()
val systemScopeConfigs = InternalConfigHandler.getSystemScopes()
val systemScopeConfigs = InternalConfigHandler.getSystemScopeMap().values
val links = configGroup.linksNotData
val outputScope = prevScope?.let { prevScope -> links[prevScope]?.takeUnless { it.outputAnyScope }?.outputScope }

Expand Down Expand Up @@ -909,7 +909,7 @@ object CwtConfigHandler {
fun ProcessingContext.completeLocalisationCommandScope(configGroup: CwtConfigGroup, result: CompletionResultSet) {
//TODO 进一步匹配scope
val lookupElements = mutableSetOf<LookupElement>()
val systemScopeConfigs = InternalConfigHandler.getSystemScopes()
val systemScopeConfigs = InternalConfigHandler.getSystemScopeMap().values
val localisationLinks = configGroup.localisationLinks
val outputScope = prevScope?.let { prevScope -> localisationLinks[prevScope]?.takeUnless { it.outputAnyScope }?.outputScope }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ class InternalConfigGroup(
val systemScopeMap: Map<@CaseInsensitive String, ParadoxSystemScopeConfig>

val locales: Array<ParadoxLocaleConfig>
val localeList: List<ParadoxLocaleConfig>
val localeMap: Map<String, ParadoxLocaleConfig>
val localeMapNotDefault: Map<String, ParadoxLocaleConfig>
val localeMapByCode: Map<String, ParadoxLocaleConfig>
val predefinedVariables: Array<ParadoxPredefinedVariableConfig>
val predefinedVariableList: List<ParadoxPredefinedVariableConfig>
val predefinedVariableMap: Map<String, ParadoxPredefinedVariableConfig>

init {
Expand Down Expand Up @@ -57,8 +56,8 @@ class InternalConfigGroup(
val codes = it.properties?.find { p -> p.key == "codes" }?.values?.mapNotNull { v -> v.stringValue }.orEmpty()
ParadoxLocaleConfig(id, description, codes, it.pointer)
}
localeList = locales.toList()
localeMap = locales.associateBy { it.id }
localeMapNotDefault = localeMap.filterKeys { it == "l_default" }
localeMapByCode = buildMap { locales.forEach { locale -> locale.codes.forEach { code -> put(code, locale) } } }

//初始化predefinedVariable数据
Expand All @@ -67,7 +66,6 @@ class InternalConfigGroup(
val description = prop.documentation.orEmpty()
ParadoxPredefinedVariableConfig(id, description, prop.pointer)
}
predefinedVariableList = predefinedVariables.toList()
predefinedVariableMap = predefinedVariables.associateBy { it.id }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ object InternalConfigHandler {
/**
* 从内置规则文件中得到指定ID的系统作用域设置。
*/
fun getSystemScope(id: String, project: Project? = null):ParadoxSystemScopeConfig? {
fun getSystemScope(id: String, project: Project? = null): ParadoxSystemScopeConfig? {
return getInternalConfig(project).systemScopeMap[id]
}

/**
* 从内置规则文件中得到所有系统作用域设置。
*/
fun getSystemScopeMap(project: Project? = null): Map<@CaseInsensitive String, ParadoxSystemScopeConfig>{
fun getSystemScopeMap(project: Project? = null): Map<@CaseInsensitive String, ParadoxSystemScopeConfig> {
return getInternalConfig(project).systemScopeMap
}

/**
* 从内置规则文件中得到所有系统作用域设置。
*/
fun getSystemScopes(project: Project? = null): Array<ParadoxSystemScopeConfig>{
fun getSystemScopes(project: Project? = null): Array<ParadoxSystemScopeConfig> {
return getInternalConfig(project).systemScopes
}
//endregion
Expand Down Expand Up @@ -57,15 +57,8 @@ object InternalConfigHandler {
/**
* 从内置规则文件中得到得到所有语言区域设置。
*/
fun getLocaleList(project: Project? = null): List<ParadoxLocaleConfig> {
return getInternalConfig(project).localeList
}

/**
* 从内置规则文件中得到得到所有语言区域设置。
*/
fun getLocaleMap(project: Project? = null): Map<String, ParadoxLocaleConfig> {
return getInternalConfig(project).localeMap
fun getLocaleMap(project: Project? = null, includeDefault: Boolean = true): Map<String, ParadoxLocaleConfig> {
return if(includeDefault) getInternalConfig(project).localeMap else getInternalConfig(project).localeMapNotDefault
}
//endregion

Expand All @@ -84,13 +77,6 @@ object InternalConfigHandler {
return getInternalConfig(project).predefinedVariables
}

/**
* 从内置规则文件中得到得到所有预定义变量设置。
*/
fun getPredefinedVariableList(project: Project? = null): List<ParadoxPredefinedVariableConfig> {
return getInternalConfig(project).predefinedVariableList
}

/**
* 从内置规则文件中得到得到所有预定义变量设置。
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ParadoxSettingsState : BaseState() {
val locales by lazy {
buildList {
add("auto")
addAll(InternalConfigHandler.getLocaleMap().keys)
addAll(InternalConfigHandler.getLocaleMap(includeDefault = false).keys)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ internal fun getLocalesToSelect(existingLocales: List<ParadoxLocaleConfig>, loca
//置顶偏好的语言区域
val preferredLocale = preferredParadoxLocale()
return if(existingLocales.isEmpty()) {
InternalConfigHandler.getLocaleList().pinned { it == preferredLocale }
InternalConfigHandler.getLocaleMap(includeDefault = false).values.pinned { it == preferredLocale }
} else {
InternalConfigHandler.getLocaleMap().values.filter { it == locale || it !in existingLocales }.pinned { it == preferredLocale }
InternalConfigHandler.getLocaleMap(includeDefault = false).values.filter { it == locale || it !in existingLocales }.pinned { it == preferredLocale }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CopyLocalisationForLocaleIntention : IntentionAction, PriorityAction {
originalElement?.parentOfType<ParadoxLocalisationProperty>() != null
} else {
val originalStartElement = file.findElementAt(selectionStart) ?: return false
val originalEndElement = file.findElementAt(selectionEnd) ?: return false
val originalEndElement = file.findElementAt(selectionEnd)
hasLocalisationPropertiesBetween(originalStartElement, originalEndElement)
}
}
Expand All @@ -66,7 +66,7 @@ class CopyLocalisationForLocaleIntention : IntentionAction, PriorityAction {
listOf(element)
} else {
val originalStartElement = file.findElementAt(selectionStart) ?: return
val originalEndElement = file.findElementAt(selectionEnd) ?: return
val originalEndElement = file.findElementAt(selectionEnd)
findLocalisationPropertiesBetween(originalStartElement, originalEndElement)
}
if(elements.isEmpty()) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CopyLocalisationIntention : IntentionAction, PriorityAction {
return originalElement?.parentOfType<ParadoxLocalisationProperty>() != null
} else {
val originalStartElement = file.findElementAt(selectionStart) ?: return false
val originalEndElement = file.findElementAt(selectionEnd) ?: return false
val originalEndElement = file.findElementAt(selectionEnd)
return hasLocalisationPropertiesBetween(originalStartElement, originalEndElement)
}
}
Expand All @@ -55,7 +55,7 @@ class CopyLocalisationIntention : IntentionAction, PriorityAction {
CopyPasteManager.getInstance().setContents(StringSelection(text))
} else {
val originalStartElement = file.findElementAt(selectionStart) ?: return
val originalEndElement = file.findElementAt(selectionEnd) ?: return
val originalEndElement = file.findElementAt(selectionEnd)
val elements = findLocalisationPropertiesBetween(originalStartElement, originalEndElement)
if(elements.isEmpty()) return
elements.forEach { keys.add(it.name) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ val ParadoxLocalisationCommandScope.commandScopeId: PsiElement get() = findRequi
val ParadoxLocalisationCommandField.commandFieldId: PsiElement? get() = findOptionalChild(COMMAND_FIELD_ID)


fun hasLocalisationPropertiesBetween(start: PsiElement, end: PsiElement): Boolean {
fun hasLocalisationPropertiesBetween(start: PsiElement, end: PsiElement?): Boolean {
val startElement = start.findParentInFile(true) { it.parent is ParadoxLocalisationPropertyList }
val endElement = end.findParentInFile(true) { it.parent is ParadoxLocalisationPropertyList }
val endElement = end?.findParentInFile(true) { it.parent is ParadoxLocalisationPropertyList }
when {
startElement == null && endElement == null -> return false
startElement == null && endElement != null -> {
Expand All @@ -68,9 +68,9 @@ fun hasLocalisationPropertiesBetween(start: PsiElement, end: PsiElement): Boolea
return false
}

fun findLocalisationPropertiesBetween(start: PsiElement, end: PsiElement): List<ParadoxLocalisationProperty> {
fun findLocalisationPropertiesBetween(start: PsiElement, end: PsiElement?): List<ParadoxLocalisationProperty> {
val startElement = start.findParentInFile(true) { it.parent is ParadoxLocalisationPropertyList }
val endElement = end.findParentInFile(true) { it.parent is ParadoxLocalisationPropertyList }
val endElement = end?.findParentInFile(true) { it.parent is ParadoxLocalisationPropertyList }
when {
startElement == null && endElement == null -> return emptyList()
startElement == null && endElement != null -> {
Expand All @@ -80,6 +80,7 @@ fun findLocalisationPropertiesBetween(start: PsiElement, end: PsiElement): List<
if(it is ParadoxLocalisationProperty) result.add(it)
it != endElement
}
return result
}
startElement != null && endElement == null -> {
val listElement = startElement.parent
Expand All @@ -88,6 +89,7 @@ fun findLocalisationPropertiesBetween(start: PsiElement, end: PsiElement): List<
if(it is ParadoxLocalisationProperty) result.add(it)
it != startElement
}
return result
}
startElement != null && endElement != null -> {
val result = mutableListOf<ParadoxLocalisationProperty>()
Expand Down

0 comments on commit c637cd7

Please sign in to comment.