use of org.eclipse.lsp4j.Position in project xtext-core by eclipse.
the class DocumentExtensions method newPosition.
public Position newPosition(final Resource resource, final int offset) {
if ((resource instanceof XtextResource)) {
final ICompositeNode rootNode = ((XtextResource) resource).getParseResult().getRootNode();
final LineAndColumn lineAndColumn = NodeModelUtils.getLineAndColumn(rootNode, offset);
int _line = lineAndColumn.getLine();
int _minus = (_line - 1);
int _column = lineAndColumn.getColumn();
int _minus_1 = (_column - 1);
return new Position(_minus, _minus_1);
}
return null;
}
use of org.eclipse.lsp4j.Position in project xtext-core by eclipse.
the class ContentAssistService method toCompletionItem.
protected CompletionItem toCompletionItem(final ContentAssistEntry entry, final int caretOffset, final Position caretPosition, final Document document) {
final CompletionItem completionItem = new CompletionItem();
String _elvis = null;
String _label = entry.getLabel();
if (_label != null) {
_elvis = _label;
} else {
String _proposal = entry.getProposal();
_elvis = _proposal;
}
completionItem.setLabel(_elvis);
completionItem.setDetail(entry.getDescription());
completionItem.setDocumentation(entry.getDocumentation());
String _elvis_1 = null;
String _prefix = entry.getPrefix();
if (_prefix != null) {
_elvis_1 = _prefix;
} else {
_elvis_1 = "";
}
int _length = _elvis_1.length();
final int prefixOffset = (caretOffset - _length);
final Position prefixPosition = document.getPosition(prefixOffset);
Range _range = new Range(prefixPosition, caretPosition);
String _proposal_1 = entry.getProposal();
TextEdit _textEdit = new TextEdit(_range, _proposal_1);
completionItem.setTextEdit(_textEdit);
completionItem.setKind(this.translateKind(entry));
return completionItem;
}
use of org.eclipse.lsp4j.Position in project xtext-core by eclipse.
the class ContentAssistService method createCompletionList.
public CompletionList createCompletionList(final Document document, final XtextResource resource, final TextDocumentPositionParams params, final CancelIndicator cancelIndicator) {
try {
final CompletionList result = new CompletionList();
result.setIsIncomplete(true);
final IdeContentProposalAcceptor acceptor = this.proposalAcceptorProvider.get();
final int caretOffset = document.getOffSet(params.getPosition());
final Position caretPosition = params.getPosition();
final TextRegion position = new TextRegion(caretOffset, 0);
try {
this.createProposals(document.getContents(), position, caretOffset, resource, acceptor);
} catch (final Throwable _t) {
if (_t instanceof Throwable) {
final Throwable t = (Throwable) _t;
boolean _isOperationCanceledException = this.operationCanceledManager.isOperationCanceledException(t);
boolean _not = (!_isOperationCanceledException);
if (_not) {
throw t;
}
} else {
throw Exceptions.sneakyThrow(_t);
}
}
final Procedure2<ContentAssistEntry, Integer> _function = (ContentAssistEntry it, Integer idx) -> {
final CompletionItem item = this.toCompletionItem(it, caretOffset, caretPosition, document);
item.setSortText(Strings.padStart(Integer.toString((idx).intValue()), 5, '0'));
List<CompletionItem> _items = result.getItems();
_items.add(item);
};
IterableExtensions.<ContentAssistEntry>forEach(acceptor.getEntries(), _function);
return result;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.lsp4j.Position in project xtext-core by eclipse.
the class DocumentTest method position.
private Position position(final int l, final int c) {
Position _position = new Position();
final Procedure1<Position> _function = (Position it) -> {
it.setLine(l);
it.setCharacter(c);
};
return ObjectExtensions.<Position>operator_doubleArrow(_position, _function);
}
use of org.eclipse.lsp4j.Position in project xtext-core by eclipse.
the class RenameTest2 method testRenameContainer.
@Test
public void testRenameContainer() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.newLine();
_builder.append("element Foo {");
_builder.newLine();
_builder.append(" ");
_builder.append("element Bar {");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("ref foo.Foo.Bar");
_builder.newLine();
_builder.append(" ");
_builder.append("ref Foo.Bar");
_builder.newLine();
_builder.append(" ");
_builder.append("ref Bar");
_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, "Baz");
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 : Baz [[2, 8] .. [2, 11]]");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("Bar [[5, 5] .. [5, 16]]");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("Bar [[6, 5] .. [6, 12]]");
_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);
}
}
Aggregations