Closed olegklimov closed 7 months ago
/bounty $3000
💎 $3,000 bounty created by olegklimov
🙋 If you'd like to work on this issue, comment below to get assigned
👉 To claim this bounty, submit a pull request that includes the text /claim #1
somewhere in its body
📝 Before proceeding, please make sure you can receive payouts in your country
💵 Payment arrives in your account 2-5 days after the bounty is rewarded
💯 You keep 100% of the bounty award
🙏 Thank you for contributing to smallcloudai/refact-lsp!
/attempt #1
I would like to take a look at this.
@olegklimov Just to be clear, I need to make a PR to sublimelsp/LSP adding support for LSP 3.18 InlineCompletion.
Just to be clear, I need to make a PR to sublimelsp/LSP adding support for LSP 3.18 InlineCompletion
@olegklimov Just to be clear, I need to make a PR to sublimelsp/LSP adding support for LSP 3.18 InlineCompletion.
@jwortmann Would you be open to such a PR?
Hello, so based on this issue am I right assuming that you are planning or working on adding inline completions to the Refact LSP server?
With the inline completions added to the 3.18 LSP specs, I was/am considering to experiment with it and try to implement it myself, however, at the moment and as far as I know there isn't any server yet with support for inline completions. So the problem would be that there is currently no way to test it, which seems like a blocking factor for this feature, because there are likely some limitations and edge cases to be expected. GitHub Copilot for example uses its own custom requests for the completions (which I think are not really compatible with the inline completions from the LSP specs), and there are significant bugs/limitations for the phantom (inline) completions implemented in the LSP-copilot helper package: https://github.com/TerminalFi/LSP-copilot/issues?q=is%3Aissue+is%3Aopen+label%3Aphantom Most of them could probably only be fixed or solved by SublimeHQ in Sublime Text core.
But perhaps the implementation from the LSP-copilot package can be used as a starting point.
@mnmt7 Of course contributions for the LSP package are welcome. Feel free to open a PR if/when you have implemented something. Or maybe we can even work together.
isn't any server yet with support for inline completions
This can be easily made into such server. It's still proof of concept, very small and simple at this stage.
LSP-copilot
It seems they got stuck in 2022, arrived at something that worked good enough for them (a popup?).
solved by SublimeHQ in Sublime Text core
Maybe we can persuade them to solve a couple we need.
/attempt https://github.com/smallcloudai/refact-lsp/issues/1
@nexuspy Are you still working on this issue? I'd love to take a shot at this if you're busy with other stuff.
@olegklimov do we need to PR into your repo or sublime ?
Hi @ogil7190 It's much more clear now!
LSP is a protocol, inline completions from 3.18 are not currently supported by any IDE, including VS Code Insiders.
But, it is possible to send any custom call to the LSP server, and wait for results, in VS Code typescript it can be done like this:
completions = await client.sendRequest("my-lsp/getCompletions", params);
where client
is an LSP client, from vscode-languageclient
package. Most likely it is just as easy in a Sublime extension.
In this issue, the goal is to make Sublime Text support multi line completions. That might require some changes to Sublime itself, or maybe just changes to the open LSP module for Sublime.
It's completed if there's an easy way for an extension to produce inline completions (gray text) that can be accepted by pressing Tab. And that doesn't interfere too much with a regular completion popup that already exists in Sublime. The grey text itself should be easy to deliver to the Sublime extension, because LSP is easy to work with, we can make a custom function without following the new standard.
/attempt #1
I looked into the sublime plugin api and it seems like this shouldn't be too difficult to complete.
This task is still blocked by this server not supporting the inline completions from the language server protocol, no? Or is it part of the task to add that as well, i.e. to provide both an implementation in sublimelsp/LSP, and also a PR to this repository here?
I can guarantee that there will be no PR merged into the Sublime LSP package until there exists a server which implements the inline completions.
inline completions from 3.18 are not currently supported by any IDE, including VS Code Insiders
Usually it is a hard prerequisite that a client implementation exists (usually it's VS Code), for any new feature to be included into the LSP specifications. So this actually surprises me quite a bit, but I must say that I haven't checked the VS Code source code, so I don't want to doubt what you wrote. But it means that this is basically a chicken or egg problem, because probably no client would want to add something that is not supported by any server, and vice versa...
However, if custom requests are on the table, that would certainly lower the entry barrier to get this done. Could you confirm that a custom request like refact-lsp/inlineCompletion
is an allowed option?
Another alternative would be to just create a custom "Refact AI" package for Sublime Text, without any LSP at all, if I understand your last paragraph correctly?
Anyways, I expect all of the alternatives to still have significant limitations in usability due to Sublime Text API limitations and bugs with the inline (phantom) text.
solved by SublimeHQ in Sublime Text core
Maybe we can persuade them to solve a couple we need.
I'm not sure how, though. The corresponding issues are well known and were reported in the issue tracker quite some time ago, see for example https://github.com/sublimehq/sublime_text/issues/5536 and various other issues. Still, there seems to be no reaction from the SublimeHQ dev(s), and in general it seems unclear to me how they prioritize such bugs and feature requests.
It was/is unclear to me whether you plan to add inline completion support to this server, but if the requirements are more loose (like a custom request), then I'd also like to give this a try if possible
/attempt #1
Note: The user @digital-phoenix is already attempting to complete issue #1 and claim the bounty. If you attempt to complete the same issue, there is a chance that @digital-phoenix will complete the issue first, and be awarded the bounty. We recommend discussing with @digital-phoenix and potentially collaborating on the same solution versus creating an alternate solution.
@olegklimov Am I correct in assuming you plan to support the multi line lsp spec with the refact server?
@olegklimov I think i have solved the issue as you like, I can provide my solution if you want, please look at the SS and tell me if its correct or not.
@ogil7190
correct or not
Looks fantastic! But it also needs behavior to be correct (or at least not super annoying). The inline completion might conflict with a regular popup that already exists in Sublime. They might trigger at different moments in time, appear to fight for the screen space, etc.
@jwortmann
Another alternative would be to just create a custom "Refact AI" package for Sublime Text, without any LSP at all, if I understand your last paragraph correctly?
It still has to be an LSP server, because it needs some other events LSP servers typically receive, like file opened, text changed, here is where the workspace (project folder) is.
@olegklimov We need to have a plugin like VScode. This needs a custom tailored solution as nothing direct from API is accessible. This will also not interfere with existing popups for real estate in my opinion.
interfere with existing popups for real estate in my opinion
What happens when you hit Tab? To provide visual clues to the user, the one visible (popup or the grey text) should react to Tab. So only one should be visible. Or I'm open to other solution that people at least can get used to. Or I can use it for a day and honestly say it works natural for me. It's the tricky part I think here.
We need to have a plugin like VScode
Right, let me create the repo:
https://github.com/smallcloudai/refact-sublime
To get a sense of what kind of behavior is needed, @ogil7190 you can try our VS Code plugin -- we have free tier cloud inference.
@olegklimov i am already a user of your free tier 😂
Lets start working on it, i am sure i can implement this complex UX and make it feel like the same in both cases. But we need to regularly connect, PR comments is too slow.
It still has to be an LSP server, because it needs some other events LSP servers typically receive, like file opened, text changed, here is where the workspace (project folder) is.
Those events can easily be communicated via the regular Sublime Text plugin API. There are other plugins like for example https://packagecontrol.io/packages/Codeium which do exactly that. There is not really the need for an LSP server in that case, and it might have other advantages like more control over when the completions are triggered, etc.
It would still have the same behavioral and presentation bugs, for example like in the screenshot from the comment above, where the cursor is accidentally placed to the right of the inline completion.
But to directly implement the inline completion from the LSP specs into this server and into the LSP package would have the advantage that the client part should be maintained in the long term, and potentially be improved if/when Sublime Text fixes its bugs. But it is still unclear whether this is the goal; I've asked in the Sublime forum at https://forum.sublimetext.com/t/how-to-implement-multiline-code-suggestions-in-sublime-text/68934/6 and in this issue whether it will or should be added to this server, but there is still no clear answer for that. So I think that my sentence from the comment above still stands - no server support, no merge. It's just too risky without any practical testing, and we don't want to have possibly very buggy behavior in the LSP package, if it doesn't work well.
The alternative with a custom LSP request would be much easier; we can just push the implementation to a new LSP-refact helper package, with a custom inline rendering for that request. This is how LSP-copilot works, which also uses a custom request for its completions (and also a custom listener implementation to control when they are triggered).
I could imagine that GitHub Copilot some time in the future will change its API to use the new textDocument/inlineCompletion
request from the LSP specs, though. It seems to have some other advantages, like communicating the currently selected completion item from the regular completions popup to the server when requesting inline completions. See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#inlineCompletionContext. This probably can only work if implemented directly into the LSP client package (though I think this aspect is currently not possible with the Sublime API limitations).
I agree with what @jwortmann is saying. I believe the best step forward is to add spec conformant inline completion functionality to this server. That would provide a clear test case for this issue and would better future proof the project.
We need to have a plugin like VScode
Right, let me create the repo:
https://github.com/smallcloudai/refact-sublime
To get a sense of what kind of behavior is needed, @ogil7190 you can try our VS Code plugin -- we have free tier cloud inference.
@olegklimov add me to some team or slack or collaboration group. email - ogil7190@gmail.com
I created an LSP channel on our slack, as a way to quickly ask questions. Anyone can join if you're interested, email needed for that. But I'll answer here just as well.
So was there any decision yet on how exactly this task should be implemented (referring to my previous comments)?
If it can be anything that looks somewhat like an inline completion, but doesn't have to be the exact description from the opening post (i.e. inline completions from the LSP specs for sublimelsp/LSP client, which is currently blocked by no server having support for that), it might just take an hour or two of work if you are familiar with the Sublime Text API and know what to do (like for example, just copy the phantom implementation from LSP-copilot...). But to get the best possible design for long term sustainability and to figure out the behavioral edge cases probably requires extensive testing and several iterations.
@olegklimov feel free to add my to the slack my email is jarobrownlee on gmail.
@hnhparitosh: The Refact.ai team prefers to assign a single contributor to the issue rather than let anyone attempt it right away. We recommend waiting for a confirmation from a member before getting started.
/attempt https://github.com/smallcloudai/refact-lsp/issues/1
Options Cancel my attempt
@VirtualDharm: The Refact.ai team prefers to assign a single contributor to the issue rather than let anyone attempt it right away. We recommend waiting for a confirmation from a member before getting started.
hey everyone I am new to open source, can i start working on this? or guide me to something where I can contribute to!!!!
Hey @ogil7190 can you show your prototype, for partial bounty or something? We want this plugin to actually be completed. Any progress seems to be stopped at the moment.
In this project there's an LSP server for Refact. It almost works well, but it adds text to a popup in Sublime, doesn't show the gray text.
The
mini_auto_complete
option in Sublime replaces popup with a single line gray text, but it's not the right thing either.The right thing would be multiline gray text, and it so happens the upcoming LSP standard version 3.18 has the official support for it, called InlineCompletion.
This issue/bounty is for implementing it correctly in Sublime.
Some tricky parts:
Showing gray text and popup might conflict, the popup has its strengths too. So the decision about which suggestion to show might be tricky, sure it's shouldn't show both at the same time.
Grey text should not increase visible line counters, for example a code suggestion at line 100 that has 5 lines shouldn't make the next line 106 before it's accepted.
They should accept the changes to implement this at Sublime and Sublime LSP plugin.
A discussion at Sublime forum, they also have Discord.