diff --git a/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnostic.java b/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnostic.java index f69408ce566..2c5e80f163b 100644 --- a/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnostic.java +++ b/src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnostic.java @@ -111,6 +111,10 @@ public class TypoDiagnostic extends AbstractDiagnostic { type = String.class ) private String userWordsToIgnore = DEFAULT_USER_WORDS_TO_IGNORE; + @DiagnosticParameter( + type = Boolean.class + ) + private Boolean caseInsensitive = false; @Override public void configure(Map configuration) { @@ -118,15 +122,19 @@ public void configure(Map configuration) { minWordLength = Math.max(minWordLength, DEFAULT_MIN_WORD_LENGTH); } - private Set getWordsToIgnore() { + private List getWordsToIgnore() { var delimiter = ","; String exceptions = SPACES_PATTERN.matcher(info.getResourceString("diagnosticExceptions")).replaceAll(""); if (!userWordsToIgnore.isEmpty()) { exceptions = exceptions + delimiter + SPACES_PATTERN.matcher(userWordsToIgnore).replaceAll(""); } + if (caseInsensitive) { + exceptions = exceptions.toLowerCase(); + } + return Arrays.stream(exceptions.split(delimiter)) - .collect(Collectors.toSet()); + .collect(Collectors.toList()); } private static JLanguageTool acquireLanguageTool(String lang) { @@ -140,7 +148,7 @@ private static void releaseLanguageTool(String lang, JLanguageTool languageTool) private Map> getTokensMap( DocumentContext documentContext ) { - Set wordsToIgnore = getWordsToIgnore(); + List wordsToIgnore = getWordsToIgnore(); Map> tokensMap = new HashMap<>(); Trees.findAllRuleNodes(documentContext.getAst(), rulesToFind).stream() @@ -150,12 +158,14 @@ private Map> getTokensMap( .filter(token -> !FORMAT_STRING_PATTERN.matcher(token.getText()).find()) .forEach((Token token) -> { String curText = QUOTE_PATTERN.matcher(token.getText()).replaceAll("").trim(); - String[] camelCaseSplitedWords = StringUtils.splitByCharacterTypeCamelCase(curText); + String[] camelCaseSplitWords = StringUtils.splitByCharacterTypeCamelCase(curText); - Arrays.stream(camelCaseSplitedWords) + Arrays.stream(camelCaseSplitWords) .filter(Predicate.not(String::isBlank)) .filter(element -> element.length() >= minWordLength) - .filter(Predicate.not(wordsToIgnore::contains)) + .filter(element -> wordsToIgnore.stream().noneMatch(word + -> (caseInsensitive && word.equalsIgnoreCase(element)) + || (!caseInsensitive && word.equals(element)))) .forEach(element -> tokensMap.computeIfAbsent(element, newElement -> new ArrayList<>()).add(token)); } ); diff --git a/src/main/resources/com/github/_1c_syntax/bsl/languageserver/configuration/parameters-schema.json b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/configuration/parameters-schema.json index 7eb26253098..a2c070211a8 100644 --- a/src/main/resources/com/github/_1c_syntax/bsl/languageserver/configuration/parameters-schema.json +++ b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/configuration/parameters-schema.json @@ -1766,6 +1766,12 @@ "default": 3, "type": "integer", "title": "Minimum length for checked words" + }, + "caseInsensitive": { + "description": "Excluded words are case-insensitive", + "default": false, + "type": "boolean", + "title": "Excluded words are case-insensitive" } }, "$id": "#/definitions/Typo" diff --git a/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnostic_en.properties b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnostic_en.properties index 9b511ea6574..a992d977da6 100644 --- a/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnostic_en.properties +++ b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnostic_en.properties @@ -7,4 +7,5 @@ diagnosticExceptions=Str,Autotest,Infobase,Enums,Len,Desc,Asc,Overridable,GUID,E Sys,Saas,www,yyyy,xsl,src,deserialization,Params,Archiver,Serializer,xsi,ico,epf,cfu,txt,htm,rtf,ppt,vsd,mpp,mdb,msg,rar,exe,grs,geo,jpg,bmp,\ tif,gif,png,pdf,odt,odf,odp,odg,ods,erf,docx,xlsx,pptx,utf,xsd,SRVR,saas,wsdl,Apdex,APDEX,uid,XLS,XLSX,html,TXT,ODT,Addin,DIB minWordLength=Minimum length for checked words -userWordsToIgnore=Dictionary for excluding words (comma separated) \ No newline at end of file +userWordsToIgnore=Dictionary for excluding words (comma separated) +caseInsensitive=Excluded words are case-insensitive \ No newline at end of file diff --git a/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnostic_ru.properties b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnostic_ru.properties index 205541fd218..49b0ea4cca7 100644 --- a/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnostic_ru.properties +++ b/src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnostic_ru.properties @@ -15,4 +15,5 @@ diagnosticExceptions=Автогенерируемых,Автогруппиров ,Студотряде,Субконто,Таб,Техподдержки,Токене,Транслите,Тэги,Тэгов,Убыв,Физлица,Финализировать,Фич,Хэш,Штрихкодам\ ,Штрихкодом,Штрихкоду,Мдд,Чммсс minWordLength=Минимальная длина проверяемых слов -userWordsToIgnore=Пользовательский словарь исключений (через запятую) \ No newline at end of file +userWordsToIgnore=Пользовательский словарь исключений (через запятую) +caseInsensitive=Не учитывать регистр в словаре исключений \ No newline at end of file diff --git a/src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnosticTest.java b/src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnosticTest.java index 103b99712d7..2c43b6e8801 100644 --- a/src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnosticTest.java +++ b/src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnosticTest.java @@ -83,6 +83,22 @@ void testConfigureUserWordsToIgnore() { .hasRange(8, 13, 8, 18); } + @Test + void testConfigureUserWordsToIgnoreCaseInsensitive() { + + Map configuration = diagnosticInstance.getInfo().getDefaultConfiguration(); + configuration.put("userWordsToIgnore", "ваРинаты"); + configuration.put("caseInsensitive", true); + diagnosticInstance.configure(configuration); + + List diagnostics = getDiagnostics(); + + assertThat(diagnostics).hasSize(2); + assertThat(diagnostics, true) + .hasRange(1, 13, 1, 21) + .hasRange(8, 13, 8, 18); + } + @Test void testConfigureUserWordsToIgnoreWithSpaces() { diff --git a/src/test/resources/diagnostics/TypoDiagnostic.bsl b/src/test/resources/diagnostics/TypoDiagnostic.bsl index ef1dd49ddf5..26916bab281 100644 --- a/src/test/resources/diagnostics/TypoDiagnostic.bsl +++ b/src/test/resources/diagnostics/TypoDiagnostic.bsl @@ -8,4 +8,5 @@ Возврат; Сообщить("ыть"); // срабатывание здесь ДеньНедели = Формат(ДатаКолонки, "ДФ=ддд"); // Нет срабатывания. Форматная строка + ЗапроситьДанныеОКВЭДФССВТранзакции = Истина; // Нет срабатывания. Аббревиатура КонецФункции \ No newline at end of file