Java Code Examples for org.eclipse.lsp4j.TextDocumentContentChangeEvent#setText()
The following examples show how to use
org.eclipse.lsp4j.TextDocumentContentChangeEvent#setText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SemanticHighlightingTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
protected void changeDocument(ICompilationUnit unit, String content, int version, Range range, int length) { DidChangeTextDocumentParams changeParms = new DidChangeTextDocumentParams(); VersionedTextDocumentIdentifier textDocument = new VersionedTextDocumentIdentifier(); textDocument.setUri(JDTUtils.toURI(unit)); textDocument.setVersion(version); changeParms.setTextDocument(textDocument); TextDocumentContentChangeEvent event = new TextDocumentContentChangeEvent(); if (range != null) { event.setRange(range); event.setRangeLength(length); } event.setText(content); List<TextDocumentContentChangeEvent> contentChanges = new ArrayList<>(); contentChanges.add(event); changeParms.setContentChanges(contentChanges); lifeCycleHandler.didChange(changeParms); }
Example 2
Source File: DocumentLifeCycleHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private void changeDocument(ICompilationUnit cu, String content, int version, Range range, int length) throws JavaModelException { DidChangeTextDocumentParams changeParms = new DidChangeTextDocumentParams(); VersionedTextDocumentIdentifier textDocument = new VersionedTextDocumentIdentifier(); textDocument.setUri(JDTUtils.toURI(cu)); textDocument.setVersion(version); changeParms.setTextDocument(textDocument); TextDocumentContentChangeEvent event = new TextDocumentContentChangeEvent(); if (range != null) { event.setRange(range); event.setRangeLength(length); } event.setText(content); List<TextDocumentContentChangeEvent> contentChanges = new ArrayList<>(); contentChanges.add(event); changeParms.setContentChanges(contentChanges); lifeCycleHandler.didChange(changeParms); }
Example 3
Source File: DocumentTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
private TextDocumentContentChangeEvent change(final Position startPos, final Position endPos, final String newText) { TextDocumentContentChangeEvent _textDocumentContentChangeEvent = new TextDocumentContentChangeEvent(); final Procedure1<TextDocumentContentChangeEvent> _function = (TextDocumentContentChangeEvent it) -> { if ((startPos != null)) { Range _range = new Range(); final Procedure1<Range> _function_1 = (Range it_1) -> { it_1.setStart(startPos); it_1.setEnd(endPos); }; Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_1); it.setRange(_doubleArrow); } it.setText(newText); }; return ObjectExtensions.<TextDocumentContentChangeEvent>operator_doubleArrow(_textDocumentContentChangeEvent, _function); }
Example 4
Source File: FileContentsTrackerTests.java From groovy-language-server with Apache License 2.0 | 5 votes |
@Test void testDidChangeWithoutRange() { DidOpenTextDocumentParams openParams = new DidOpenTextDocumentParams(); openParams.setTextDocument(new TextDocumentItem("file.txt", "plaintext", 1, "hello world")); tracker.didOpen(openParams); DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams(); changeParams.setTextDocument(new VersionedTextDocumentIdentifier("file.txt", 2)); TextDocumentContentChangeEvent changeEvent = new TextDocumentContentChangeEvent(); changeEvent.setText("hi there"); changeParams.setContentChanges(Collections.singletonList(changeEvent)); tracker.didChange(changeParams); Assertions.assertEquals("hi there", tracker.getContents(URI.create("file.txt"))); }
Example 5
Source File: FileContentsTrackerTests.java From groovy-language-server with Apache License 2.0 | 5 votes |
@Test void testDidChangeWithRange() { DidOpenTextDocumentParams openParams = new DidOpenTextDocumentParams(); openParams.setTextDocument(new TextDocumentItem("file.txt", "plaintext", 1, "hello world")); tracker.didOpen(openParams); DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams(); changeParams.setTextDocument(new VersionedTextDocumentIdentifier("file.txt", 2)); TextDocumentContentChangeEvent changeEvent = new TextDocumentContentChangeEvent(); changeEvent.setText(", friend"); changeEvent.setRange(new Range(new Position(0, 5), new Position(0, 11))); changeEvent.setRangeLength(6); changeParams.setContentChanges(Collections.singletonList(changeEvent)); tracker.didChange(changeParams); Assertions.assertEquals("hello, friend", tracker.getContents(URI.create("file.txt"))); }
Example 6
Source File: FileContentsTrackerTests.java From groovy-language-server with Apache License 2.0 | 5 votes |
@Test void testDidChangeWithRangeMultiline() { DidOpenTextDocumentParams openParams = new DidOpenTextDocumentParams(); openParams.setTextDocument(new TextDocumentItem("file.txt", "plaintext", 1, "hello\nworld")); tracker.didOpen(openParams); DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams(); changeParams.setTextDocument(new VersionedTextDocumentIdentifier("file.txt", 2)); TextDocumentContentChangeEvent changeEvent = new TextDocumentContentChangeEvent(); changeEvent.setText("affles"); changeEvent.setRange(new Range(new Position(1, 1), new Position(1, 5))); changeEvent.setRangeLength(4); changeParams.setContentChanges(Collections.singletonList(changeEvent)); tracker.didChange(changeParams); Assertions.assertEquals("hello\nwaffles", tracker.getContents(URI.create("file.txt"))); }
Example 7
Source File: DocumentContentSynchronizer.java From intellij-quarkus with Eclipse Public License 2.0 | 5 votes |
/** * Convert IntelliJ {@link DocumentEvent} to LS according {@link TextDocumentSyncKind}. * * @param event * IntelliJ {@link DocumentEvent} * @return true if change event is ready to be sent */ private boolean createChangeEvent(DocumentEvent event) { changeParams = new DidChangeTextDocumentParams(new VersionedTextDocumentIdentifier(), Collections.singletonList(new TextDocumentContentChangeEvent())); changeParams.getTextDocument().setUri(fileUri.toString()); Document document = event.getDocument(); TextDocumentContentChangeEvent changeEvent = null; TextDocumentSyncKind syncKind = getTextDocumentSyncKind(); switch (syncKind) { case None: return false; case Full: changeParams.getContentChanges().get(0).setText(event.getDocument().getText()); break; case Incremental: changeEvent = changeParams.getContentChanges().get(0); CharSequence newText = event.getNewFragment(); int offset = event.getOffset(); int length = event.getOldLength(); try { // try to convert the Eclipse start/end offset to LS range. Range range = new Range(LSPIJUtils.toPosition(offset, document), LSPIJUtils.toPosition(offset + length, document)); changeEvent.setRange(range); changeEvent.setText(newText.toString()); changeEvent.setRangeLength(length); } finally { } break; } return true; }
Example 8
Source File: CompletionHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private void changeDocument(ICompilationUnit unit, String content, int version) throws JavaModelException { DidChangeTextDocumentParams changeParms = new DidChangeTextDocumentParams(); VersionedTextDocumentIdentifier textDocument = new VersionedTextDocumentIdentifier(); textDocument.setUri(JDTUtils.toURI(unit)); textDocument.setVersion(version); changeParms.setTextDocument(textDocument); TextDocumentContentChangeEvent event = new TextDocumentContentChangeEvent(); event.setText(content); List<TextDocumentContentChangeEvent> contentChanges = new ArrayList<>(); contentChanges.add(event); changeParms.setContentChanges(contentChanges); lifeCycleHandler.didChange(changeParms); }
Example 9
Source File: EditorEventManager.java From lsp4intellij with Apache License 2.0 | 4 votes |
public void documentChanged(DocumentEvent event) { if (editor.isDisposed()) { return; } if (event.getDocument() == editor.getDocument()) { //Todo - restore when adding hover support // long predTime = System.nanoTime(); //So that there are no hover events while typing changesParams.getTextDocument().setVersion(version++); if (syncKind == TextDocumentSyncKind.Incremental) { TextDocumentContentChangeEvent changeEvent = changesParams.getContentChanges().get(0); CharSequence newText = event.getNewFragment(); int offset = event.getOffset(); int newTextLength = event.getNewLength(); Position lspPosition = DocumentUtils.offsetToLSPPos(editor, offset); int startLine = lspPosition.getLine(); int startColumn = lspPosition.getCharacter(); CharSequence oldText = event.getOldFragment(); //if text was deleted/replaced, calculate the end position of inserted/deleted text int endLine, endColumn; if (oldText.length() > 0) { endLine = startLine + StringUtil.countNewLines(oldText); String[] oldLines = oldText.toString().split("\n"); int oldTextLength = oldLines.length == 0 ? 0 : oldLines[oldLines.length - 1].length(); endColumn = oldLines.length == 1 ? startColumn + oldTextLength : oldTextLength; } else { //if insert or no text change, the end position is the same endLine = startLine; endColumn = startColumn; } Range range = new Range(new Position(startLine, startColumn), new Position(endLine, endColumn)); changeEvent.setRange(range); changeEvent.setRangeLength(newTextLength); changeEvent.setText(newText.toString()); } else if (syncKind == TextDocumentSyncKind.Full) { changesParams.getContentChanges().get(0).setText(editor.getDocument().getText()); } requestManager.didChange(changesParams); } else { LOG.error("Wrong document for the EditorEventManager"); } }