Skip to content

Commit

Permalink
Merge pull request #527 from machitgarha/fix-duplicating-autocompletion
Browse files Browse the repository at this point in the history
Fix autocompletion leading to duplicated symbols and tokens
  • Loading branch information
Gert-dev authored Jul 25, 2022
2 parents 5c72473 + fe432ca commit bf8b7eb
Show file tree
Hide file tree
Showing 3 changed files with 250 additions and 68 deletions.
32 changes: 11 additions & 21 deletions lib/SerenataClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,17 @@ class SerenataClient extends AutoLanguageClient
});
}

onDidConvertAutocomplete(completionItem, suggestion/*, request*/) {
onDidConvertAutocomplete(completionItem, suggestion, request) {
const textEdit = completionItem.textEdit;

// TODO: Workaround for https://github.com/atom-community/atom-languageclient/pull/207
if (textEdit && textEdit.newText.substring(0, 2) === '\\$') {
suggestion.customReplacmentPrefix = request.editor.getTextInBufferRange([
[textEdit.range.start.line, textEdit.range.start.character],
request.bufferPosition
]);
}

suggestion.className = 'php-ide-serenata-autocompletion-suggestion';

if (completionItem.deprecated) {
Expand Down Expand Up @@ -461,26 +471,6 @@ class SerenataClient extends AutoLanguageClient
suggestion.rightLabel = detailParts.join(' — ');
}

onDidInsertSuggestion({editor/*, triggerPosition*/, suggestion}) {
const additionalTextEdits = suggestion.completionItem.additionalTextEdits;

if (!additionalTextEdits || additionalTextEdits.length === 0) {
return;
}

return editor.transact(() => {
return additionalTextEdits.map((additionalTextEdit) => {
editor.setTextInBufferRange(
[
[additionalTextEdit.range.start.line, additionalTextEdit.range.start.character],
[additionalTextEdit.range.end.line, additionalTextEdit.range.end.character]
],
additionalTextEdit.newText
);
});
});
}

onOpenTextDocument(parameters) {
const {Convert} = require('atom-languageclient');

Expand Down
Loading

0 comments on commit bf8b7eb

Please sign in to comment.