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 sorting problem in QuickFileOpenService #10694

Merged
merged 2 commits into from
Feb 3, 2022

Conversation

colin-grant-work
Copy link
Contributor

@colin-grant-work colin-grant-work commented Jan 31, 2022

What it does

There were a couple of problems in the sort function for the file quick pick and in the tests for them:

A positive returns means left after right, so these values are reversed.

assert.equal(quickFileOpenService['compareItems'](a, b), 1, 'a should be before b');
assert.equal(quickFileOpenService['compareItems'](b, a), -1, 'a should be before b');

I've replaced the return expectations with actual passes through a sort function so that we're guaranteed to mirror the actual behavior of the function in its intended context of use.


To test whether L before R, these should also be reversed (but since the test expectations were reversed, the tests passed)

const compareByLabel = (l: FileQuickPickItem, r: FileQuickPickItem) => r.label.localeCompare(l.label);


Fuzzy scores can be greater than Scores.max (1000), so imperfect matches could get a lead over perfect matches.

matchScore = (fuzzyMatch.score === Infinity) ? QuickFileOpenService.Scores.max : fuzzyMatch.score;

How to test

  1. Mostly see if the tests pass.
  2. Create a workspace with files with the filenames used in the new test.
  3. Search for the perfect match.
  4. Observe that it is ordered above the very good match.

Review checklist

Reminder for reviewers

@colin-grant-work colin-grant-work added the file search issues related to the file search label Jan 31, 2022
Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

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

@colin-grant-work unfortunately the changes do not work for me, the file-search is broken when I tried in the browser and electron. The following error is reported multiple times:

quick-file-open.ts:247 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'score')
    at score (/home/evinfug/workspaces/theia/examples/electron/lib/packages_file-search_lib_browser_file-search-frontend-module_js.bundle.js:346)
    at Array.compareByLabelScore (/home/evinfug/workspaces/theia/examples/electron/lib/packages_file-search_lib_browser_file-search-frontend-module_js.bundle.js:355)
    at compareWithDiscriminators (/home/evinfug/workspaces/theia/examples/electron/lib/packages_file-search_lib_browser_file-search-frontend-module_js.bundle.js:523)
    at QuickFileOpenService.compareItems (/home/evinfug/workspaces/theia/examples/electron/lib/packages_file-search_lib_browser_file-search-frontend-module_js.bundle.js:361)
    at /home/evinfug/workspaces/theia/examples/electron/lib/packages_file-search_lib_browser_file-search-frontend-module_js.bundle.js:305
    at Array.sort (<anonymous>)
    at handler (/home/evinfug/workspaces/theia/examples/electron/lib/packages_file-search_lib_browser_file-search-frontend-module_js.bundle.js:305)

Steps to Reproduce:

  1. start the application with theia as a workspace
  2. search for pack
  3. the file-search is broken

@colin-grant-work
Copy link
Contributor Author

  1. the file-search is broken

@vince-fugnitto, good catch. The perils of only doing searches that work in a small workspace (and of trusting the declared types...)! I've pushed a commit that handles the null returns from fuzzy, and I also noticed that we were mishandling the file results (not recently opened) separator and fixed that.

Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

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

I confirm that the changes work as expected following the update, and the tests successfully pass 👍
I verified using a large workspace with exact, good and invalid results and it works fine, even with recent results.

Copy link
Contributor

@JonasHelming JonasHelming 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 to me, I did a smoke test as well.

@colin-grant-work colin-grant-work merged commit 2faa18b into master Feb 3, 2022
@colin-grant-work colin-grant-work deleted the bugfix/quickpick-sort branch February 3, 2022 15:47
@github-actions github-actions bot added this to the 1.23.0 milestone Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
file search issues related to the file search
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants