Skip to content

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

Merged
merged 1 commit into from
Jul 7, 2025

Conversation

lerouxb
Copy link
Collaborator

@lerouxb lerouxb commented Jul 7, 2025

db.fo -> db["foo.bar"] rather than db.foo.bar so that the result is valid and then if you type on like db["foo.bar"].fi it will continue to autocomplete as db["foo.bar"].find.

Because db.foo.bar.fi won't autocomplete because db.foo.bar is invalid if the collection name is foo.bar. ie. there is no prop foo on db.

Copy link
Collaborator

@nirinchev nirinchev left a 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',
Copy link
Collaborator

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?

Copy link
Collaborator Author

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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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 ;)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

probably dashes, spaces, quotes..

Copy link
Collaborator

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

@lerouxb lerouxb merged commit 4069e88 into main Jul 7, 2025
30 checks passed
@lerouxb lerouxb deleted the insert-correct-ts branch July 7, 2025 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants