All-Hands-AI / OpenHands

🙌 OpenHands: Code Less, Make More
https://all-hands.dev
MIT License
31.24k stars 3.6k forks source link

Use Language Server Protocol (LSP) to re-implement all code editing #1934

Open xingyaoww opened 3 months ago

xingyaoww commented 3 months ago

What problem or use case are you trying to solve?

OpenDevin now sometimes suffers with edit command (concrete example: https://github.com/OpenDevin/OpenDevin/pull/1928).

Describe the UX of the solution you'd like

As suggested by a friend @ganler, maybe it is more like a fundamental solution if we can gradually replace all the swe-agent tools to interface with a Language Server Protocol:

image

It gives us the ability to:

  1. Open file
  2. Change/edit file
  3. Go to the definition of a symbol
  4. More importantly, this is actually scale to multiple programming languages!

Do you have thoughts on the technical implementation?

Describe alternatives you've considered

Additional context

li-boxuan commented 3 months ago

Oh nice! I have worked with LSP before! I could probably contribute to this.

ganler commented 3 months ago

LSP has a general interface to interact with. But if we want to start with some very easy, Jedi can be a great starter in my experience. :)

https://jedi.readthedocs.io/en/latest/docs/api.html#examples

ganler commented 3 months ago

For more general cases of interactions, monitors4codegen has some examples using multilspy to interact with some LSP implementations.

https://github.com/microsoft/monitors4codegen#4-multilspy

casper-hansen commented 3 months ago

FYI, Devin (the closed one) is fully integrated with VS Code. That means it has access to all the extensions, linting, and debugging tools. I think this is something to consider

frankxu2004 commented 3 months ago

I wonder if LSP can also actually edit the files, in addition to just monitoring file changes (usually user-triggered) and provide completion suggestions, etc.

For the VSCode solution, maybe incorporating the full VScode is heavy, but the underlying editor of vscode, monaco, could be a good option. Alternatively, CodeMirror is also quite minimalist. These editors usually maintain editor state, including undo stack as well so that if the agent is doing something wrong, we can let it call "undo" function.

For the edit command replacement, the closest might be: https://microsoft.github.io/monaco-editor/typedoc/interfaces/editor.ICodeEditor.html#executeEdits , or https://codemirror.net/examples/change/

ramsey-coding commented 3 months ago

Is it a good idea to incorporate complex LSP protocol with agent?

ganler commented 3 months ago

I wonder if LSP can also actually edit the files, in addition to just monitoring file changes (usually user-triggered) and provide completion suggestions, etc.

For the VSCode solution, maybe incorporating the full VScode is heavy, but the underlying editor of vscode, monaco, could be a good option. Alternatively, CodeMirror is also quite minimalist. These editors usually maintain editor state, including undo stack as well so that if the agent is doing something wrong, we can let it call "undo" function.

For the edit command replacement, the closest might be: https://microsoft.github.io/monaco-editor/typedoc/interfaces/editor.ICodeEditor.html#executeEdits , or https://codemirror.net/examples/change/

LSP models cursors and code locations & ranges. And knowing the locations it's easy to insert code, isn't it ;).

frankxu2004 commented 3 months ago

Good point. @ganler I wonder who maintains the cursor and code location states? (the editor states). For a real editor there's actual editor states, but it seems like we still have to maintain an "headless" editor in the backend

0xdevalias commented 2 months ago

This may also be another alternative/useful exploration:

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.