Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.github._1c_syntax.bsl.languageserver.configuration.formating.FormattingOptions;
import com.github._1c_syntax.bsl.languageserver.configuration.inlayhints.InlayHintOptions;
import com.github._1c_syntax.bsl.languageserver.configuration.references.ReferencesOptions;
import com.github._1c_syntax.bsl.languageserver.configuration.semantictokens.SemanticTokensOptions;
import com.github._1c_syntax.utils.Absolute;
import jakarta.annotation.PostConstruct;
import lombok.AccessLevel;
Expand Down Expand Up @@ -102,6 +103,10 @@ public class LanguageServerConfiguration {
@Setter(value = AccessLevel.NONE)
private ReferencesOptions referencesOptions = new ReferencesOptions();

@JsonProperty("semanticTokens")
@Setter(value = AccessLevel.NONE)
private SemanticTokensOptions semanticTokensOptions = new SemanticTokensOptions();
Comment on lines +106 to +108
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LanguageServerConfigurationTest should be updated to include verification that SemanticTokensOptions is properly initialized and configured. Similar to how InlayHintOptions and CodeLensOptions are tested in testPartialInitialization(), add assertions to verify that the new semanticTokensOptions field is correctly loaded from configuration files and has appropriate defaults.

Copilot uses AI. Check for mistakes.

private String siteRoot = "https://1c-syntax.github.io/bsl-language-server";
private boolean useDevSite;

Expand Down Expand Up @@ -217,5 +222,6 @@ private void copyPropertiesFrom(LanguageServerConfiguration configuration) {
PropertyUtils.copyProperties(this.documentLinkOptions, configuration.documentLinkOptions);
PropertyUtils.copyProperties(this.formattingOptions, configuration.formattingOptions);
PropertyUtils.copyProperties(this.referencesOptions, configuration.referencesOptions);
PropertyUtils.copyProperties(this.semanticTokensOptions, configuration.semanticTokensOptions);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* This file is a part of BSL Language Server.
*
* Copyright (c) 2018-2025
* Alexey Sosnoviy <[email protected]>, Nikita Fedkin <[email protected]> and contributors
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* BSL Language Server is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* BSL Language Server is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with BSL Language Server.
*/
package com.github._1c_syntax.bsl.languageserver.configuration.semantictokens;

import java.util.Map;
import java.util.Set;

/**
* Предварительно разобранные паттерны функций-шаблонизаторов.
* <p>
* Структура:
* <ul>
* <li>localMethods: Set методов для локального вызова (без модуля)</li>
* <li>moduleMethodPairs: Map из имени модуля -> Set методов этого модуля</li>
* </ul>
*
* @param localMethods Методы для локального вызова (без указания модуля)
* @param moduleMethodPairs Методы с указанием модуля (модуль -> набор методов)
*/
public record ParsedStrTemplateMethods(
Set<String> localMethods,
Map<String, Set<String>> moduleMethodPairs
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* This file is a part of BSL Language Server.
*
* Copyright (c) 2018-2025
* Alexey Sosnoviy <[email protected]>, Nikita Fedkin <[email protected]> and contributors
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* BSL Language Server is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* BSL Language Server is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with BSL Language Server.
*/
package com.github._1c_syntax.bsl.languageserver.configuration.semantictokens;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

/**
* Настройки для семантических токенов.
* <p>
* Позволяет указать дополнительные функции-шаблонизаторы строк,
* аналогичные СтрШаблон/StrTemplate, для подсветки плейсхолдеров (%1, %2 и т.д.).
*/
@Getter
@AllArgsConstructor(onConstructor = @__({@JsonCreator(mode = JsonCreator.Mode.DISABLED)}))
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class SemanticTokensOptions {

private static final List<String> DEFAULT_STR_TEMPLATE_METHODS = List.of(
// Локальный вызов
"ПодставитьПараметрыВСтроку",
"SubstituteParametersToString",
// Стандартный модуль БСП
"СтроковыеФункцииКлиентСервер.ПодставитьПараметрыВСтроку",
// Английский вариант
"StringFunctionsClientServer.SubstituteParametersToString"
);

/**
* Список паттернов "Модуль.Метод" для функций-шаблонизаторов строк.
* <p>
* Строки внутри вызовов этих функций будут подсвечиваться так же,
* как строки в СтрШаблон/StrTemplate (с выделением плейсхолдеров %1, %2 и т.д.).
* <p>
* Формат: "ИмяМодуля.ИмяМетода", например:
* <ul>
* <li>"СтроковыеФункцииКлиентСервер.ПодставитьПараметрыВСтроку"</li>
* <li>"StringFunctionsClientServer.SubstituteParametersToString"</li>
* <li>"ПодставитьПараметрыВСтроку" - для локального вызова без указания модуля</li>
* </ul>
* <p>
* По умолчанию включает стандартные варианты из БСП.
*/
private List<String> strTemplateMethods = new ArrayList<>(DEFAULT_STR_TEMPLATE_METHODS);

/**
* Кэшированные разобранные паттерны функций-шаблонизаторов.
*/
@JsonIgnore
private ParsedStrTemplateMethods parsedStrTemplateMethods = parseStrTemplateMethods(DEFAULT_STR_TEMPLATE_METHODS);

/**
* Устанавливает список паттернов функций-шаблонизаторов и пересчитывает кэш.
*
* @param strTemplateMethods Список паттернов
*/
public void setStrTemplateMethods(List<String> strTemplateMethods) {
this.strTemplateMethods = strTemplateMethods;
this.parsedStrTemplateMethods = parseStrTemplateMethods(strTemplateMethods);
}

/**
* Возвращает предварительно разобранные паттерны функций-шаблонизаторов.
*
* @return Разобранные паттерны для быстрого поиска
*/
@JsonIgnore
public ParsedStrTemplateMethods getParsedStrTemplateMethods() {
return parsedStrTemplateMethods;
}

private static ParsedStrTemplateMethods parseStrTemplateMethods(List<String> methods) {
var localMethods = new HashSet<String>();
var moduleMethodPairs = new HashMap<String, Set<String>>();

for (var pattern : methods) {
if (pattern.isBlank()) {
continue;
}
var patternLower = pattern.toLowerCase(Locale.ENGLISH);

if (patternLower.contains(".")) {
var parts = patternLower.split("\\.", 2);
if (parts.length == 2 && !parts[0].isEmpty() && !parts[1].isEmpty()) {
moduleMethodPairs
.computeIfAbsent(parts[0], k -> new HashSet<>())
.add(parts[1]);
}
} else {
localMethods.add(patternLower);
}
}

return new ParsedStrTemplateMethods(localMethods, moduleMethodPairs);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* This file is a part of BSL Language Server.
*
* Copyright (c) 2018-2025
* Alexey Sosnoviy <[email protected]>, Nikita Fedkin <[email protected]> and contributors
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* BSL Language Server is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* BSL Language Server is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with BSL Language Server.
*/
/**
* Пакет содержит настройки для семантических токенов.
*/
@NullMarked
package com.github._1c_syntax.bsl.languageserver.configuration.semantictokens;

import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
*/
package com.github._1c_syntax.bsl.languageserver.semantictokens;

import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration;
import com.github._1c_syntax.bsl.languageserver.configuration.events.LanguageServerConfigurationChangedEvent;
import com.github._1c_syntax.bsl.languageserver.configuration.semantictokens.ParsedStrTemplateMethods;
import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
import com.github._1c_syntax.bsl.languageserver.semantictokens.strings.AstTokenInfo;
import com.github._1c_syntax.bsl.languageserver.semantictokens.strings.QueryContext;
Expand All @@ -33,11 +36,13 @@
import com.github._1c_syntax.bsl.languageserver.utils.MultilingualStringAnalyser;
import com.github._1c_syntax.bsl.languageserver.utils.Ranges;
import com.github._1c_syntax.bsl.parser.BSLLexer;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.antlr.v4.runtime.Token;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.SemanticTokenTypes;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
Expand All @@ -57,6 +62,7 @@
* <li>Запросы SDBL: разбивает строки на части вокруг токенов запроса и добавляет токены SDBL</li>
* <li>НСтр/NStr: подсвечивает языковые ключи (ru=, en=)</li>
* <li>СтрШаблон/StrTemplate: подсвечивает плейсхолдеры (%1, %2)</li>
* <li>Конфигурируемые функции-шаблонизаторы: подсвечивает плейсхолдеры (%1, %2)</li>
* <li>Обычные строки: выдаёт токен для всей строки</li>
* </ul>
*/
Expand All @@ -72,6 +78,30 @@ public class StringSemanticTokensSupplier implements SemanticTokensSupplier {
);

private final SemanticTokensHelper helper;
private final LanguageServerConfiguration configuration;

private volatile ParsedStrTemplateMethods parsedStrTemplateMethods;

@PostConstruct
private void init() {
updateParsedStrTemplateMethods();
}

/**
* Обработчик события {@link LanguageServerConfigurationChangedEvent}.
* <p>
* Обновляет кэшированные паттерны функций-шаблонизаторов при изменении конфигурации.
*
* @param event Событие
*/
@EventListener
public void handleEvent(LanguageServerConfigurationChangedEvent event) {
updateParsedStrTemplateMethods();
}

private void updateParsedStrTemplateMethods() {
parsedStrTemplateMethods = configuration.getSemanticTokensOptions().getParsedStrTemplateMethods();
}

@Override
public List<SemanticTokenEntry> getSemanticTokens(DocumentContext documentContext) {
Expand Down Expand Up @@ -277,7 +307,7 @@ private void processSpecialContext(

private Map<Token, StringContext> collectSpecialStringContexts(DocumentContext documentContext) {
Map<Token, StringContext> contexts = new HashMap<>();
var visitor = new SpecialContextVisitor(contexts);
var visitor = new SpecialContextVisitor(contexts, parsedStrTemplateMethods);
visitor.visit(documentContext.getAst());
return contexts;
}
Expand Down
Loading
Loading