Skip to content

Commit

Permalink
fix: fix autocomplete prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Jan 6, 2021
1 parent bb2db5f commit bd0576e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/adapters/autocomplete-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default class AutocompleteAdapter {

// We must update the replacement prefix as characters are added and removed
const cache = this._suggestionCache.get(server)!;
const replacementPrefix = request.editor.getTextInBufferRange([cache.originalBufferPoint, request.bufferPosition]);
const replacementPrefix = request.editor.getTextInBufferRange([[cache.triggerPoint.row, cache.triggerPoint.column + cache.triggerChar.length], request.bufferPosition]);
for (const suggestion of suggestions) {
if (suggestion.customReplacmentPrefix) { // having this property means a custom range was provided
const len = replacementPrefix.length;
Expand Down
21 changes: 21 additions & 0 deletions test/adapters/autocomplete-adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,27 @@ describe('AutoCompleteAdapter', () => {
result = (await autoCompleteAdapter.getSuggestions(server, customRequest))[0];
expect(result.replacementPrefix).equals('ba');
});

it('includes non trigger character prefix in replacementPrefix', async () => {
const customRequest = createRequest({ prefix: 'foo', position: new Point(0, 3) });
customRequest.editor.setText('foo');
sinon.stub(server.connection, 'completion').resolves([
createCompletionItem('foobar'),
]);
let result = (await autoCompleteAdapter.getSuggestions(server, customRequest))[0];

expect(result.replacementPrefix).equals('foo');
customRequest.editor.setTextInBufferRange([[0, 3], [0, 3]], 'b');
customRequest.prefix = 'foob';
customRequest.bufferPosition = new Point(0, 4);
result = (await autoCompleteAdapter.getSuggestions(server, customRequest))[0];
expect(result.replacementPrefix).equals('foob');
customRequest.editor.setTextInBufferRange([[0, 4], [0, 4]], 'a');
customRequest.prefix = 'fooba';
customRequest.bufferPosition = new Point(0, 5);
result = (await autoCompleteAdapter.getSuggestions(server, customRequest))[0];
expect(result.replacementPrefix).equals('fooba');
});
});

describe('completionKindToSuggestionType', () => {
Expand Down

0 comments on commit bd0576e

Please sign in to comment.