Поддержка семантической подсветки лямбд внутри строковых литералов (sfaqer/lambdas)#3860
Draft
Поддержка семантической подсветки лямбд внутри строковых литералов (sfaqer/lambdas)#3860
Conversation
Adds support for the sfaqer/lambdas library by parsing BSL code inside string parameters of configurable lambda methods (e.g., Лямбда.Выражение). Changes: - Add LAMBDA context to StringContext enum - Add lambdaMethods configuration to SemanticTokensOptions - Extend SpecialContextVisitor to detect lambda method calls - Add processLambdaString in StringSemanticTokensSupplier using BSL lexer - Update JSON schema with lambdaMethods property - Add tests for lambda semantic highlighting and configuration Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com> Agent-Logs-Url: https://github.com/1c-syntax/bsl-language-server/sessions/bb8c052a-c688-4797-ac97-7de78ede20a0
…rder Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com> Agent-Logs-Url: https://github.com/1c-syntax/bsl-language-server/sessions/bb8c052a-c688-4797-ac97-7de78ede20a0
Copilot
AI
changed the title
[WIP] Add support for semantic highlighting of lambdas in string literals
Поддержка семантической подсветки лямбд внутри строковых литералов (sfaqer/lambdas)
Mar 23, 2026
Integrate lambda highlighting into StringSemanticTokensSupplier using the same architecture as queries/NStr/StrTemplate (token splitting). Changes: - Remove standalone LambdaStringSemanticTokensSupplier - Detect lambdas via -> regex in any string (OS files only) - Tokenize lambda body with BSLTokenizer (not raw BSLLexer) - Highlight lambda parameters as Parameter type - Highlight parentheses, commas and arrow as Operator type - Split string tokens around lambda sub-tokens to prevent overlap Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ual DocumentContext Instead of manually tokenizing the lambda body and mapping token types, create a position-padded virtual DocumentContext (like QueryComputer does for SDBL queries) and call ALL other semantic token suppliers on it. Benefits: - Free highlighting of nested strings, NStr, StrTemplate, queries - Automatic support for any future supplier additions - Removes manual token type mapping (LAMBDA_NUMBER_TYPES, etc.) Position preservation uses the same technique as queries: pad with empty lines and spaces so tokenizer output positions match the original document. Double quotes are replaced preserving positions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace simple "" → " with the alternating pattern from QueryComputer.removeDoubleQuotes: opening "" → ' "' (space+quote), closing "" → '" ' (quote+space). This correctly unescapes double quotes while preserving character positions for the BSL tokenizer. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…da bodies VSCode applies TextMate string.quoted.double.bsl scope to entire string literals, coloring gaps between semantic tokens green. Add custom 'source' token type to the legend that VSCode doesn't recognize, causing it to render those gaps with default foreground color instead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Test Results1 944 files 1 944 suites 49m 14s ⏱️ Results for commit ad8587e. ♻️ This comment has been updated with latest results. |
…ghlighting Wrap the lambda body in a fake 'Функция _Лямбда(params) Возврат ... КонецФункции' so the BSL parser builds proper AST nodes and SymbolsSemanticTokensSupplier highlights parameter references in the body. Add SOURCE custom token type to override TextMate string scope in lambda body gaps. Use UUID for virtual document URIs to avoid collisions in parallel execution. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove PROCESSING_LAMBDA ThreadLocal and the filter(s != this) exclusion. StringSemanticTokensSupplier now processes virtual documents like any other, enabling recursive highlighting of lambdas nested inside lambda bodies. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…mbda support - Add semantic token mapping for annotation tokens in lambda parameters: AMPERSAND and ANNOTATION_*_SYMBOL as Decorator, STRING, DECIMAL/FLOAT, DATETIME, TRUE/FALSE/UNDEFINED/NULL, PLUS/MINUS, ASSIGN - Fix nested lambda highlighting: StringSemanticTokensSupplier was missing from allSuppliers list due to @lazy injection not including self. Replaced with lazy ApplicationContext.getBeansOfType() resolution. - Remove unused @lazy import - Add tests for annotation params and nested lambdas - Delete temporary TokenTest.java Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…rings - Add CustomSemanticTokenTypes.STRING_ESCAPE for escaped quote pairs - Register stringEscape in SemanticTokensLegend - Scan fullContent for "" pairs and add escape SubTokens - Remove overlapping body tokens when they conflict with escape tokens - Fix nested lambda support: use ApplicationContext.getBeansOfType() for lazy supplier resolution (includes StringSemanticTokensSupplier itself) - Add tests for escape highlighting in both params and body Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add collectSpecialContextSubTokens() to scan params area (left of ->) for %N placeholders (StrTemplate) and language keys (NStr) when the lambda string is inside a СтрШаблон/НСтр call. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Scan body (right of ->) for %N placeholders before adding virtual doc tokens, so removeOverlappingTokens gives placeholder tokens priority over BSL lexer's % (Operator) + 1 (Number) split. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…emoval
Body tokens from virtual document (e.g. STRINGTAIL |" ) can start
before an escape token ("") and hide it during left-to-right overlap
removal. Now removeOverlappingTokens first removes any non-escape
tokens that overlap with escape token intervals, then does the
standard sweep.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The custom SOURCE token type doesn't work in VSCode to override TextMate string scope. Replace all SOURCE gap-filling with standard SemanticTokenTypes.String and remove SOURCE from legend and CustomSemanticTokenTypes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.




Строки внутри вызовов лямбда-методов (например,
Лямбда.Выражение("Параметр -> Возврат Параметр > 5")) теперь подсвечиваются как BSL-код — с выделением ключевых слов, операторов и чисел — вместо отображения одним цветом строки.Changes
StringContext.LAMBDA— новый контекст строки; не объединяется с другими контекстами черезcombine()SemanticTokensOptions.lambdaMethods— конфигурируемый список паттерновМодуль.Метод, по умолчанию["Лямбда.Выражение"]. ПереиспользуетParsedStrTemplateMethodsдля парсинга паттерновSpecialContextVisitor— расширен третьим параметромparsedLambdaMethods; детектит лямбда-вызовы вvisitGlobalMethodCallиprocessModuleMethodCallStringSemanticTokensSupplier.processLambdaString()— извлекает содержимое строки, токенизирует черезBSLLexer, маппит BSL-токены на семантические типы (Keyword,Operator,Number), заполняет промежутки какStringschema.json— добавлено свойствоlambdaMethodsв секциюsemanticTokensExample
{ "semanticTokens": { "lambdaMethods": [ "Лямбда.Выражение", "Lambda.Expression" ] } }⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.