Skip to content

Commit

Permalink
Fix TranslationIndex#hasDefaultTranslations impl
Browse files Browse the repository at this point in the history
Also fixes ktlint complaints
  • Loading branch information
RedNesto committed Dec 16, 2023
1 parent 3e28b81 commit 2f32b1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,14 @@ class TranslationEditorNotificationProvider : EditorNotificationProvider {
return null
}

val hasDefaultTranslations = TranslationIndex.hasDefaultTranslations(project, file.mcDomain)
val hasMcpModule = file.findPsiFile(project)?.findMcpModule() != null
return Function {
createNotificationPanel(missingTranslations, hasDefaultTranslations, hasMcpModule, file, project)
createNotificationPanel(missingTranslations, hasMcpModule, file, project)
}
}

private fun createNotificationPanel(
missingTranslations: Sequence<Translation>,
hasDefaultTranslations: Boolean,
hasMcpModule: Boolean,
file: VirtualFile,
project: Project
Expand Down Expand Up @@ -97,12 +95,7 @@ class TranslationEditorNotificationProvider : EditorNotificationProvider {
.ask(project)
if (sort) {
try {
TranslationSorter.query(
project,
psi,
hasDefaultTranslations,
Ordering.LIKE_DEFAULT
)
TranslationSorter.query(project, psi, true, Ordering.LIKE_DEFAULT)
} catch (e: Exception) {
Notification(
"Translations sorting error",
Expand Down
11 changes: 8 additions & 3 deletions src/main/kotlin/translations/index/TranslationIndex.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ class TranslationIndex : FileBasedIndexExtension<String, TranslationIndexEntry>(
getProjectDefaultEntries(project, domain).flatten()

fun hasDefaultTranslations(project: Project, domain: String? = null): Boolean {
return !FileBasedIndex.getInstance().processValues(NAME, TranslationConstants.DEFAULT_LOCALE, null, { _, entry ->
return@processValues entry.sourceDomain == domain
}, GlobalSearchScope.projectScope(project))
return !FileBasedIndex.getInstance()
.processValues(
NAME,
TranslationConstants.DEFAULT_LOCALE,
null,
{ _, entry -> entry.sourceDomain != domain },
GlobalSearchScope.projectScope(project)
)
}

fun getTranslations(project: Project, file: VirtualFile): Sequence<Translation> {
Expand Down

0 comments on commit 2f32b1f

Please sign in to comment.