-
Notifications
You must be signed in to change notification settings - Fork 8
fix: when autocompleting with insertText, use that rather than name #562
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - just non-blocking comments on my part.
}, | ||
{ | ||
kind: 'property', | ||
name: 'functionProp', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... why are we getting these completions? Shouldn't they be filtered out since they don't start with fo
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function filterStartingWith({
name,
trigger,
}: {
name: string;
trigger: string;
}): boolean {
name = name.toLocaleLowerCase();
trigger = trigger.toLocaleLowerCase();
if (name.startsWith(trigger)) {
console.log({ name, trigger });
return true;
};
return false;
}
trigger is a blank string in this case:
Autocompleter
without filter
✓ returns the global scope for a global variable that does not exist
✓ returns completions for global variables
✓ returns nothing for a member of a variable that does not exist
✓ returns matches for a member of a variable that exists
✓ returns matches for part of a member of a variable that exists
✓ returns matches for an unknown member of a variable that exists
✓ returns the global scope for object parameters of a function that does not exist
✓ returns matches for object parameters of a function that exists
✓ returns matches for part of an object parameter of a function that exists
✓ returns matches for an unknown object parameter of a function that exists
✓ returns completions for variables with dots in their names
with filter
✓ returns nothing when it has no code
{ name: 'myglobalfunction', trigger: 'myglobalfunct' }
✓ returns completions for global variables
{ name: 'myglobalobject', trigger: 'myglobalobject' }
{ name: 'foo.bar', trigger: '' }
{ name: 'functionprop', trigger: '' }
{ name: 'stringprop', trigger: '' }
{ name: 'functionprop', trigger: 'functionpr' }
✓ returns completions for members of global variables
{ name: 'param1', trigger: 'par' }
{ name: 'param2', trigger: 'par' }
✓ returns completions for the fields of object function parameters
15 passing (60ms)
@@ -190,8 +190,23 @@ function mapCompletions( | |||
return completions.entries | |||
.filter((entry) => filter({ trigger, kind: entry.kind, name: entry.name })) | |||
.map((entry) => { | |||
/* | |||
With the includeCompletionsWithInsertText option set, auto-completions | |||
might have an insertText property for cases like where a property has |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What other cases are there and should we add tests for those as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't think of any. Once I do I'll add regression tests ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably dashes, spaces, quotes..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, will be interesting to see some corner cases involving quotes - e.g. a collection called foo"bar'
fails with the current autocompleter - kind of hoping it will work out of the box with the new one
db.fo
->db["foo.bar"]
rather thandb.foo.bar
so that the result is valid and then if you type on likedb["foo.bar"].fi
it will continue to autocomplete asdb["foo.bar"].find
.Because
db.foo.bar.fi
won't autocomplete becausedb.foo.bar
is invalid if the collection name isfoo.bar
. ie. there is no propfoo
ondb
.