Skip to content
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

Fix TS/JS Completion Item Provider for Completions that are not whole words #16955

Merged
merged 1 commit into from
Dec 16, 2016

Conversation

mjbvz
Copy link
Contributor

@mjbvz mjbvz commented Dec 9, 2016

Fixes #16888

Bug
The js/ts completion provider can currently only complete whole words in most cases (as defined by TextDocument.getWordRangeAtPosition). This causes completion of literal string types to fail if they are not a whole word.

dec-08-2016 17-01-45

Fix
Instead of relaying on the default range, compute a range by taking the longest match of the replacement text backwards from the current position.

dec-08-2016 17-03-24

… words

Fixes microsoft#16888

**Bug**
The js/ts completion provide can currently only complete whole words (as defined by `TextDocument.getWordRangeAtPosition`). This causes completion of literal string types to fail if they are not a whole word.

**Fix**
Instead of relaying on the default range, compute a range by taking the longest match of the replacement text from the current position.
if (entry.replacementSpan) {
let span: protocol.TextSpan = entry.replacementSpan;
// The indexing for the range returned by the server uses 1-based indexing.
// We convert to 0-based indexing.
this.textEdit = TextEdit.replace(new Range(span.start.line - 1, span.start.offset - 1, span.end.line - 1, span.end.offset - 1), entry.name);
} else {
const text = document.getText(new Range(position.line, Math.max(0, position.character - entry.name.length), position.line, position.character));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assume that the replacement text will always start with the replaced text. @dbaeumer is this a safe assumption to make. It worked in all cases in my testing, but we may want to scope the fix by only applying it to certain kinds of completion entries

@mjbvz mjbvz added this to the January 2017 milestone Dec 9, 2016
@mjbvz
Copy link
Contributor Author

mjbvz commented Dec 9, 2016

The completions for the literal types are new in TS 2.1.x. In VSCode 1.7.2, we just treated the string values being completed as normal strings instead of types.

I think we should hold off on merging this fix until post 1.8. I would like a period of testing in insiders for this.

@mjbvz mjbvz merged commit bbe153d into microsoft:master Dec 16, 2016
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autocomplete with dash
3 participants