mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[grazie] IJPL-33160 Spellchecker incorrectly handles english text as french
Merge-request: IJ-MR-191083 Merged-by: Ilia Permiashkin <ilia.permiashkin@jetbrains.com> GitOrigin-RevId: 657fc44c94ce2f5e1e5bf95b1fdad195c3708931
This commit is contained in:
committed by
intellij-monorepo-bot
parent
13a1755839
commit
898f8a01ab
@@ -20,27 +20,26 @@ import com.intellij.psi.util.CachedValuesManager
|
||||
private typealias DetectionResults = Map<String, ChainLanguageDetector.ChainDetectionResult>
|
||||
|
||||
object BatchLangDetector {
|
||||
private val RELIABLE_CACHE = Key.create<CachedValue<DetectionResults>>("grazie reliable language detection cache")
|
||||
private val UNRELIABLE_CACHE = Key.create<CachedValue<DetectionResults>>("grazie unreliable language detection cache")
|
||||
private val CACHE = Key.create<CachedValue<DetectionResults>>("grazie reliable language detection cache")
|
||||
|
||||
fun getLanguage(content: TextContent, offset: Int): Language? {
|
||||
val text = content.substring(offset).take(LanguageDetectorHolder.LIMIT)
|
||||
if (!NaturalTextDetector.seemsNatural(text)) return null
|
||||
val language = detectForFile(content.containingFile, false)[text]?.result?.preferred
|
||||
val language = detectForFile(content.containingFile)[text]?.result?.preferred
|
||||
return if (language == Language.UNKNOWN) null else language
|
||||
}
|
||||
|
||||
fun updateContext(file: PsiFile, context: DetectionContext.Local) {
|
||||
detectForFile(file, true).forEach { (text, details) ->
|
||||
detectForFile(file).forEach { (text, details) ->
|
||||
val wordsCount = text.words().count()
|
||||
context.update(text.length, wordsCount, details)
|
||||
}
|
||||
}
|
||||
|
||||
private fun detectForFile(file: PsiFile, isReliable: Boolean): DetectionResults =
|
||||
CachedValuesManager.getCachedValue(file, if (isReliable) RELIABLE_CACHE else UNRELIABLE_CACHE) {
|
||||
private fun detectForFile(file: PsiFile): DetectionResults =
|
||||
CachedValuesManager.getCachedValue(file, CACHE) {
|
||||
val texts = getCleanTexts(file)
|
||||
val languages = LanguageDetectorHolder.get().detectWithDetails(texts, isReliable) { ProgressManager.checkCanceled() }
|
||||
val languages = LanguageDetectorHolder.get().detectWithDetails(texts,true) { ProgressManager.checkCanceled() }
|
||||
CachedValueProvider.Result.create(texts.zip(languages).toMap(), file, grazieConfigTracker())
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.intellij.grazie.ide
|
||||
|
||||
import ai.grazie.nlp.langs.Language
|
||||
import com.intellij.grazie.GrazieTestBase
|
||||
import com.intellij.grazie.jlanguage.Lang
|
||||
import com.intellij.grazie.utils.HighlightingUtil
|
||||
import com.intellij.grazie.utils.getLanguageIfAvailable
|
||||
|
||||
internal class LanguageDetectionTest: GrazieTestBase() {
|
||||
|
||||
fun `test text in the middle is not French`() {
|
||||
enableProofreadingFor(setOf(Lang.FRENCH, Lang.AMERICAN_ENGLISH))
|
||||
myFixture.configureByText("a.java", """
|
||||
// use multiple instances within container
|
||||
|
||||
// use multiple containers
|
||||
|
||||
// use concurrent pinging within PF instance, using a worker pool
|
||||
""".trimIndent())
|
||||
myFixture.checkHighlighting()
|
||||
|
||||
HighlightingUtil.getAllFileTexts(myFixture.file.viewProvider)
|
||||
.forEach {
|
||||
val contentLanguage = getLanguageIfAvailable(it)
|
||||
assertEquals(
|
||||
"Language of `$it` expected to be English, not $contentLanguage",
|
||||
Language.ENGLISH, contentLanguage
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ class CamelCase {
|
||||
String CANopen, DBtune;
|
||||
|
||||
// My name is MacTyppoo, DBtune
|
||||
// Very very long text DBtune1
|
||||
// <GRAMMAR_ERROR descr="RB_RB_COMMA">Very very</GRAMMAR_ERROR> long text DBtune1
|
||||
// there is another word: RESTTful
|
||||
int SSIZE_MAX, MacTyppoo;
|
||||
boolean <TYPO descr="Typo: In word 'SSSIZE'">SSSIZE</TYPO>_MAX;
|
||||
|
||||
Reference in New Issue
Block a user