Skip to content

Commit

Permalink
Fix for autocomplete on imports.
Browse files Browse the repository at this point in the history
Issue MordFustang21#6.

The issue is that gopls sends back the coordinates for the text in the 
actual buffer and does not consider the changes made along the replaces. 
So, as soon as the first replace in the text happens all other 
coordinates are automatically wrong.

Replaced text suggestions from bottom to top (reverse for-each), so it 
will prevent text to be moved from it's original place.
  • Loading branch information
marcelkohl committed May 18, 2021
1 parent 7146be6 commit 06af311
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class GolangLanguageClient extends AutoLanguageClient {
// apply additional edits for the suggestion
let buf = args.editor.getBuffer();
if (args.suggestion.additionalTextEdits) {
args.suggestion.additionalTextEdits.forEach(function(item) {
args.suggestion.additionalTextEdits.reverse().forEach(function(item) {
buf.insert([item.range.start.line, item.range.start.character], item.newText);
});
}
Expand Down

0 comments on commit 06af311

Please sign in to comment.