Skip to content

Commit 9df6024

Browse files
authored
Merge pull request #3364 from 1c-syntax/feature/annotation-hover
Всплывающая подсказка и переход к определениям для аннотаций в OneScript
2 parents c80915a + fff4668 commit 9df6024

18 files changed

+835
-343
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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.context.symbol;
23+
24+
import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
25+
import com.github._1c_syntax.bsl.languageserver.context.symbol.description.MethodDescription;
26+
import lombok.Builder;
27+
import lombok.EqualsAndHashCode;
28+
import lombok.Setter;
29+
import lombok.ToString;
30+
import lombok.Value;
31+
import lombok.experimental.NonFinal;
32+
import org.eclipse.lsp4j.Range;
33+
import org.eclipse.lsp4j.SymbolKind;
34+
35+
import java.util.Collections;
36+
import java.util.List;
37+
import java.util.Optional;
38+
39+
@Value
40+
@Builder
41+
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
42+
@ToString(exclude = {"parent"})
43+
public class AnnotationSymbol implements SourceDefinedSymbol, Describable {
44+
45+
String name;
46+
47+
SymbolKind symbolKind;
48+
49+
@EqualsAndHashCode.Include
50+
DocumentContext owner;
51+
52+
Range range;
53+
54+
@EqualsAndHashCode.Include
55+
Range selectionRange;
56+
57+
@Setter
58+
@NonFinal
59+
@Builder.Default
60+
Optional<SourceDefinedSymbol> parent = Optional.empty();
61+
62+
Optional<MethodDescription> description;
63+
64+
@Override
65+
public List<SourceDefinedSymbol> getChildren() {
66+
return Collections.emptyList();
67+
}
68+
69+
@Override
70+
public void accept(SymbolTreeVisitor visitor) {
71+
// no-op
72+
}
73+
74+
public static AnnotationSymbol from(String name, MethodSymbol methodSymbol) {
75+
return AnnotationSymbol.builder()
76+
.name(name)
77+
.symbolKind(SymbolKind.TypeParameter)
78+
.owner(methodSymbol.getOwner())
79+
.range(methodSymbol.getRange())
80+
.selectionRange(methodSymbol.getSelectionRange())
81+
.description(methodSymbol.getDescription())
82+
.parent(Optional.of(methodSymbol))
83+
.build();
84+
}
85+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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

Comments
 (0)