Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VS Classic] Distinguish multiline and single line completions #9

Closed
olegklimov opened this issue Nov 26, 2023 · 5 comments
Closed

Comments

@olegklimov
Copy link
Contributor

olegklimov commented Nov 26, 2023

Multi line completion -- should happen when the cursor is on a empty string, or on a string with only spaces.

A typical example of multi line completion:

def do_this_thing():
    |

User hits Enter, IDE provides auto-indent, and then a function body should appear as grey text.

To implement it, the plugin should check if the line is empty or it has only spaces, then delete all the spaces on the empty line (in memory, not in the editor), and then request the model for completions.

It's important to delete spaces before asking the model, because there should be a way for the model to suggest code with less indent. Typical example of this:

int main()
{
    printf("Hello world!\n");
    |

Now the completion is "}", but it will not work unless there are no spaces on that line. With spaces, the model is constrained to "    }".

Now the single line completion should happen when the current line is not empty, and there is nothing except closing special characters on the right:

let right_of_cursor_has_only_special_chars = Boolean(right_of_cursor.match(/^[:\s\t\n\r(){},."'];]*$/));

If multiline=false, the model will return only the remainder of the current line, and stop. The plugin needs to replace the line ending in the editor with the new completion given by the model.

If the cursor is not exactly on the last character of the current line, then #6 about how to deal with that case.

@olegklimov
Copy link
Contributor Author

Current behavior:

  • Hitting Enter doesn't request any completions at all
  • multiline is always true, in completion request in RefactLanguageClient.cs

@olegklimov olegklimov changed the title [VS Classic] Distinguish multiline and single line. [VS Classic] Distinguish multiline and single line completions Nov 26, 2023
@digital-phoenix
Copy link
Contributor

@olegklimov Currently the the lsp server returns completion suggestions by providing the text that should go after the current cursor position. If you want the completion to replace white space the code should use a different endpoint for the completions. If the lsp server supported textDocument/inlineCompletion from the latest spec that could be used instead which would provide the information needed to replace white space on the current line.

@olegklimov olegklimov mentioned this issue Nov 28, 2023
@digital-phoenix
Copy link
Contributor

@olegklimov just to clarify if the cursor is at the end of the line it should use the multi line version. Is that right?

@olegklimov
Copy link
Contributor Author

olegklimov commented Nov 29, 2023

No, if the cursor line is empty or has only spaces => multiline (this happens often when you hit Enter)
right_of_cursor_has_only_special_chars => single line
else => ignore

olegklimov pushed a commit that referenced this issue Dec 26, 2023
* adding files for refact extension

* testing github workflow

* removing default exe to test workflow

* uploading artifacts in workflow

* readding exe

* cleaning up files

* C/C++ now works with grey text

* fixed minor typo

* can now select intellisense options, whitespace causes less problems for grey text completions and the code will only ask for completions when the cursor is at the end of a line

* removing binary and updating build scripts

* fixing build script typo

* fixing minor build naming issue

* Updating code to be consistent with new build script

* improved the options page

* added comments and fixed formatting

* updating enter behaviour

* fixing minor bugs and functional issues

* added code to fix issues around single vs multiline completions issues #9 and #6

* added scroll bars for the options page

* adding status bar and killing server process on shutdown

* fixing minor bug where grey text was inserted into incorrect places
@olegklimov
Copy link
Contributor Author

This works.

There are still problems with overlapping characters but that one works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants