use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.
the class ValidatorTest method testMultilineDiagnostic.
@Test
public void testMultilineDiagnostic() {
String model = "type Multiline_Demo {\n" + "}\n";
writeFile("MyType1.testlang", model);
initialize();
List<Diagnostic> problems = problems();
Assert.assertEquals("problems found:\n" + Joiner.on("\n").join(problems), 1, problems.size());
Diagnostic problem = Iterables.getFirst(problems, null);
assertEquals("Test Validation to mark the whole type", problem.getMessage());
Assert.assertEquals(TestLanguageValidator.MULTILINE_PROBLEM, problem.getCode().get());
Range range = problem.getRange();
Assert.assertEquals(0, range.getStart().getLine());
Assert.assertEquals(0, range.getStart().getCharacter());
Assert.assertEquals(1, range.getEnd().getLine());
Assert.assertEquals(1, range.getEnd().getCharacter());
}
use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.
the class CodeLensService method computeCodeLenses.
@Override
public List<? extends CodeLens> computeCodeLenses(Document document, XtextResource resource, CodeLensParams params, CancelIndicator indicator) {
CodeLens codeLens = new CodeLens();
Command command = new Command();
command.setCommand("do.this");
command.setTitle("Do Awesome Stuff");
command.setArguments(Lists.newArrayList("foo", Integer.valueOf(1), Boolean.valueOf(true)));
codeLens.setCommand(command);
codeLens.setData(new Position(1, 2));
codeLens.setRange(new Range(new Position(1, 1), new Position(1, 2)));
return Lists.newArrayList(codeLens);
}
use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.
the class DocumentExtensions method newLocation.
public Location newLocation(Resource resource, ITextRegion textRegion) {
Range range = newRange(resource, textRegion);
if (range == null) {
return null;
}
String uri = uriExtensions.toUriString(resource.getURI());
return new Location(uri, range);
}
use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.
the class DocumentExtensions method newRange.
public Range newRange(Resource resource, int startOffset, int endOffset) {
Position startPosition = newPosition(resource, startOffset);
if (startPosition == null) {
return null;
}
Position endPosition = newPosition(resource, endOffset);
if (endPosition == null) {
return null;
}
return new Range(startPosition, endPosition);
}
use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.
the class ChangeConverter2 method _handleReplacements.
protected void _handleReplacements(ITextDocumentChange change) {
try {
if (change.getReplacements().size() > 0) {
String uri = uriExtensions.toUriString(change.getNewURI());
access.doRead(uri, (ILanguageServerAccess.Context context) -> {
Document document = context.getDocument();
List<TextEdit> textEdits = Lists.transform(change.getReplacements(), (ITextReplacement replacement) -> {
Position start = document.getPosition(replacement.getOffset());
Position end = document.getPosition(replacement.getOffset() + replacement.getLength());
Range range = new Range(start, end);
return new TextEdit(range, replacement.getReplacementText());
});
return addTextEdit(uri, document, textEdits.toArray(new TextEdit[textEdits.size()]));
}).get();
}
} catch (InterruptedException | ExecutionException e) {
throw Exceptions.sneakyThrow(e);
}
}
Aggregations