Skip to content

fix: fix removing triggerChar #100

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

Merged
merged 2 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.triggerPoint, request.bufferPosition]);
const replacementPrefix = request.editor.getTextInBufferRange([cache.originalBufferPoint, 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 @@ -483,6 +483,27 @@ describe('AutoCompleteAdapter', () => {
result = (await autoCompleteAdapter.getSuggestions(server, customRequest))[0];
expect(result.replacementPrefix).equals('#al');
});

it('does not include the triggerChar in replacementPrefix', async () => {
const customRequest = createRequest({ prefix: '.', position: new Point(0, 4) });
customRequest.editor.setText('foo.');
server.capabilities.completionProvider!.triggerCharacters = ['.'];
sinon.stub(server.connection, 'completion').resolves([
createCompletionItem('bar'),
]);
let result = (await autoCompleteAdapter.getSuggestions(server, customRequest))[0];
expect(result.replacementPrefix).equals('');
customRequest.editor.setTextInBufferRange([[0, 4], [0, 4]], 'b');
customRequest.prefix = 'b';
customRequest.bufferPosition = new Point(0, 5);
result = (await autoCompleteAdapter.getSuggestions(server, customRequest))[0];
expect(result.replacementPrefix).equals('b');
customRequest.editor.setTextInBufferRange([[0, 5], [0, 5]], 'a');
customRequest.prefix = 'ba';
customRequest.bufferPosition = new Point(0, 6);
result = (await autoCompleteAdapter.getSuggestions(server, customRequest))[0];
expect(result.replacementPrefix).equals('ba');
});
});

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