|
| 1 | +/* |
| 2 | + * This file is a part of BSL Language Server. |
| 3 | + * |
| 4 | + * Copyright (c) 2018-2024 |
| 5 | + * Alexey Sosnoviy <labotamy@gmail.com>, Nikita Fedkin <nixel2007@gmail.com> and contributors |
| 6 | + * |
| 7 | + * SPDX-License-Identifier: LGPL-3.0-or-later |
| 8 | + * |
| 9 | + * BSL Language Server is free software; you can redistribute it and/or |
| 10 | + * modify it under the terms of the GNU Lesser General Public |
| 11 | + * License as published by the Free Software Foundation; either |
| 12 | + * version 3.0 of the License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * BSL Language Server is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | + * Lesser General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU Lesser General Public |
| 20 | + * License along with BSL Language Server. |
| 21 | + */ |
| 22 | +package com.github._1c_syntax.bsl.languageserver.hover; |
| 23 | + |
| 24 | +import com.github._1c_syntax.bsl.languageserver.context.symbol.AnnotationSymbol; |
| 25 | +import com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol; |
| 26 | +import lombok.RequiredArgsConstructor; |
| 27 | +import org.eclipse.lsp4j.MarkupContent; |
| 28 | +import org.eclipse.lsp4j.MarkupKind; |
| 29 | +import org.eclipse.lsp4j.SymbolKind; |
| 30 | +import org.springframework.stereotype.Component; |
| 31 | + |
| 32 | +import java.util.StringJoiner; |
| 33 | + |
| 34 | +/** |
| 35 | + * Построитель контента для всплывающего окна для {@link AnnotationSymbol}. |
| 36 | + */ |
| 37 | +@Component |
| 38 | +@RequiredArgsConstructor |
| 39 | +public class AnnotationSymbolMarkupContentBuilder implements MarkupContentBuilder<AnnotationSymbol> { |
| 40 | + |
| 41 | + private final DescriptionFormatter descriptionFormatter; |
| 42 | + |
| 43 | + @Override |
| 44 | + public MarkupContent getContent(AnnotationSymbol symbol) { |
| 45 | + var maybeMethodSymbol = symbol.getParent(); |
| 46 | + if (maybeMethodSymbol.filter(MethodSymbol.class::isInstance).isEmpty()) { |
| 47 | + return new MarkupContent(MarkupKind.MARKDOWN, ""); |
| 48 | + } |
| 49 | + |
| 50 | + var markupBuilder = new StringJoiner("\n"); |
| 51 | + var methodSymbol = (MethodSymbol) maybeMethodSymbol.get(); |
| 52 | + |
| 53 | + // сигнатура |
| 54 | + // местоположение метода |
| 55 | + // описание метода |
| 56 | + // параметры |
| 57 | + // примеры |
| 58 | + // варианты вызова |
| 59 | + |
| 60 | + // сигнатура |
| 61 | + String signature = descriptionFormatter.getSignature(symbol, methodSymbol); |
| 62 | + descriptionFormatter.addSectionIfNotEmpty(markupBuilder, signature); |
| 63 | + |
| 64 | + // местоположение метода |
| 65 | + String methodLocation = descriptionFormatter.getLocation(methodSymbol); |
| 66 | + descriptionFormatter.addSectionIfNotEmpty(markupBuilder, methodLocation); |
| 67 | + |
| 68 | + // описание метода |
| 69 | + String purposeSection = descriptionFormatter.getPurposeSection(methodSymbol); |
| 70 | + descriptionFormatter.addSectionIfNotEmpty(markupBuilder, purposeSection); |
| 71 | + |
| 72 | + // параметры |
| 73 | + String parametersSection = descriptionFormatter.getParametersSection(methodSymbol); |
| 74 | + descriptionFormatter.addSectionIfNotEmpty(markupBuilder, parametersSection); |
| 75 | + |
| 76 | + // примеры |
| 77 | + String examplesSection = descriptionFormatter.getExamplesSection(methodSymbol); |
| 78 | + descriptionFormatter.addSectionIfNotEmpty(markupBuilder, examplesSection); |
| 79 | + |
| 80 | + // варианты вызова |
| 81 | + String callOptionsSection = descriptionFormatter.getCallOptionsSection(methodSymbol); |
| 82 | + descriptionFormatter.addSectionIfNotEmpty(markupBuilder, callOptionsSection); |
| 83 | + |
| 84 | + String content = markupBuilder.toString(); |
| 85 | + |
| 86 | + return new MarkupContent(MarkupKind.MARKDOWN, content); |
| 87 | + } |
| 88 | + |
| 89 | + @Override |
| 90 | + public SymbolKind getSymbolKind() { |
| 91 | + return SymbolKind.TypeParameter; |
| 92 | + } |
| 93 | + |
| 94 | +} |
0 commit comments