use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class FormatProviderTest method testRangeFormat.
@Test
void testRangeFormat() throws IOException {
// given
int startLine = 4;
int endLine = 25;
DocumentRangeFormattingParams params = new DocumentRangeFormattingParams();
params.setTextDocument(getTextDocumentIdentifier());
params.setRange(Ranges.create(startLine, 0, endLine, 0));
params.setOptions(new FormattingOptions(4, true));
String fileContent = FileUtils.readFileToString(getTestFile(), StandardCharsets.UTF_8);
String formattedFileContent = FileUtils.readFileToString(getFormattedTestFile(), StandardCharsets.UTF_8);
String[] strings = formattedFileContent.split("\n");
StringJoiner joiner = new StringJoiner("\n");
for (int i = 0; i < strings.length; i++) {
if (i < startLine || i > endLine) {
continue;
}
joiner.add(strings[i]);
}
formattedFileContent = joiner.toString();
DocumentContext documentContext = TestUtils.getDocumentContext(URI.create(params.getTextDocument().getUri()), fileContent);
// when
List<TextEdit> textEdits = formatProvider.getRangeFormatting(params, documentContext);
// then
assertThat(textEdits).hasSize(1);
TextEdit textEdit = textEdits.get(0);
assertThat(textEdit.getNewText()).isEqualTo(formattedFileContent);
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class HoverProviderTest method testSourceDefinedVariable.
@Test
void testSourceDefinedVariable() {
// given
DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
HoverParams params = new HoverParams();
params.setPosition(new Position(6, 15));
// when
Optional<Hover> optionalHover = hoverProvider.getHover(documentContext, params);
// then
assertThat(optionalHover).isPresent();
var hover = optionalHover.get();
assertThat(hover.getContents().getRight().getValue()).isNotEmpty();
assertThat(hover.getRange()).isEqualTo(Ranges.create(6, 10, 20));
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class HoverProviderTest method testSourceDefinedMethod.
@Test
void testSourceDefinedMethod() {
// given
DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
HoverParams params = new HoverParams();
params.setPosition(new Position(3, 10));
// when
Optional<Hover> optionalHover = hoverProvider.getHover(documentContext, params);
// then
assertThat(optionalHover).isPresent();
var hover = optionalHover.get();
assertThat(hover.getContents().getRight().getValue()).isNotEmpty();
assertThat(hover.getRange()).isEqualTo(Ranges.create(3, 8, 18));
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class ReferencesProviderTest method testMethodsFromManagerModule.
@Test
void testMethodsFromManagerModule() {
DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
var managerModule = serverContext.getDocument("Catalog.Справочник1", ModuleType.ManagerModule).orElseThrow();
var params = new ReferenceParams();
params.setPosition(new Position(24, 15));
// when
var references = referencesProvider.getReferences(managerModule, params);
// then
var location = new Location(documentContext.getUri().toString(), Ranges.create(6, 24, 38));
assertThat(references).isNotEmpty().contains(location);
}
use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project bsl-language-server by 1c-syntax.
the class ReferencesProviderTest method testLocalMethods.
@Test
void testLocalMethods() {
DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
var params = new ReferenceParams();
params.setPosition(new Position(0, 10));
// when
var references = referencesProvider.getReferences(documentContext, params);
// then
assertThat(references).hasSize(1);
var reference = references.get(0);
assertThat(reference.getUri()).isEqualTo(documentContext.getUri().toString());
assertThat(reference.getRange()).isEqualTo(Ranges.create(4, 0, 10));
}
Aggregations