New line at the end of suggestions
Okay I'm not 100% sure on that one, but it looks like some suggestions end with a new line, which makes it quite annoying because most of the time, that new line is not wanted (especially in single-line suggestions). eg.
import Foo from './foo.js';
import CopilotComplete from // ask for completion here
import Bar from './Bar.js';
If this is indeed the case, could the potential \n be removed at the end of the last line of the suggestion?
If that's any help, I'm using phantom suggestions. Not sure if this happens with other modes.
I don't think we know random user codes better than copilot unless it's proven that \n is added by us.
I don't think we know random user codes better than copilot
The thing is, the official integration of Copilot in VS Code seems to remove this trailing \n, at least I've never had this issue after 2+ years of using Copilot in VS Code.
unless it's proven that
\nis added by us.
I have no idea. Could take a look, but I've never worked on any ST extension before
I can't reproduce it in both default popup mode and phantom mode.
https://github.com/user-attachments/assets/39da57a2-fa26-483a-8116-185dc6f6aaf9
It doesn't seem to happen every time. Had to try a dozen completions before I had it happen in this dummy vue component, for instance:
https://github.com/user-attachments/assets/56b9e37c-f257-466a-8937-4fe1ecfd1f09
@TerminalFi @timfjord Any thought?
@mcrampon I will attempt to reproduce this tomorrow. Until then, if you can provide the logs of when this happens, that would expedite issue identification
Since it's generated by AI, I wouldn't be surprised if the output is random (so may not be reproduced stably).
@mcrampon I will attempt to reproduce this tomorrow. Until then, if you can provide the logs of when this happens, that would expedite issue identification
Completely random, I sometimes have a \n, sometimes not:
:: [09:43:49.477] <<< LSP-copilot (17) (duration: 1224ms): {'completions': [{'uuid': 'f629613c-9129-41b7-bb40-9cc670fd168f', 'text': '</script>\n', 'range': {'start': {'line': 7, 'character': 0}, 'end': {'line': 7, 'character': 0}}, 'displayText': '</script>\n', 'position': {'line': 7, 'character': 0}, 'docVersion': 10, 'point': 66, 'region': (66, 66)}]}
:: [09:44:39.469] <<< LSP-copilot (21) (duration: 126ms): {'completions': [{'uuid': '794de52d-3c17-44b6-93c0-40714cd6a6eb', 'text': '</script>', 'range': {'start': {'line': 7, 'character': 0}, 'end': {'line': 7, 'character': 0}}, 'displayText': '</script>', 'position': {'line': 7, 'character': 0}, 'docVersion': 12, 'point': 66, 'region': (66, 66)}]}
Complete logs if that helps
:: [09:43:48.241] -> LSP-copilot textDocument/didChange: {'textDocument': {'uri': 'file:///home/mat/foo.vue', 'version': 10}, 'contentChanges': [{'range': {'start': {'line': 6, 'character': 1}, 'end': {'line': 6, 'character': 1}}, 'rangeLength': 0, 'text': '\n'}]}
:: [09:43:48.250] --> LSP-copilot getCompletions (16): {'doc': {'source': "\n\n\n\n', 'range': {'start': {'line': 7, 'character': 0}, 'end': {'line': 7, 'character': 0}}, 'displayText': '\n', 'position': {'line': 7, 'character': 0}, 'docVersion': 10, 'point': 66, 'region': (66, 66)}]}
:: [09:43:52.852] -> LSP-copilot textDocument/didChange: {'textDocument': {'uri': 'file:///home/mat/foo.vue', 'version': 11}, 'contentChanges': [{'range': {'start': {'line': 7, 'character': 0}, 'end': {'line': 7, 'character': 0}}, 'rangeLength': 0, 'text': '\n'}]}
:: [09:43:52.862] --> LSP-copilot getCompletions (18): {'doc': {'source': "\n\n\n\n", 'tabSize': 2, 'indentSize': 1, 'insertSpaces': True, 'path': '/home/mat/foo.vue', 'uri': 'file:///home/mat/foo.vue', 'relativePath': '../../foo.vue', 'languageId': 'vue', 'position': {'line': 8, 'character': 0}, 'version': 11}}
:: [09:43:52.865] --> LSP-copilot getCompletionsCycling (19): {'doc': {'source': "\n\n\n\n", 'tabSize': 2, 'indentSize': 1, 'insertSpaces': True, 'path': '/home/mat/foo.vue', 'uri': 'file:///home/mat/foo.vue', 'relativePath': '../../foo.vue', 'languageId': 'vue', 'position': {'line': 8, 'character': 0}, 'version': 11}}
:: [09:43:52.865] LSP-copilot textDocument/didChange: {'textDocument': {'uri': 'file:///home/mat/foo.vue', 'version': 12}, 'contentChanges': [{'range': {'start': {'line': 7, 'character': 0}, 'end': {'line': 8, 'character': 0}}, 'rangeLength': 10, 'text': ''}]}
:: [09:44:39.339] --> LSP-copilot getCompletions (20): {'doc': {'source': "\n\n\n', 'range': {'start': {'line': 7, 'character': 0}, 'end': {'line': 7, 'character': 0}}, 'displayText': '', 'position': {'line': 7, 'character': 0}, 'docVersion': 12}]}
:: [09:44:39.345] ', 'range': {'start': {'line': 7, 'character': 0}, 'end': {'line': 7, 'character': 0}}, 'displayText': '', 'position': {'line': 7, 'character': 0}, 'docVersion': 12, 'point': 66, 'region': (66, 66)}]}
:: [09:44:42.893] -> LSP-copilot textDocument/didChange: {'textDocument': {'uri': 'file:///home/mat/foo.vue', 'version': 13}, 'contentChanges': [{'range': {'start': {'line': 7, 'character': 0}, 'end': {'line': 7, 'character': 0}}, 'rangeLength': 0, 'text': ''}]}
:: [09:44:42.903] --> LSP-copilot getCompletions (22): {'doc': {'source': "\n\n\n", 'tabSize': 2, 'indentSize': 1, 'insertSpaces': True, 'path': '/home/mat/foo.vue', 'uri': 'file:///home/mat/foo.vue', 'relativePath': '../../foo.vue', 'languageId': 'vue', 'position': {'line': 7, 'character': 9}, 'version': 13}}
:: [09:44:42.907] --> LSP-copilot getCompletionsCycling (23): {'doc': {'source': "\n\n\n", 'tabSize': 2, 'indentSize': 1, 'insertSpaces': True, 'path': '/home/mat/foo.vue', 'uri': 'file:///home/mat/foo.vue', 'relativePath': '../../foo.vue', 'languageId': 'vue', 'position': {'line': 7, 'character': 9}, 'version': 13}}
:: [09:44:42.907]
This new line is returned by Copilot, I also noticed that and it is a bit annoying. But we could definitely work around that. The simplest solution could be to strip the response, as I am almost sure that in 99% of cases, we don't care about the trailing new lines.
Let me look at the vscode and see the logic
I haven't checked, but most likely in VSCode they rely on the inline suggestions API, which can handle this case, because usually, after suggestion, there is a new line, so it might just ignore it. In our case, since ST doesn't offer something similar, we should probably manually trim the trailing new lines.
Any news on this? I often get the same problem when I'm inside a single-line string and let Copilot autocomplete the remainder, after which it will also move my cursor below this line and inserts a new blank line in the process. I'm constantly having to rearrange things because of this.