2424import com .github ._1c_syntax .bsl .languageserver .context .symbol .ModuleSymbol ;
2525import com .github ._1c_syntax .bsl .languageserver .utils .Resources ;
2626import com .github ._1c_syntax .bsl .mdo .CommonModule ;
27- import com .github ._1c_syntax .bsl .mdo .support .ReturnValueReuse ;
28- import com .github ._1c_syntax .bsl .types .ModuleType ;
2927import lombok .RequiredArgsConstructor ;
3028import org .eclipse .lsp4j .MarkupContent ;
3129import org .eclipse .lsp4j .MarkupKind ;
4341public class ModuleSymbolMarkupContentBuilder implements MarkupContentBuilder <ModuleSymbol > {
4442
4543 private final Resources resources ;
44+ private final DescriptionFormatter descriptionFormatter ;
4645
4746 @ Override
4847 public MarkupContent getContent (ModuleSymbol symbol ) {
4948 var markupBuilder = new StringJoiner ("\n " );
5049
51- // Сигнатура модуля
52- String signature = buildSignature (symbol );
53- addSectionIfNotEmpty (markupBuilder , signature );
54-
5550 // Местоположение модуля
56- String location = buildLocation (symbol );
57- addSectionIfNotEmpty (markupBuilder , location );
51+ String moduleLocation = descriptionFormatter . getLocation (symbol );
52+ descriptionFormatter . addSectionIfNotEmpty (markupBuilder , moduleLocation );
5853
5954 // Информация о модуле из метаданных
60- String moduleInfo = buildModuleInfo (symbol );
61- addSectionIfNotEmpty (markupBuilder , moduleInfo );
55+ String moduleInfo = getModuleInfo (symbol );
56+ descriptionFormatter . addSectionIfNotEmpty (markupBuilder , moduleInfo );
6257
6358 String content = markupBuilder .toString ();
6459 return new MarkupContent (MarkupKind .MARKDOWN , content );
@@ -69,48 +64,7 @@ public SymbolKind getSymbolKind() {
6964 return SymbolKind .Module ;
7065 }
7166
72- private String buildSignature (ModuleSymbol symbol ) {
73- var documentContext = symbol .getOwner ();
74- var moduleType = documentContext .getModuleType ();
75- var moduleName = symbol .getName ();
76-
77- // Для CommonModule показываем только имя модуля
78- if (moduleType == ModuleType .CommonModule ) {
79- return String .format ("```bsl\n %s\n ```" , moduleName );
80- }
81-
82- // Для остальных типов используем mdoRef в зависимости от локали
83- var mdObject = documentContext .getMdObject ();
84- if (mdObject .isPresent ()) {
85- var mdoRefLocal = documentContext .getServerContext ()
86- .getConfiguration ()
87- .getMdoRefLocal (mdObject .get ());
88- return String .format ("```bsl\n %s\n ```" , mdoRefLocal );
89- }
90-
91- var mdoRef = documentContext .getMdoRef ();
92- return String .format ("```bsl\n %s\n ```" , mdoRef );
93- }
94-
95- private String buildLocation (ModuleSymbol symbol ) {
96- var documentContext = symbol .getOwner ();
97- var uri = documentContext .getUri ();
98-
99- // Используем локализованный mdoRef
100- var mdObject = documentContext .getMdObject ();
101- String mdoRefLocal ;
102- if (mdObject .isPresent ()) {
103- mdoRefLocal = documentContext .getServerContext ()
104- .getConfiguration ()
105- .getMdoRefLocal (mdObject .get ());
106- } else {
107- mdoRefLocal = documentContext .getMdoRef ();
108- }
109-
110- return String .format ("[%s](%s)" , mdoRefLocal , uri );
111- }
112-
113- private String buildModuleInfo (ModuleSymbol symbol ) {
67+ private String getModuleInfo (ModuleSymbol symbol ) {
11468 var documentContext = symbol .getOwner ();
11569 var mdObject = documentContext .getMdObject ();
11670
@@ -123,13 +77,13 @@ private String buildModuleInfo(ModuleSymbol symbol) {
12377 return "" ;
12478 }
12579
126- var infoBuilder = new StringJoiner ("\n " );
80+ var moduleInfoBuilder = new StringJoiner ("\n " );
12781
12882 // Комментарий
12983 var comment = commonModule .getComment ();
13084 if (!comment .isBlank ()) {
131- infoBuilder .add (comment );
132- infoBuilder .add ("" );
85+ moduleInfoBuilder .add (comment );
86+ moduleInfoBuilder .add ("" );
13387 }
13488
13589 // Флаги доступности
@@ -159,33 +113,24 @@ private String buildModuleInfo(ModuleSymbol symbol) {
159113
160114 if (!flags .isEmpty ()) {
161115 var flagsHeader = "**" + getResourceString ("availability" ) + ":** " ;
162- infoBuilder .add (flagsHeader + String .join (", " , flags ));
163- infoBuilder .add ("" );
116+ moduleInfoBuilder .add (flagsHeader + String .join (", " , flags ));
117+ moduleInfoBuilder .add ("" );
164118 }
165119
166120 // Режим повторного использования
167121 var returnValueReuse = commonModule .getReturnValuesReuse ();
168- if (returnValueReuse != ReturnValueReuse .DONT_USE ) {
169- var reuseKey = switch (returnValueReuse ) {
170- case DURING_REQUEST -> "duringRequest" ;
171- case DURING_SESSION -> "duringSession" ;
172- default -> "" ;
173- };
174- if (!reuseKey .isEmpty ()) {
175- var reuseHeader = "**" + getResourceString ("returnValuesReuse" ) + ":** " ;
176- infoBuilder .add (reuseHeader + getResourceString (reuseKey ));
177- }
178- }
122+ var reuseKey = switch (returnValueReuse ) {
123+ case DURING_REQUEST -> "duringRequest" ;
124+ case DURING_SESSION -> "duringSession" ;
125+ case DONT_USE , UNKNOWN -> "" ;
126+ };
179127
180- return infoBuilder .toString ();
181- }
182-
183- private void addSectionIfNotEmpty (StringJoiner markupBuilder , String newContent ) {
184- if (!newContent .isEmpty ()) {
185- markupBuilder .add (newContent );
186- markupBuilder .add ("" );
187- markupBuilder .add ("---" );
128+ if (!reuseKey .isEmpty ()) {
129+ var reuseHeader = "**" + getResourceString ("returnValuesReuse" ) + ":** " ;
130+ moduleInfoBuilder .add (reuseHeader + getResourceString (reuseKey ));
188131 }
132+
133+ return moduleInfoBuilder .toString ();
189134 }
190135
191136 private String getResourceString (String key ) {
0 commit comments