Skip to content

Commit 65f3d0a

Browse files
authored
Merge pull request #3781 from 1c-syntax/feature/fixes260116
Исправления замечаний сонара
2 parents cbf9bc9 + 47117b5 commit 65f3d0a

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

src/main/java/com/github/_1c_syntax/bsl/languageserver/providers/SemanticTokensProvider.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,11 @@ private static List<SemanticTokensEdit> computeEdits(int[] prev, int[] curr) {
392392
* При вставке текста без перевода строки (lineOffset == 0), первый токен
393393
* может иметь смещённый deltaStart.
394394
*/
395-
private static int findSuffixMatchWithOffset(int[] prev, int[] curr, int firstDiffToken, int lineOffset, int tokenSize) {
395+
private static int findSuffixMatchWithOffset(int[] prev,
396+
int[] curr,
397+
int firstDiffToken,
398+
int lineOffset,
399+
int tokenSize) {
396400
final int DELTA_LINE_INDEX = 0;
397401
final int DELTA_START_INDEX = 1;
398402

src/main/java/com/github/_1c_syntax/bsl/languageserver/semantictokens/BslDocSemanticTokensSupplier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ private void addBslDocTokensWithMultilineSupport(
158158
String lineText = lines[lineIdx];
159159
int charOffset = (lineIdx == 0) ? fileStartChar : 0;
160160

161-
var lineElements = elementsByLine.getOrDefault(lineIdx, List.of());
161+
var lineElements = elementsByLine.getOrDefault(fileLine, List.of());
162162

163163
if (lineElements.isEmpty()) {
164164
int startLineIdx = lineIdx;
165165

166166
while (lineIdx < lines.length) {
167-
var nextLineElements = elementsByLine.getOrDefault(lineIdx, List.of());
167+
var nextLineElements = elementsByLine.getOrDefault(fileLine, List.of());
168168
if (!nextLineElements.isEmpty()) {
169169
break;
170170
}

src/main/java/com/github/_1c_syntax/bsl/languageserver/semantictokens/PreprocessorSemanticTokensSupplier.java

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -102,34 +102,38 @@ private void addDirectives(List<SemanticTokenEntry> entries, BSLParser.FileConte
102102
// excluding region start/end, native, use (handled as Namespace)
103103
private void addOtherPreprocs(List<SemanticTokenEntry> entries, BSLParser.FileContext ast) {
104104
for (var preprocessor : Trees.<BSLParser.PreprocessorContext>findAllRuleNodes(ast, BSLParser.RULE_preprocessor)) {
105-
boolean containsRegion = (preprocessor.regionStart() != null) || (preprocessor.regionEnd() != null);
105+
var containsRegion = (preprocessor.regionStart() != null) || (preprocessor.regionEnd() != null);
106106
if (containsRegion) {
107107
continue; // region handled as Namespace above
108108
}
109109

110-
// Find HASH token and keyword tokens to combine them into single token
111-
Token hashToken = null;
112-
boolean firstKeywordCombined = false;
110+
addOtherPreprocs(entries, preprocessor);
111+
}
112+
}
113113

114-
for (Token token : Trees.getTokens(preprocessor)) {
115-
if (token.getChannel() != Token.DEFAULT_CHANNEL) {
116-
continue;
117-
}
118-
if (token.getType() == BSLLexer.HASH) {
119-
hashToken = token;
120-
} else {
121-
String symbolicName = BSLLexer.VOCABULARY.getSymbolicName(token.getType());
122-
if (symbolicName != null && symbolicName.startsWith("PREPROC_")) {
123-
// Track keyword tokens for combining with HASH
124-
if (hashToken != null && !firstKeywordCombined) {
125-
// First keyword after HASH - combine them into single token
126-
helper.addRange(entries, Ranges.create(hashToken, token), SemanticTokenTypes.Macro);
127-
firstKeywordCombined = true;
128-
} else {
129-
// Subsequent keywords (e.g., "Сервер", "Тогда" in "#Если Сервер Тогда")
130-
// or keyword without preceding HASH (shouldn't happen in valid syntax)
131-
helper.addRange(entries, Ranges.create(token), SemanticTokenTypes.Macro);
132-
}
114+
private void addOtherPreprocs(List<SemanticTokenEntry> entries, BSLParser.PreprocessorContext preprocessor) {
115+
// Find HASH token and keyword tokens to combine them into single token
116+
Token hashToken = null;
117+
var firstKeywordCombined = false;
118+
119+
for (Token token : Trees.getTokens(preprocessor)) {
120+
if (token.getChannel() != Token.DEFAULT_CHANNEL) {
121+
continue;
122+
}
123+
if (token.getType() == BSLLexer.HASH) {
124+
hashToken = token;
125+
} else {
126+
var symbolicName = BSLLexer.VOCABULARY.getSymbolicName(token.getType());
127+
if (symbolicName != null && symbolicName.startsWith("PREPROC_")) {
128+
// Track keyword tokens for combining with HASH
129+
if (hashToken != null && !firstKeywordCombined) {
130+
// First keyword after HASH - combine them into single token
131+
helper.addRange(entries, Ranges.create(hashToken, token), SemanticTokenTypes.Macro);
132+
firstKeywordCombined = true;
133+
} else {
134+
// Subsequent keywords (e.g., "Сервер", "Тогда" in "#Если Сервер Тогда")
135+
// or keyword without preceding HASH (shouldn't happen in valid syntax)
136+
helper.addRange(entries, Ranges.create(token), SemanticTokenTypes.Macro);
133137
}
134138
}
135139
}

0 commit comments

Comments
 (0)