Skip to content

Commit 589f2e1

Browse files
committed
Всплывающая подсказка и переход к определениям для аннотаций в OneScript
1 parent e436d19 commit 589f2e1

File tree

13 files changed

+664
-308
lines changed

13 files changed

+664
-308
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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.annotations.Annotation;
26+
import com.github._1c_syntax.bsl.languageserver.context.symbol.description.MethodDescription;
27+
import com.github._1c_syntax.bsl.languageserver.context.symbol.variable.VariableDescription;
28+
import lombok.Builder;
29+
import lombok.EqualsAndHashCode;
30+
import lombok.Getter;
31+
import lombok.Setter;
32+
import lombok.ToString;
33+
import lombok.Value;
34+
import lombok.experimental.NonFinal;
35+
import org.eclipse.lsp4j.Range;
36+
import org.eclipse.lsp4j.SymbolKind;
37+
38+
import java.util.ArrayList;
39+
import java.util.List;
40+
import java.util.Optional;
41+
42+
@Value
43+
@Builder
44+
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
45+
@ToString(exclude = {"children", "parent"})
46+
public class AnnotationSymbol implements SourceDefinedSymbol, Describable {
47+
48+
String name;
49+
50+
SymbolKind symbolKind;
51+
52+
@EqualsAndHashCode.Include
53+
DocumentContext owner;
54+
55+
Range range;
56+
57+
@EqualsAndHashCode.Include
58+
Range selectionRange;
59+
60+
@Setter
61+
@NonFinal
62+
@Builder.Default
63+
Optional<SourceDefinedSymbol> parent = Optional.empty();
64+
65+
@Builder.Default
66+
List<SourceDefinedSymbol> children = new ArrayList<>();
67+
68+
Optional<MethodDescription> description;
69+
70+
@Override
71+
public void accept(SymbolTreeVisitor visitor) {
72+
// no-op
73+
}
74+
75+
public static AnnotationSymbol from(String name, MethodSymbol methodSymbol) {
76+
return AnnotationSymbol.builder()
77+
.name(name)
78+
.symbolKind(SymbolKind.TypeParameter)
79+
.owner(methodSymbol.getOwner())
80+
.range(methodSymbol.getRange())
81+
.selectionRange(methodSymbol.getSelectionRange())
82+
.description(methodSymbol.getDescription())
83+
.parent(Optional.of(methodSymbol))
84+
.build();
85+
}
86+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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 com.github._1c_syntax.bsl.languageserver.context.symbol.ParameterDefinition;
27+
import com.github._1c_syntax.bsl.languageserver.context.symbol.description.MethodDescription;
28+
import com.github._1c_syntax.bsl.languageserver.context.symbol.description.ParameterDescription;
29+
import com.github._1c_syntax.bsl.languageserver.context.symbol.description.TypeDescription;
30+
import com.github._1c_syntax.bsl.languageserver.utils.MdoRefBuilder;
31+
import com.github._1c_syntax.bsl.languageserver.utils.Resources;
32+
import lombok.RequiredArgsConstructor;
33+
import org.eclipse.lsp4j.MarkupContent;
34+
import org.eclipse.lsp4j.MarkupKind;
35+
import org.eclipse.lsp4j.SymbolKind;
36+
import org.springframework.stereotype.Component;
37+
38+
import java.util.Collections;
39+
import java.util.HashMap;
40+
import java.util.List;
41+
import java.util.Map;
42+
import java.util.StringJoiner;
43+
import java.util.stream.Collectors;
44+
import java.util.stream.Stream;
45+
46+
/**
47+
* Построитель контента для всплывающего окна для {@link AnnotationSymbol}.
48+
*/
49+
@Component
50+
@RequiredArgsConstructor
51+
public class AnnotationSymbolMarkupContentBuilder implements MarkupContentBuilder<AnnotationSymbol> {
52+
53+
private final DescriptionFormatter descriptionFormatter;
54+
55+
@Override
56+
public MarkupContent getContent(AnnotationSymbol symbol) {
57+
var maybeMethodSymbol = symbol.getParent();
58+
if (maybeMethodSymbol.filter(MethodSymbol.class::isInstance).isEmpty()) {
59+
return new MarkupContent(MarkupKind.MARKDOWN, "");
60+
}
61+
62+
var markupBuilder = new StringJoiner("\n");
63+
var methodSymbol = (MethodSymbol) maybeMethodSymbol.get();
64+
65+
// сигнатура
66+
// местоположение метода
67+
// описание метода
68+
// параметры
69+
// примеры
70+
// варианты вызова
71+
72+
// сигнатура
73+
String signature = descriptionFormatter.getSignature(symbol, methodSymbol);
74+
descriptionFormatter.addSectionIfNotEmpty(markupBuilder, signature);
75+
76+
// местоположение метода
77+
String methodLocation = descriptionFormatter.getLocation(methodSymbol);
78+
descriptionFormatter.addSectionIfNotEmpty(markupBuilder, methodLocation);
79+
80+
// описание метода
81+
String purposeSection = descriptionFormatter.getPurposeSection(methodSymbol);
82+
descriptionFormatter.addSectionIfNotEmpty(markupBuilder, purposeSection);
83+
84+
// параметры
85+
String parametersSection = descriptionFormatter.getParametersSection(methodSymbol);
86+
descriptionFormatter.addSectionIfNotEmpty(markupBuilder, parametersSection);
87+
88+
// примеры
89+
String examplesSection = descriptionFormatter.getExamplesSection(methodSymbol);
90+
descriptionFormatter.addSectionIfNotEmpty(markupBuilder, examplesSection);
91+
92+
// варианты вызова
93+
String callOptionsSection = descriptionFormatter.getCallOptionsSection(methodSymbol);
94+
descriptionFormatter.addSectionIfNotEmpty(markupBuilder, callOptionsSection);
95+
96+
String content = markupBuilder.toString();
97+
98+
return new MarkupContent(MarkupKind.MARKDOWN, content);
99+
}
100+
101+
@Override
102+
public SymbolKind getSymbolKind() {
103+
return SymbolKind.TypeParameter;
104+
}
105+
106+
}

0 commit comments

Comments
 (0)