use of org.eclipse.lsp4j.Position in project xtext-core by eclipse.
the class RenameTest2 method testRenameSelfRef.
@Test
public void testRenameSelfRef() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.newLine();
_builder.append("element Foo {");
_builder.newLine();
_builder.append(" ");
_builder.append("ref Foo");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final String model = _builder.toString();
final String file = this.writeFile("foo/Foo.fileawaretestlanguage", model);
this.initialize();
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(file);
Position _position = new Position(2, 9);
final RenameParams params = new RenameParams(_textDocumentIdentifier, _position, "Bar");
final WorkspaceEdit workspaceEdit = this.languageServer.rename(params).get();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("changes :");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("Foo.fileawaretestlanguage : Bar [[2, 8] .. [2, 11]]");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("Bar [[3, 5] .. [3, 8]]");
_builder_1.newLine();
_builder_1.append("documentChanges : ");
_builder_1.newLine();
this.assertEquals(_builder_1.toString(), this.toExpectation(workspaceEdit));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.lsp4j.Position in project xtext-core by eclipse.
the class UnknownProjectConfigTest method checkCompletion.
protected void checkCompletion(final String uri) {
try {
TextDocumentPositionParams _textDocumentPositionParams = new TextDocumentPositionParams();
final Procedure1<TextDocumentPositionParams> _function = (TextDocumentPositionParams it) -> {
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(uri);
it.setTextDocument(_textDocumentIdentifier);
Position _position = new Position(0, 10);
it.setPosition(_position);
};
TextDocumentPositionParams _doubleArrow = ObjectExtensions.<TextDocumentPositionParams>operator_doubleArrow(_textDocumentPositionParams, _function);
final CompletableFuture<Either<List<CompletionItem>, CompletionList>> completionItems = this.languageServer.completion(_doubleArrow);
final Either<List<CompletionItem>, CompletionList> result = completionItems.get();
List<CompletionItem> _xifexpression = null;
boolean _isLeft = result.isLeft();
if (_isLeft) {
_xifexpression = result.getLeft();
} else {
_xifexpression = result.getRight().getItems();
}
final List<CompletionItem> items = _xifexpression;
final String actualCompletionItems = this.toExpectation(items);
StringConcatenation _builder = new StringConcatenation();
_builder.append("Foo (TypeDeclaration) -> Foo [[0, 10] .. [0, 10]]");
_builder.newLine();
_builder.append("boolean -> boolean [[0, 10] .. [0, 10]]");
_builder.newLine();
_builder.append("int -> int [[0, 10] .. [0, 10]]");
_builder.newLine();
_builder.append("op -> op [[0, 10] .. [0, 10]]");
_builder.newLine();
_builder.append("string -> string [[0, 10] .. [0, 10]]");
_builder.newLine();
_builder.append("void -> void [[0, 10] .. [0, 10]]");
_builder.newLine();
_builder.append("} -> } [[0, 10] .. [0, 10]]");
_builder.newLine();
_builder.append("{ -> { [[0, 9] .. [0, 10]]");
_builder.newLine();
final String expectedCompletionItems = _builder.toString();
this.assertEquals(expectedCompletionItems, actualCompletionItems);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.lsp4j.Position in project xtext-core by eclipse.
the class CodeActionService method recordWorkspaceEdit.
private WorkspaceEdit recordWorkspaceEdit(final Document doc, final XtextResource resource, final IChangeSerializer.IModification<Resource> mod) {
try {
final XtextResourceSet rs = new XtextResourceSet();
final Resource copy = rs.createResource(resource.getURI());
String _text = resource.getParseResult().getRootNode().getText();
StringInputStream _stringInputStream = new StringInputStream(_text);
copy.load(_stringInputStream, CollectionLiterals.<Object, Object>emptyMap());
this.serializer.<Resource>addModification(copy, mod);
final ArrayList<IEmfResourceChange> documentchanges = CollectionLiterals.<IEmfResourceChange>newArrayList();
this.serializer.applyModifications(CollectionBasedAcceptor.<IEmfResourceChange>of(documentchanges));
WorkspaceEdit _workspaceEdit = new WorkspaceEdit();
final Procedure1<WorkspaceEdit> _function = (WorkspaceEdit it) -> {
Iterable<ITextDocumentChange> _filter = Iterables.<ITextDocumentChange>filter(documentchanges, ITextDocumentChange.class);
for (final ITextDocumentChange documentchange : _filter) {
{
final Function1<ITextReplacement, TextEdit> _function_1 = (ITextReplacement replacement) -> {
TextEdit _textEdit = new TextEdit();
final Procedure1<TextEdit> _function_2 = (TextEdit it_1) -> {
it_1.setNewText(replacement.getReplacementText());
Position _position = doc.getPosition(replacement.getOffset());
Position _position_1 = doc.getPosition(replacement.getEndOffset());
Range _range = new Range(_position, _position_1);
it_1.setRange(_range);
};
return ObjectExtensions.<TextEdit>operator_doubleArrow(_textEdit, _function_2);
};
final List<TextEdit> edits = ListExtensions.<ITextReplacement, TextEdit>map(documentchange.getReplacements(), _function_1);
it.getChanges().put(documentchange.getNewURI().toString(), edits);
}
}
};
return ObjectExtensions.<WorkspaceEdit>operator_doubleArrow(_workspaceEdit, _function);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.lsp4j.Position in project xtext-core by eclipse.
the class CodeLensService method computeCodeLenses.
@Override
public List<? extends CodeLens> computeCodeLenses(final Document document, final XtextResource resource, final CodeLensParams params, final CancelIndicator indicator) {
CodeLens _codeLens = new CodeLens();
final Procedure1<CodeLens> _function = (CodeLens it) -> {
Command _command = new Command();
final Procedure1<Command> _function_1 = (Command it_1) -> {
it_1.setCommand("do.this");
it_1.setTitle("Do Awesome Stuff");
it_1.setArguments(Collections.<Object>unmodifiableList(CollectionLiterals.<Object>newArrayList("foo", Integer.valueOf(1), Boolean.valueOf(true))));
};
Command _doubleArrow = ObjectExtensions.<Command>operator_doubleArrow(_command, _function_1);
it.setCommand(_doubleArrow);
Position _position = new Position(1, 2);
it.setData(_position);
};
CodeLens _doubleArrow = ObjectExtensions.<CodeLens>operator_doubleArrow(_codeLens, _function);
return Collections.<CodeLens>unmodifiableList(CollectionLiterals.<CodeLens>newArrayList(_doubleArrow));
}
use of org.eclipse.lsp4j.Position in project xtext-core by eclipse.
the class PositionComparatorTest method withNull.
@Test
public void withNull() {
Position _position = new Position(2, 2);
Position _position_1 = new Position(1, 1);
final List<? extends Position> input = this.sort(CollectionLiterals.<Position>newArrayList(_position, null, _position_1));
Assert.assertEquals(1, input.get(0).getLine());
Assert.assertEquals(1, input.get(0).getCharacter());
Assert.assertEquals(2, input.get(1).getLine());
Assert.assertEquals(2, input.get(1).getCharacter());
Assert.assertNull(IterableExtensions.last(input));
}
Aggregations