Skip to content

Commit 0454275

Browse files
authored
Merge pull request #3630 from 1c-syntax/feature/feat2889
Добавление игнонирование регистра в диагностику Typo
2 parents 3fca5e0 + 97e18b4 commit 0454275

File tree

8 files changed

+83
-14
lines changed

8 files changed

+83
-14
lines changed

build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,10 @@ tasks.withType<GenerateModuleMetadata> {
448448
enabled = false
449449
}
450450

451+
tasks.register("updateLicenses") {
452+
dependsOn(tasks.licenseFormat)
453+
}
454+
451455
fun buildTime(): String {
452456
val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
453457
formatter.timeZone = TimeZone.getTimeZone("UTC")

src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnostic.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import lombok.extern.slf4j.Slf4j;
4040
import org.antlr.v4.runtime.Token;
4141
import org.apache.commons.lang3.StringUtils;
42+
import org.apache.commons.text.WordUtils;
4243
import org.languagetool.JLanguageTool;
4344
import org.languagetool.Languages;
4445
import org.languagetool.rules.RuleMatch;
@@ -48,7 +49,9 @@
4849
import java.util.Arrays;
4950
import java.util.Collections;
5051
import java.util.HashMap;
52+
import java.util.HashSet;
5153
import java.util.List;
54+
import java.util.Locale;
5255
import java.util.Map;
5356
import java.util.Set;
5457
import java.util.function.Predicate;
@@ -107,20 +110,38 @@ public class TypoDiagnostic extends AbstractDiagnostic {
107110
)
108111
private String userWordsToIgnore = DEFAULT_USER_WORDS_TO_IGNORE;
109112

113+
/**
114+
* Готовый список слов для игнорирования
115+
*/
116+
private Set<String> wordsToIgnore = new HashSet<>();
117+
118+
@DiagnosticParameter(
119+
type = Boolean.class
120+
)
121+
private Boolean caseInsensitive = false;
122+
110123
@Override
111124
public void configure(Map<String, Object> configuration) {
112125
super.configure(configuration);
113126
minWordLength = Math.max(minWordLength, DEFAULT_MIN_WORD_LENGTH);
127+
wordsToIgnore = makeWordsToIgnore();
114128
}
115129

116-
private Set<String> getWordsToIgnore() {
117-
var delimiter = ",";
118-
String exceptions = SPACES_PATTERN.matcher(info.getResourceString("diagnosticExceptions")).replaceAll("");
130+
private Set<String> makeWordsToIgnore() {
131+
char delimiter = ',';
132+
var exceptions = SPACES_PATTERN.matcher(info.getResourceString("diagnosticExceptions")).replaceAll("");
119133
if (!userWordsToIgnore.isEmpty()) {
120-
exceptions = exceptions + delimiter + SPACES_PATTERN.matcher(userWordsToIgnore).replaceAll("");
134+
exceptions += delimiter + SPACES_PATTERN.matcher(userWordsToIgnore).replaceAll("");
135+
}
136+
137+
// добавим к переданным строки в разных регистрах
138+
if (caseInsensitive && !exceptions.isEmpty()) {
139+
exceptions +=
140+
delimiter + exceptions.toLowerCase(Locale.getDefault()) // нижний регистр
141+
+ delimiter + WordUtils.capitalizeFully(exceptions, delimiter); // титульный
121142
}
122143

123-
return Arrays.stream(exceptions.split(delimiter))
144+
return Arrays.stream(exceptions.split(String.valueOf(delimiter)))
124145
.collect(Collectors.toSet());
125146
}
126147

@@ -135,7 +156,6 @@ private static void releaseLanguageTool(String lang, JLanguageTool languageTool)
135156
private Map<String, List<Token>> getTokensMap(
136157
DocumentContext documentContext
137158
) {
138-
Set<String> wordsToIgnore = getWordsToIgnore();
139159
Map<String, List<Token>> tokensMap = new HashMap<>();
140160

141161
Trees.findAllRuleNodes(documentContext.getAst(), rulesToFind).stream()
@@ -144,9 +164,9 @@ private Map<String, List<Token>> getTokensMap(
144164
.filter(token -> !FORMAT_STRING_PATTERN.matcher(token.getText()).find())
145165
.forEach((Token token) -> {
146166
String curText = QUOTE_PATTERN.matcher(token.getText()).replaceAll("").trim();
147-
String[] camelCaseSplitedWords = StringUtils.splitByCharacterTypeCamelCase(curText);
167+
String[] camelCaseSplitWords = StringUtils.splitByCharacterTypeCamelCase(curText);
148168

149-
Arrays.stream(camelCaseSplitedWords)
169+
Arrays.stream(camelCaseSplitWords)
150170
.filter(Predicate.not(String::isBlank))
151171
.filter(element -> element.length() >= minWordLength)
152172
.filter(Predicate.not(wordsToIgnore::contains))

src/main/resources/com/github/_1c_syntax/bsl/languageserver/configuration/parameters-schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,6 +1980,12 @@
19801980
"default": 3,
19811981
"type": "integer",
19821982
"title": "Minimum length for checked words"
1983+
},
1984+
"caseInsensitive": {
1985+
"description": "Excluded words are case-insensitive",
1986+
"default": false,
1987+
"type": "boolean",
1988+
"title": "Excluded words are case-insensitive"
19831989
}
19841990
},
19851991
"$id": "#/definitions/Typo"

src/main/resources/com/github/_1c_syntax/bsl/languageserver/configuration/schema.json

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -924,15 +924,30 @@
924924
"properties": {
925925
"type": {
926926
"type": "string",
927-
"enum": ["ERROR", "CODE_SMELL", "VULNERABILITY", "SECURITY_HOTSPOT"]
927+
"enum": [
928+
"ERROR",
929+
"CODE_SMELL",
930+
"VULNERABILITY",
931+
"SECURITY_HOTSPOT"
932+
]
928933
},
929934
"severity": {
930935
"type": "string",
931-
"enum": ["INFO", "MINOR", "MAJOR", "CRITICAL", "BLOCKER"]
936+
"enum": [
937+
"INFO",
938+
"MINOR",
939+
"MAJOR",
940+
"CRITICAL",
941+
"BLOCKER"
942+
]
932943
},
933944
"scope": {
934945
"type": "string",
935-
"enum": ["ALL", "BSL", "OS"]
946+
"enum": [
947+
"ALL",
948+
"BSL",
949+
"OS"
950+
]
936951
},
937952
"modules": {
938953
"type": "array",
@@ -963,7 +978,12 @@
963978
},
964979
"lspSeverity": {
965980
"type": "string",
966-
"enum": ["Error", "Warning", "Information", "Hint"],
981+
"enum": [
982+
"Error",
983+
"Warning",
984+
"Information",
985+
"Hint"
986+
],
967987
"description": "LSP severity level (Error, Warning, Information, Hint). If not specified, calculated automatically based on type and severity."
968988
}
969989
}

src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnostic_en.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ diagnosticExceptions=Str,Autotest,Infobase,Enums,Len,Desc,Asc,Overridable,GUID,E
77
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,\
88
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
99
minWordLength=Minimum length for checked words
10-
userWordsToIgnore=Dictionary for excluding words (comma separated)
10+
userWordsToIgnore=Dictionary for excluding words (comma separated)
11+
caseInsensitive=Excluded words are case-insensitive

src/main/resources/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnostic_ru.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ diagnosticExceptions=Автогенерируемых,Автогруппиров
1515
,Студотряде,Субконто,Таб,Техподдержки,Токене,Транслите,Тэги,Тэгов,Убыв,Физлица,Финализировать,Фич,Хэш,Штрихкодам\
1616
,Штрихкодом,Штрихкоду,Мдд,Чммсс
1717
minWordLength=Минимальная длина проверяемых слов
18-
userWordsToIgnore=Пользовательский словарь исключений (через запятую)
18+
userWordsToIgnore=Пользовательский словарь исключений (через запятую)
19+
caseInsensitive=Не учитывать регистр в словаре исключений

src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnosticTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ void testConfigureUserWordsToIgnore() {
8383
.hasRange(8, 13, 8, 18);
8484
}
8585

86+
@Test
87+
void testConfigureUserWordsToIgnoreCaseInsensitive() {
88+
89+
Map<String, Object> configuration = diagnosticInstance.getInfo().getDefaultConfiguration();
90+
configuration.put("userWordsToIgnore", "ваРинаты");
91+
configuration.put("caseInsensitive", true);
92+
diagnosticInstance.configure(configuration);
93+
94+
List<Diagnostic> diagnostics = getDiagnostics();
95+
96+
assertThat(diagnostics).hasSize(2);
97+
assertThat(diagnostics, true)
98+
.hasRange(1, 13, 1, 21)
99+
.hasRange(8, 13, 8, 18);
100+
}
101+
86102
@Test
87103
void testConfigureUserWordsToIgnoreWithSpaces() {
88104

src/test/resources/diagnostics/TypoDiagnostic.bsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
Возврат;
99
Сообщить("ыть"); // срабатывание здесь
1010
ДеньНедели = Формат(ДатаКолонки, "ДФ=ддд"); // Нет срабатывания. Форматная строка
11+
ЗапроситьДанныеОКВЭДФССВТранзакции = Истина; // Нет срабатывания. Аббревиатура
1112
КонецФункции

0 commit comments

Comments
 (0)