Skip to content

Commit

Permalink
1.3.25 #100 删除disableLogger以免忽略某些重要的报错
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonKnightOfBreeze committed Nov 25, 2024
1 parent 59d81cd commit e8498d6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 32 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
* [X] 兼容脚本文件中的内联模版表达式(如,`has_ethic = ethic_[[fanatic]fanatic_]pacifist`
* [X] #96
* [X] #97 兼容VIC3中的定义(define)引用(对应新的规则类型`$define_reference`
* [X] #100 删除`disableLogger`以免忽略某些重要的报错

***

* [X] Compatible with inline template expressions in script files (e.g., `has_ethic = ethic_[[fanatic]fanatic_]pacifist`)
* [X] #96
* [X] #97 Support Vic3 define references (corresponding to new data type `$define_reference`)
* [X] #100 Remove `disableLogger` to avoid ignoring some important errors.

## 1.3.24

Expand Down
9 changes: 9 additions & 0 deletions notes/优化笔记.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,13 @@ icu.windea.pls.localisation.psi.ParadoxLocalisationFile 69 69 4.42KB 22.89MB
icu.windea.pls.model.elementInfo.ParadoxModifierInfo 4,612 147.58KB 11.32MB
icu.windea.pls.config.CwtConfigContext 23,043 921.72KB 10.15MB
icu.windea.pls.model.ParadoxFileInfo 32,696 1.05MB 9.46MB
```

## 兼容

### 备注

```
since 223-EAP, call 'VfsUtil.findFile(Path, boolean)' may cause:
java.lang.Throwable: Slow operations are prohibited on EDT. See SlowOperations.assertSlowOperationsAreAllowed javadoc.
```
21 changes: 11 additions & 10 deletions src/main/kotlin/icu/windea/pls/core/PlatformExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,17 @@ inline fun <T, R> T.runCatchingCancelable(block: T.() -> R): Result<R> {
return runCatching(block).onFailure { if (it is ProcessCanceledException) throw it }
}

inline fun <R> disableLogger(block: () -> R): R {
val globalLogger = Logger.getLogger("") //DO NOT use Logger.getGlobalLogger(), it's incorrect
val loggerLevel = globalLogger.level
try {
globalLogger.level = Level.OFF
return block()
} finally {
globalLogger.level = loggerLevel
}
}
//removed since: https://github.com/DragonKnightOfBreeze/Paradox-Language-Support/issues/100
//inline fun <R> disableLogger(block: () -> R): R {
// val globalLogger = Logger.getLogger("") //DO NOT use Logger.getGlobalLogger(), it's incorrect
// val loggerLevel = globalLogger.level
// try {
// globalLogger.level = Level.OFF
// return block()
// } finally {
// globalLogger.level = loggerLevel
// }
//}

fun TextRange.unquote(text: String): TextRange {
val leftQuoted = text.isLeftQuoted()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,12 @@ class FileRenderCodeInjector : CodeInjectorBase() {

@InjectMethod(pointer = InjectMethod.Pointer.AFTER, static = true)
fun customize(renderer: SimpleColoredComponent, value: Any) {
doCustomizeCatching(value, renderer)
}

private fun doCustomizeCatching(value: Any, renderer: SimpleColoredComponent) {
disableLogger {
runCatchingCancelable {
if (doCustomize(value, renderer)) return
}
runCatchingCancelable {
if (doCustomize(renderer, value)) return
}
}

private fun doCustomize(value: Any, renderer: SimpleColoredComponent): Boolean {
private fun doCustomize(renderer: SimpleColoredComponent, value: Any): Boolean {
val file = when {
value is FileNode -> value.file
value is VirtualFile -> value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ object ParadoxCoreManager {
private fun doGetRootInfo(rootFile: VirtualFile): ParadoxRootInfo? {
//尝试从此目录向下查找descriptor.mod
run {
val descriptorFile = disableLogger { getDescriptorFile(rootFile) } ?: return@run
val descriptorFile = runReadAction { getDescriptorFile(rootFile) } ?: return@run
val descriptorInfo = getDescriptorInfo(descriptorFile) ?: return null
return ParadoxModRootInfo(rootFile, descriptorFile, descriptorInfo)
}

//尝试从此目录向下查找launcher-settings.json,如果找到,再根据"dlcPath"的值获取游戏文件的根目录
//注意游戏文件的根目录可能是此目录的game子目录,而非此目录自身
run {
val launcherSettingsFile = disableLogger { getLauncherSettingsFile(rootFile) } ?: return@run
val launcherSettingsFile = runReadAction { getLauncherSettingsFile(rootFile) } ?: return@run
val launcherSettingsInfo = getLauncherSettingsInfo(launcherSettingsFile) ?: return null
return ParadoxGameRootInfo(rootFile, launcherSettingsFile, launcherSettingsInfo)
}
Expand Down Expand Up @@ -141,9 +141,7 @@ object ParadoxCoreManager {
//尝试兼容某些file是LightVirtualFile的情况(例如,file位于VCS DIFF视图中)
if (file is LightVirtualFile) {
file.originalFile?.let { return it }
//since 223-EAP, call 'VfsUtil.findFile(Path, boolean)' may cause:
//java.lang.Throwable: Slow operations are prohibited on EDT. See SlowOperations.assertSlowOperationsAreAllowed javadoc.
disableLogger { VfsUtil.findFile(filePath, false) }?.let { return it }
runReadAction { VfsUtil.findFile(filePath, false) }?.let { return it }
return null
}
return file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,16 @@ object ParadoxExpressionMatcher {
}

private fun doGetCatching(): Boolean {
//it's necessary to suppress outputting error logs and throwing exceptions here
//it should be necessary to suppress outputting error logs and throwing exceptions here

//java.lang.Throwable: Indexing process should not rely on non-indexed file data.
//java.lang.AssertionError: Reentrant indexing
//com.intellij.openapi.project.IndexNotReadyException

return disableLogger {
runCatchingCancelable {
@Suppress("UNCHECKED_CAST")
(value as () -> Boolean)()
}.getOrDefault(true)
}
return runCatchingCancelable {
@Suppress("UNCHECKED_CAST")
(value as () -> Boolean)()
}.getOrDefault(true)
}
}

Expand Down

0 comments on commit e8498d6

Please sign in to comment.