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 @@ -24,6 +24,7 @@
import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration;
import com.github._1c_syntax.bsl.languageserver.context.symbol.VariableSymbol;
import com.github._1c_syntax.bsl.languageserver.context.symbol.variable.VariableDescription;
import com.github._1c_syntax.bsl.languageserver.utils.Resources;
import lombok.RequiredArgsConstructor;
import org.eclipse.lsp4j.MarkupContent;
import org.eclipse.lsp4j.MarkupKind;
Expand All @@ -41,19 +42,25 @@ public class VariableSymbolMarkupContentBuilder implements MarkupContentBuilder<

private final LanguageServerConfiguration configuration;
private final DescriptionFormatter descriptionFormatter;
private final Resources resources;

@Override
public MarkupContent getContent(VariableSymbol symbol) {
var markupBuilder = new StringJoiner("\n");

// сигнатура
// информация о переменной
// местоположение переменной
// описание переменной

// сигнатура
String signature = descriptionFormatter.getSignature(symbol);
descriptionFormatter.addSectionIfNotEmpty(markupBuilder, signature);

// информация о переменной
var variableInfo = getVariableInfo(symbol);
descriptionFormatter.addSectionIfNotEmpty(markupBuilder, variableInfo);

// местоположение переменной
var location = descriptionFormatter.getLocation(symbol);
descriptionFormatter.addSectionIfNotEmpty(markupBuilder, location);
Expand All @@ -78,4 +85,20 @@ public SymbolKind getSymbolKind() {
return SymbolKind.Variable;
}

private String getVariableInfo(VariableSymbol symbol) {
return switch (symbol.getKind()) {
case GLOBAL -> getResourceString("globalVariable");
case MODULE -> getResourceString("moduleVariable");
case LOCAL -> getResourceString("localVariable").formatted(symbol.getScope().getName());
case PARAMETER -> getResourceString("methodParameter").formatted(symbol.getScope().getName());
case DYNAMIC -> symbol.getScope().getSymbolKind() == SymbolKind.Module
? getResourceString("dynamicVariableOfModule")
: getResourceString("dynamicVariableOfMethod").formatted(symbol.getScope().getName());
};
}

private String getResourceString(String key) {
return resources.getResourceString(getClass(), key);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Variable kinds
globalVariable=Global variable
moduleVariable=Module-level variable
localVariable=Local variable of method %s
methodParameter=Parameter of method %s
dynamicVariableOfModule=Dynamic variable of module
dynamicVariableOfMethod=Dynamic variable of method %s

Copy link

Copilot AI Jan 4, 2026

Choose a reason for hiding this comment

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

The English properties file has an extra blank line at the end (line 8), while the Russian properties file ends at line 7. For consistency with other resource files in the project, both files should have the same format. Consider removing the extra blank line from the English file or adding it to the Russian file to maintain consistency.

Suggested change

Copilot uses AI. Check for mistakes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Variable kinds
globalVariable=Глобальная переменная
moduleVariable=Переменная уровня модуля
localVariable=Локальная переменная метода %s
methodParameter=Параметр метода %s
dynamicVariableOfModule=Динамическая переменная модуля
dynamicVariableOfMethod=Динамическая переменная метода %s
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,18 @@ void testFileVarContentFromDirectFile_NoComments() {

var blocks = Arrays.asList(content.split("---\n?"));

assertThat(blocks).hasSize(2);
assertThat(blocks).hasSize(3);
assertThat(blocks.get(0)).isEqualTo("""
```bsl
Перем ИмяБезОписания
```

""");
assertThat(blocks.get(1)).matches("""
assertThat(blocks.get(1)).isEqualTo("""
Переменная уровня модуля

""");
assertThat(blocks.get(2)).matches("""
\\[file://.*/src/test/resources/hover/variableSymbolMarkupContentBuilder.bsl]\\(.*src/test/resources/hover/variableSymbolMarkupContentBuilder.bsl#\\d+\\)

""");
Expand All @@ -95,18 +99,22 @@ void testFileVarContentFromDirectFile_OneCommentsStringFromRight() {

var blocks = Arrays.asList(content.split("---\n?"));

assertThat(blocks).hasSize(3);
assertThat(blocks).hasSize(4);
assertThat(blocks.get(0)).isEqualTo("""
```bsl
Перем Имя_ОписаниеСправаОднойСтрокой
```

""");
assertThat(blocks.get(1)).matches("""
\\[file://.*/src/test/resources/hover/variableSymbolMarkupContentBuilder.bsl]\\(.*src/test/resources/hover/variableSymbolMarkupContentBuilder.bsl#\\d+\\)
assertThat(blocks.get(1)).isEqualTo("""
Переменная уровня модуля

""");
assertThat(blocks.get(2)).matches("""
\\[file://.*/src/test/resources/hover/variableSymbolMarkupContentBuilder.bsl]\\(.*src/test/resources/hover/variableSymbolMarkupContentBuilder.bsl#\\d+\\)

""");
assertThat(blocks.get(3)).matches("""
описание

""");
Expand All @@ -127,19 +135,23 @@ void testMethodVarContentFromDirectFile_2_comments_strings() {

var blocks = Arrays.asList(content.split("---\n?"));

assertThat(blocks).hasSize(3);
assertThat(blocks).hasSize(4);
assertThat(blocks.get(0)).isEqualTo("""
```bsl
Перем Имя_ОписаниеСверхуДвеСтроки_Функция
```

""");
assertThat(blocks.get(1)).matches("""
assertThat(blocks.get(1)).isEqualTo("""
Локальная переменная метода ИмяФункции

""");
assertThat(blocks.get(2)).matches("""
\\[file://.*/src/test/resources/hover/variableSymbolMarkupContentBuilder.bsl.ИмяФункции]\\(.*src/test/resources/hover/variableSymbolMarkupContentBuilder.bsl#\\d+\\)

""");
// TODO баг - нет \n для многострочного описания переменной
assertThat(blocks.get(2)).matches("""
assertThat(blocks.get(3)).matches("""
описание 1 строка
2 строка

Expand All @@ -161,18 +173,22 @@ void testMethodVarContentFromDirectFile_3_comments_strings() {

var blocks = Arrays.asList(content.split("---\n?"));

assertThat(blocks).hasSize(3);
assertThat(blocks).hasSize(4);
assertThat(blocks.get(0)).isEqualTo("""
```bsl
Перем Имя_ОписаниеСверхуТриСтрокиПоследняяПустая_Функция
```

""");
assertThat(blocks.get(1)).matches("""
\\[file://.*/src/test/resources/hover/variableSymbolMarkupContentBuilder.bsl.ИмяФункции]\\(.*src/test/resources/hover/variableSymbolMarkupContentBuilder.bsl#\\d+\\)
assertThat(blocks.get(1)).isEqualTo("""
Локальная переменная метода ИмяФункции

""");
assertThat(blocks.get(2)).matches("""
\\[file://.*/src/test/resources/hover/variableSymbolMarkupContentBuilder.bsl.ИмяФункции]\\(.*src/test/resources/hover/variableSymbolMarkupContentBuilder.bsl#\\d+\\)

""");
assertThat(blocks.get(3)).matches("""
описание 1 строка
2 строка

Expand All @@ -195,14 +211,18 @@ void testContentFromObjectModule() {

var blocks = Arrays.asList(content.split("---\n?"));

assertThat(blocks).hasSize(2);
assertThat(blocks).hasSize(3);
assertThat(blocks.get(0)).isEqualTo("""
```bsl
Перем ВалютаУчета
```

""");
assertThat(blocks.get(1)).matches("\\[Catalog.Справочник1]\\(.*Catalogs/.*/Ext/ObjectModule.bsl#\\d+\\)\n\n");
assertThat(blocks.get(1)).isEqualTo("""
Переменная уровня модуля

""");
assertThat(blocks.get(2)).matches("\\[Catalog.Справочник1]\\(.*Catalogs/.*/Ext/ObjectModule.bsl#\\d+\\)\n\n");
}

}
Loading