The main interface for accessing editor instances and manipulating their content.Source: editor/api/src/main/java/com/tom/rv2ide/editor/api/IEditor.java:34
import com.tom.rv2ide.models.Range;// Select from (10,5) to (10,15)Position start = new Position(10, 5);Position end = new Position(10, 15);Range range = new Range(start, end);editor.setSelection(range);// Or use the two-parameter versioneditor.setSelection(start, end);
Check if a range is valid for the current content:
Range range = new Range(new Position(100, 0), new Position(101, 0));if (editor.isValidRange(range)) { editor.setSelection(range);} else { System.err.println("Invalid range for current content");}
Position pos = new Position(50, 20);if (!editor.isValidPosition(pos)) { System.err.println("Position out of bounds"); return;}editor.setSelection(pos);
Extends editor functionality with Language Server Protocol features.Source: editor/api/src/main/java/com/tom/rv2ide/editor/api/ILspEditor.kt:30
package com.tom.rv2ide.editor.apiimport com.tom.rv2ide.lsp.api.ILanguageClientimport com.tom.rv2ide.lsp.api.ILanguageServerimport com.tom.rv2ide.lsp.models.Commandimport com.tom.rv2ide.lsp.models.SignatureHelpinterface ILspEditor { // Server connection fun setLanguageServer(server: ILanguageServer?) fun setLanguageClient(client: ILanguageClient?) // LSP commands fun executeCommand(command: Command?) // Language features fun signatureHelp() fun showSignatureHelp(help: SignatureHelp?) fun findDefinition() fun findReferences() fun expandSelection() // Window management fun ensureWindowsDismissed()}
Here’s a complete example showing various editor operations:
import com.tom.rv2ide.editor.api.IEditor;import com.tom.rv2ide.editor.api.ILspEditor;import com.tom.rv2ide.models.Position;import com.tom.rv2ide.models.Range;public class EditorExample { public void manipulateEditor(IEditor editor, ILspEditor lspEditor) { // Check if file is modified if (editor.isModified()) { System.out.println("File: " + editor.getFile().getName() + " has changes"); } // Get current cursor position Position cursor = editor.getCursorLSPPosition(); System.out.println("Cursor at: " + cursor.getLine() + "," + cursor.getColumn()); // Select a range Position start = new Position(10, 0); Position end = new Position(15, 0); if (editor.isValidPosition(start) && editor.isValidPosition(end)) { editor.setSelection(start, end); System.out.println("Selected lines 10-15"); } // Append new content int line = editor.append("\n// New comment\n"); System.out.println("Added comment at line: " + line); // Navigate to end editor.goToEnd(); // Use LSP features lspEditor.findDefinition(); }}