-
Notifications
You must be signed in to change notification settings - Fork 121
Add configurable template function highlighting for semantic tokens #3714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nixel2007
merged 15 commits into
develop
from
copilot/refactor-string-function-parameters
Dec 30, 2025
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7154dc6
Initial plan
Copilot 9e98aa5
Add configurable template function highlighting for semantic tokens
Copilot 0c6881a
Address code review: add null safety checks
Copilot dfe9a0e
Merge branch 'develop' into copilot/refactor-string-function-parameters
nixel2007 b564116
Remove non-documented methods from strTemplateMethods defaults
Copilot 2d52ed8
Add local call methods to strTemplateMethods defaults
Copilot e2dac8b
Add event listener for configuration changes in StringSemanticTokensS…
Copilot 359b714
Move ParsedStrTemplateMethods to separate class and clean up null checks
Copilot 799e037
Merge branch 'develop' into copilot/refactor-string-function-parameters
nixel2007 d81c817
Refactor StringSemanticTokensSupplierTest to use SemanticTokensTestHe…
Copilot f20814e
Fix imports in SemanticTokensOptions
Copilot c003a24
Rewrite all tests to use ExpectedToken pattern
Copilot e8e067d
Add tests for case-insensitive method name matching
Copilot bc8faac
Add setter-based caching for SemanticTokensOptions and unit tests
Copilot 8aec16e
Initialize parsedStrTemplateMethods field directly to avoid null check
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
.../_1c_syntax/bsl/languageserver/configuration/semantictokens/ParsedStrTemplateMethods.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ) { | ||
| } |
128 changes: 128 additions & 0 deletions
128
...hub/_1c_syntax/bsl/languageserver/configuration/semantictokens/SemanticTokensOptions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| * Формат: "ИмяМодуля.ИмяМетода", например: | ||
nixel2007 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * <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); | ||
| } | ||
| } | ||
28 changes: 28 additions & 0 deletions
28
...a/com/github/_1c_syntax/bsl/languageserver/configuration/semantictokens/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
LanguageServerConfigurationTestshould be updated to include verification thatSemanticTokensOptionsis properly initialized and configured. Similar to howInlayHintOptionsandCodeLensOptionsare tested intestPartialInitialization(), add assertions to verify that the newsemanticTokensOptionsfield is correctly loaded from configuration files and has appropriate defaults.