run lsp server from binary file
I am looking for a detailed guide or code example showing how to run an LSP (Language Server Protocol) server from a binary file (for instance, installed via Termux) and integrate it with a code editor. Specifically, I want to use a CodeEditor, such as the Rosemoe Sora Editor, in an Android application. For example, I am interested in using a Python LSP server like pylsp from its binary executable. Since there is no dedicated guide or chapter for this topic, I would really appreciate step-by-step instructions, including how to start the server, connect to it from the editor, and handle requests/responses using Android Java code. i used code from sora editor repository and there are two class for it and i tried to edit it from my hope the first class is LspTestJavaActivity.java that has code
private void connectToLanguageServer() throws IOException, InterruptedException {
runOnUiThread(() -> {
// toast("(Java Activity) Starting Language Server...");
editor.setEditable(false);
});
var port = randomPort();
var projectPath = new File(getExternalCacheDir(), "testProject").getAbsolutePath();
var intent = new Intent(this, LspLanguageServerService.class);
intent.putExtra("port", port);
startService(intent);
.
.
.
.
} catch (Exception e) {
runOnUiThread(() -> {
toast(String.valueOf(e));
});
connected = false;
e.printStackTrace();
}
and the second class is service and its code is LspLanguageServerService.java and i also edit it
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
int port = intent != null ? intent.getIntExtra("port", 0) : 0;
new Thread(() -> {
try (ServerSocket serverSocket = new ServerSocket(port)) {
Log.d(TAG, "Starting socket on port " + serverSocket.getLocalPort());
Socket socketClient = serverSocket.accept();
try {
Log.d(TAG, "Connected to the client on port " + socketClient.getPort());
startShellSession();
new Thread(() -> {
try (InputStream clientIn = socketClient.getInputStream()) {
byte[] buffer = new byte[4096];
int bytes;
while ((bytes = clientIn.read(buffer)) != -1) {
ptyOutput.write(buffer, 0, bytes);
ptyOutput.flush();
}
} catch (IOException e) {
Log.e(TAG, "Error piping client → pty", e);
}
}).start();
new Thread(() -> {
try (OutputStream clientOut = socketClient.getOutputStream()) {
byte[] buffer = new byte[4096];
int bytes;
while ((bytes = ptyInput.read(buffer)) != -1) {
clientOut.write(buffer, 0, bytes);
clientOut.flush();
}
} catch (IOException e) {
Log.e(TAG, "Error piping pty → client", e);
}
}).start();
} finally {
try { socketClient.close(); } catch (IOException ignored) {}
}
} catch (IOException e) {
Log.e(TAG, "Server error", e);
}
}).start();
return START_STICKY;
}
notes: startShellSession(); function it run for configuring environment and define pty variables and run lsp server from binary
it took 3 seconds almost and after it display in toast java.util.concurrent.TimeoutException: Unable to connect language server
Thank you in advance for any help!
I implemented this by using lspProject.addServerDefinition on a custom object where object : LanguageServerDefinition implemented createConnectionProvider::start to start the process. Then hooked up the process.outputStream to StreamConnectionProvider.outputStream and process.inputStream to StreamConnectionProvider.inputStream.
brother, thanks for patient with me,I am facing a new and annoying problem. Perhaps we could call it problems, but the basic thing is
java.lang.StringIndexOutOfBoundsException: Column 38 out of bounds. line: 1, column count (line separator included):18 rosemoe sora editor
This appears when I choose one of the autocomplete options, but in this message, for example, I was already in column 18 the line is correct and there is no problem with it, I have to add blank spaces so I can choose one of the options, as this message appears for all options,Later, it appears with different numbers. Also, I may have tried to find the reason and it turns out, perhaps, and I am not sure. When an error occurs in one of the lines, this message and something similar appears.So I have to delete the wrong line and then choose and it works The other matter is that I did not find a way to be able to display the locations of the errors. Does it display them automatically? If yes, then it does not show me any errors despite the apparent errors and the server messages that show the locations of the errors.
I won't let you know what I used
The version I use is "sora-editor-0.23.5"
These are copies of some important libraries
agp = "8.7.0"
kotlin = "1.9.23"
tsBinding = "4.3.1"
lsp4j = "0.23.1"
androidxAnnotation = "1.8.2"
I know you'll tell me you should use a newer version ,I hope so, but I cannot currently due to the limitations of the programming environment, so please excuse me Also, I have already tried to use the latest version of the repository, but with old libraries, and the problem occurs unfortunately. Is it perhaps the reason for the libraries or something else? Note that I followed the example in the test file.
If there is no disturbance, I wish we could talk on Telegram or any other means so that the conversation would be active and I would tell you all the details directly.
I apologize again for my many questions
I hope you take my message seriously, as I have been stuck here for a while
في الاثنين، ١٣ أكتوبر ٢٠٢٥ ١٦:١٨ Vincent Lagerros @.***> كتب:
VincentLagerros left a comment (Rosemoe/sora-editor#710) https://github.com/Rosemoe/sora-editor/issues/710#issuecomment-3397502258
I implemented this by using lspProject.addServerDefinition on a custom object where object : LanguageServerDefinition implemented createConnectionProvider::start to start the process. Then hooked up the process.outputStream to StreamConnectionProvider.outputStream and process.inputStream to StreamConnectionProvider.inputStream.
— Reply to this email directly, view it on GitHub https://github.com/Rosemoe/sora-editor/issues/710#issuecomment-3397502258, or unsubscribe https://github.com/notifications/unsubscribe-auth/BVQN3CEQCWAKPB36QVOS3GD3XORDPAVCNFSM6AAAAACGIPYBGOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTGOJXGUYDEMRVHA . You are receiving this because you authored the thread.Message ID: @.***>
java.lang.StringIndexOutOfBoundsException: Column 38 out of bounds. line: 1, column count (line separator included):18
This appears when I choose one of the autocomplete options, but in this message, for example, I was already in column 18 the line is correct and there is no problem with it, I have to add blank spaces so I can choose one of the options, as this message appears for all
Editor's line index starts from 0. If the problem is caused by our language modules, you may provide more detailed stacktrace for us to analyze the problem.
What language server are you using? The pylsp in xed-editor seems to be running normally.
brother, thanks for patient with me,I am facing a new and annoying problem. Perhaps we could call it problems, but the basic thing is
java.lang.StringIndexOutOfBoundsException: Column 38 out of bounds. line: 1, column count (line separator included):18 rosemoe sora editor
The current LSP implementation (or at least the one from 1 month ago, so it might have changed after #731) was not feature complete. I found several app crashing bugs, including issues like this (#718). The LSP used by this project is quite simplistic and only implements a subset of all features, and therefore has some issues like this on other language servers.
For my own rust-analyzer I use https://github.com/Rosemoe/sora-editor/pull/719 to fix some uncaught errors as it might be the case that the editor gets de-synced for a millisecond or something. I recommend having a local instance of the sora-editor to debug and fix these issues.
Moreover, I have some local modifications on top of that, that I have not yet pushed upstream. An example of that is semanticTokensFull/semanticTokensFullDelta that is still not supported by the project.
Can you share this project with me? I need it a lot. If not, no problem. Thank you anyway for your kind response and your patience with me.
في الأحد، ٩ نوفمبر ٢٠٢٥ ٢٢:٢٩ Vincent Lagerros @.***> كتب:
VincentLagerros left a comment (Rosemoe/sora-editor#710) https://github.com/Rosemoe/sora-editor/issues/710#issuecomment-3508808630
brother, thanks for patient with me,I am facing a new and annoying problem. Perhaps we could call it problems, but the basic thing is
java.lang.StringIndexOutOfBoundsException: Column 38 out of bounds. line: 1, column count (line separator included):18 rosemoe sora editor
The current LSP implementation (or at least the one from 1 month ago, so it might have changed after #731 https://github.com/Rosemoe/sora-editor/pull/731) was not feature complete. I found several app crashing bugs, including issues like this ( #718 https://github.com/Rosemoe/sora-editor/pull/718). The LSP used by this project is quite simplistic and only implements a subset of all features, and therefore has some issues like this on other language servers.
For my own rust-analyzer I use #719 https://github.com/Rosemoe/sora-editor/pull/719 to fix some uncaught errors as it might be the case that the editor gets de-synced for a millisecond or something. I recommend having a local instance of the sora-editor to debug and fix these issues.
Moreover, I have some local modifications on top of that, that I have not yet pushed upstream. An example of that is semanticTokensFull/semanticTokensFullDelta that is still not supported by the project.
— Reply to this email directly, view it on GitHub https://github.com/Rosemoe/sora-editor/issues/710#issuecomment-3508808630, or unsubscribe https://github.com/notifications/unsubscribe-auth/BVQN3CE5AYGUGG4W75HTQG3336P4DAVCNFSM6AAAAACGIPYBGOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTKMBYHAYDQNRTGA . You are receiving this because you authored the thread.Message ID: @.***>
Can you share this project with me? I need it a lot. If not, no problem. Thank you anyway for your kind response and your patience with me.
في الأحد، ٩ نوفمبر ٢٠٢٥ ٢٢:٢٩ Vincent Lagerros @.***> كتب: …
Unfortunately no, my own project is far from anything resembling even a prototype. I will open source my own project when it is finished, if that will ever occur. However I have been very busy currently, so I have not had the time to push any LSP stuff upstream or work on my own project.
Brother, please, I have one last question. Errors appear in places where they should not appear. What is the solution? Should I call an update or validate function? If the answer is yes, what is it and how can i call it ? The problem, for example, is that I have an already old class, let's say its name is A The error appears in any area and says the class is not defined despite the correct definition. And not only that, but it also says that a class should not be defined inside a class.
في الأحد، ٩ نوفمبر ٢٠٢٥ ٢٣:٤٠ Vincent Lagerros @.***> كتب:
VincentLagerros left a comment (Rosemoe/sora-editor#710) https://github.com/Rosemoe/sora-editor/issues/710#issuecomment-3508861297
Can you share this project with me? I need it a lot. If not, no problem. Thank you anyway for your kind response and your patience with me.
في الأحد، ٩ نوفمبر ٢٠٢٥ ٢٢:٢٩ Vincent Lagerros @.***> كتب: … <#m_-4876932762506667172_>
Unfortunately no, my own project is far from anything resembling even a prototype. I will open source my own project when it is finished, if that will ever occur. However I have been very busy currently, so I have not had the time to push any LSP stuff upstream or work on my own project.
— Reply to this email directly, view it on GitHub https://github.com/Rosemoe/sora-editor/issues/710#issuecomment-3508861297, or unsubscribe https://github.com/notifications/unsubscribe-auth/BVQN3CASZL7Z2WM2IH57G4D336YDZAVCNFSM6AAAAACGIPYBGOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTKMBYHA3DCMRZG4 . You are receiving this because you authored the thread.Message ID: @.***>