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

Highlight matches in CB #8098

Merged
merged 11 commits into from
Oct 19, 2023
Merged

Highlight matches in CB #8098

merged 11 commits into from
Oct 19, 2023

Conversation

somebody1234
Copy link
Contributor

@somebody1234 somebody1234 commented Oct 18, 2023

Pull Request Description

Important Notes

  • This PR uses a completely separate implementation from the regexes used for the existing filtering. AFAICT, this is unavoidable, since this needs to retrieve matched text.
  • I've come across a couple minor bugs related to the Component Browser:
    • When deleting text (backspacing), the full list of unfiltered entries momentarily reappear because the filtering is reset.
    • Things like h.m match HTTP_Method - if this is not intentional, it seems like it might be more difficult to fix, unfortunately.
      • Note that highlighting (I assume correctly?) does not highlight any part of HTTP_Method.

Screencast

highlight_matches.mp4

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed, the GUI was tested when built using ./run ide build.

@somebody1234 somebody1234 added CI: No changelog needed Do not require a changelog entry for this PR. -gui labels Oct 18, 2023
@somebody1234 somebody1234 requested a review from Frizi as a code owner October 18, 2023 07:54
@somebody1234
Copy link
Contributor Author

... actually, this implementation does not work when the module name is hidden (so, for submodules)

@somebody1234 somebody1234 marked this pull request as draft October 18, 2023 07:58
@somebody1234 somebody1234 marked this pull request as ready for review October 18, 2023 09:03
@farmaazon
Copy link
Contributor

  • Things like h.m match HTTP_Method - if this is not intentional, it seems like it might be more difficult to fix, unfortunately.
    • Note that highlighting (I assume correctly?) does not highlight any part of HTTP_Method.

Yes. The thing is that we always try to match the qualified path of given entry, even of those parts which are not visible. In this case, HTTP_Method is inside HTTP module, so h matches first letter of HTTP module and m matches sixth letter of HTTP_Method. The module is not displayed, so we should highlight HTTP_Method

@somebody1234
Copy link
Contributor Author

@farmaazon yeah, I realized that later. it should now work correctly in the current version

app/gui2/src/components/ComponentBrowser/component.ts Outdated Show resolved Hide resolved
app/gui2/src/components/ComponentBrowser.vue Outdated Show resolved Hide resolved
const suffix = match[match.length - 1]
if (suffix) yield { text: suffix, type: 'no-match' }
}

Copy link
Contributor

@farmaazon farmaazon Oct 18, 2023

Choose a reason for hiding this comment

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

I'd highly prefer to have the algorithm for obtaining matched letters somewhere as API for Filtering class, even as part of filter method. If the filtering/scoring algorithm will change (and it might), one would not have to remember about another place in the code to fix.

I think the filter method should return matched ranges, and label field of Compnent type could have information about matched letters in the label only. The code should be unit tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@farmaazon wdym by this?

label field of Component type could have information about matched letters in the label only

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(do you mean the match field should have information about matched letters in the label only?)

@somebody1234
Copy link
Contributor Author

... oops, the new version doesn't quite work

@somebody1234
Copy link
Contributor Author

... oh, it's also missing unit tests

@somebody1234 somebody1234 marked this pull request as draft October 18, 2023 14:34
@somebody1234 somebody1234 marked this pull request as ready for review October 19, 2023 06:28
app/gui2/src/components/ComponentBrowser/filtering.ts Outdated Show resolved Hide resolved
app/gui2/src/components/ComponentBrowser/filtering.ts Outdated Show resolved Hide resolved
app/gui2/src/components/ComponentBrowser/filtering.ts Outdated Show resolved Hide resolved
app/gui2/src/components/ComponentBrowser/filtering.ts Outdated Show resolved Hide resolved
app/gui2/src/util/database/__tests__/reactiveDb.test.ts Outdated Show resolved Hide resolved
@@ -64,7 +70,7 @@ export function qnJoin(left: QualifiedName, right: QualifiedName): QualifiedName
* The element is considered a top element if there is max 1 segment in the path.
*/
export function qnIsTopElement(name: QualifiedName): boolean {
return (name.match(/\./g)?.length ?? 0) <= 2
return !/[.].*?[.].*?[.]/.test(name)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm ok with this change, only I'm curious why it is here? It is more performant, or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i haven't confirmed whether it's more important, but: it doesn't have to store the match strings, nor create an array, nor are there any conditionals caused by optional chaining
so at the very least i don't think it's less performant

interface ComponentLabel {
label: string
matchedAlias?: Opt<string>
matchedRanges?: MatchRange[]
Copy link
Contributor

Choose a reason for hiding this comment

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

We will also want to highlight letters in matched alias at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah - this is why (i'm pretty sure) matchedRanges is present even when matchedAlias is present. i can add tests to verify the ranges are correct when the matchedAlias is present?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tests for matchedAlias have now been added (which did catch a bug)

@somebody1234
Copy link
Contributor Author

@Frizi i think this should be ready for your review now

Comment on lines 41 to 55
const actualConsoleError = console.error
console.error = () => {}
try {
const consoleError = vi.spyOn(console, 'error')
// Invalid index
new ReactiveIndex(db, (_id, _entry) => [[1, 1]])
db.set(1, 1)
db.set(2, 2)
expect(consoleError).toHaveBeenCalledOnce()
expect(consoleError).toHaveBeenCalledWith(
'Attempt to repeatedly write the same key-value pair (1,1) to the index. Please check your indexer implementation.',
)
} finally {
console.error = actualConsoleError
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of this manual spy restore, it's better to enable automatic mock restoring before each test.

https://vitest.dev/config/#restoremocks

@somebody1234 somebody1234 added the CI: Ready to merge This PR is eligible for automatic merge label Oct 19, 2023
@mergify mergify bot merged commit 895326d into develop Oct 19, 2023
@mergify mergify bot deleted the wip/sb/cb-highlight-matches branch October 19, 2023 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-gui CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Highlight matched letters in CB
3 participants