use of com.github._1c_syntax.bsl.languageserver.context.symbol.ModuleSymbol in project bsl-language-server by 1c-syntax.
the class ModuleSymbolComputerTest method testModuleName.
@Test
void testModuleName() {
// given
var documentContext = spy(TestUtils.getDocumentContextFromFile("./src/test/resources/context/symbol/ModuleSymbol.bsl"));
var computer = new ModuleSymbolComputer(documentContext);
MDOReference mdoReference = mock(MDOReference.class);
when(mdoReference.getMdoRef()).thenReturn("Document.Document1");
AbstractMDObjectBase mdObject = mock(AbstractMDObjectBase.class);
when(mdObject.getMdoReference()).thenReturn(mdoReference);
doReturn(Optional.of(mdObject)).when(documentContext).getMdObject();
// when-then pairs:
// when
doReturn(ModuleType.UNKNOWN).when(documentContext).getModuleType();
var moduleSymbol = computer.compute();
// then
assertThat(moduleSymbol.getName()).isEqualTo("Document.Document1");
// when
doReturn(ModuleType.ObjectModule).when(documentContext).getModuleType();
moduleSymbol = computer.compute();
// then
assertThat(moduleSymbol.getName()).isEqualTo("Document.Document1.ObjectModule");
// when
doReturn(ModuleType.ManagerModule).when(documentContext).getModuleType();
moduleSymbol = computer.compute();
// then
assertThat(moduleSymbol.getName()).isEqualTo("Document.Document1.ManagerModule");
}
use of com.github._1c_syntax.bsl.languageserver.context.symbol.ModuleSymbol in project bsl-language-server by 1c-syntax.
the class SymbolTreeComputer method compute.
@Override
public SymbolTree compute() {
ModuleSymbol moduleSymbol = new ModuleSymbolComputer(documentContext).compute();
List<MethodSymbol> methods = new MethodSymbolComputer(documentContext).compute();
List<RegionSymbol> regions = new RegionSymbolComputer(documentContext).compute();
List<VariableSymbol> variables = new VariableSymbolComputer(documentContext).compute();
List<SourceDefinedSymbol> allOfThem = new ArrayList<>(methods);
allOfThem.addAll(regions);
allOfThem.addAll(variables);
allOfThem.sort(Comparator.comparingInt(symbol -> symbol.getRange().getStart().getLine()));
List<SourceDefinedSymbol> topLevelSymbols = new ArrayList<>();
SourceDefinedSymbol currentParent = moduleSymbol;
for (SourceDefinedSymbol symbol : allOfThem) {
currentParent = placeSymbol(topLevelSymbols, currentParent, symbol);
}
return new SymbolTree(moduleSymbol);
}
Aggregations