Skip to content

Commit

Permalink
Исправления
Browse files Browse the repository at this point in the history
  • Loading branch information
nixel2007 committed Dec 27, 2024
1 parent bd1e564 commit a155eb2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.eclipse.lsp4j.SymbolKind;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

Expand All @@ -62,11 +63,13 @@ public class AnnotationSymbol implements SourceDefinedSymbol, Describable {
@Builder.Default
Optional<SourceDefinedSymbol> parent = Optional.empty();

@Builder.Default
List<SourceDefinedSymbol> children = new ArrayList<>();

Optional<MethodDescription> description;

@Override
public List<SourceDefinedSymbol> getChildren() {
return Collections.emptyList();
}

@Override
public void accept(SymbolTreeVisitor visitor) {
// no-op
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.github._1c_syntax.bsl.languageserver.context.events.ServerContextPopulatedEvent;
import com.github._1c_syntax.bsl.languageserver.context.symbol.AnnotationSymbol;
import com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol;
import com.github._1c_syntax.bsl.languageserver.context.symbol.SymbolTree;
import com.github._1c_syntax.bsl.languageserver.context.symbol.annotations.Annotation;
import com.github._1c_syntax.bsl.languageserver.references.model.Reference;
import com.github._1c_syntax.bsl.languageserver.utils.Methods;
Expand All @@ -37,7 +36,6 @@
import com.github._1c_syntax.bsl.parser.BSLParser;
import lombok.RequiredArgsConstructor;
import org.antlr.v4.runtime.tree.TerminalNode;
import org.apache.commons.collections4.map.CaseInsensitiveMap;
import org.apache.commons.lang3.tuple.Pair;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.Position;
Expand All @@ -47,13 +45,14 @@
import java.net.URI;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

@Component
@RequiredArgsConstructor
public class AnnotationReferenceFinder implements ReferenceFinder {

private final ServerContext serverContext;
private final Map<String, AnnotationSymbol> registeredAnnotations = new CaseInsensitiveMap<>();
private final Map<String, AnnotationSymbol> registeredAnnotations = new ConcurrentHashMap<>();

@EventListener
public void handleContextRefresh(ServerContextPopulatedEvent event) {
Expand All @@ -68,9 +67,8 @@ public void handleDocumentContextChange(DocumentContextContentChangedEvent event
DocumentContext documentContext = event.getSource();
var uri = documentContext.getUri();

registeredAnnotations.values().stream()
.filter(annotationSymbol -> annotationSymbol.getOwner().getUri().equals(uri))
.forEach(annotationSymbol -> registeredAnnotations.remove(annotationSymbol.getName()));
registeredAnnotations.values()
.removeIf(annotationSymbol -> annotationSymbol.getOwner().getUri().equals(uri));

findAndRegisterAnnotation(documentContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ class AnnotationReferenceFinderTest extends AbstractServerContextAwareTest {
@Test
void findReference() {
// given
initServerContext(TestUtils.PATH_TO_METADATA);
initServerContext("./src/test/resources/references/annotations");
var documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/references/AnnotationReferenceFinder.os");

var module = documentContext.getSymbolTree().getModule();
var method = documentContext.getSymbolTree().getMethods().get(0);

// when
var optionalReference = referenceFinder.findReference(documentContext.getUri(), new Position(0, 2));
Expand All @@ -59,7 +58,7 @@ void findReference() {
.hasValueSatisfying(reference -> assertThat(reference.getSymbol().getName()).isEqualTo("ТестоваяАннотация"))
.hasValueSatisfying(reference -> assertThat(reference.getSymbol().getSymbolKind()).isEqualTo(SymbolKind.TypeParameter))
.hasValueSatisfying(reference -> assertThat(reference.getSelectionRange()).isEqualTo(Ranges.create(0, 0, 18)))
.hasValueSatisfying(reference -> assertThat(reference.getSourceDefinedSymbol().orElseThrow().getSelectionRange()).isEqualTo(method.getSelectionRange()))
.hasValueSatisfying(reference -> assertThat(reference.getSourceDefinedSymbol().orElseThrow().getSelectionRange()).isEqualTo(Ranges.create(1, 10, 28)))
;
}
}
4 changes: 3 additions & 1 deletion src/test/resources/references/AnnotationReferenceFinder.os
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
&ТестоваяАннотация
Перем ТестоваяПеременная;

&Аннотация("ТестоваяАннотация")
&ТестоваяАннотация2
Перем ТестоваяПеременная2;

Процедура ПриСозданииОбъекта()
КонецПроцедуры
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&Аннотация("ТестоваяАннотация")
Процедура ПриСозданииОбъекта()
КонецПроцедуры
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&Аннотация("ТестоваяАннотация2")
Процедура ПриСозданииОбъекта()
КонецПроцедуры

0 comments on commit a155eb2

Please sign in to comment.