Visitar URL original
Tree sitter extractor: Proper handling of `LGTM_INDEX_FILTERS` by RasmusWL · Pull Request #15365 · github/codeql · GitHub
The Wayback Machine - https://web.archive.org/web/20240126101850/https://github.com/github/codeql/pull/15365
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

Tree sitter extractor: Proper handling of LGTM_INDEX_FILTERS #15365

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

RasmusWL
Copy link
Member

If someone had used LGTM_INDEX_FILTERS=exclude:**/*\ninclude:*.rb
before, we would have mistakenly excluded all files :|
(LGTM_INDEX_FILTERS is a prioritized list where later matches take
priority over earlier ones)

This change is needed to support adding exclude:**/* as the first
filter if paths include a glob, which currently causes bad behavior in
the Python extractor. However, we can first introduce that change once
this PR has been merged.

I realize this change can cause more folders and files to be traversed
(since they are not just skipped with --exclude). We plan to make a
better long term fix which should bring back the previous performance.

If someone had used `LGTM_INDEX_FILTERS=exclude:**/*\ninclude:*.rb`
before, we would have mistakenly excluded all files :|
(LGTM_INDEX_FILTERS is a prioritized list where later matches take
priority over earlier ones)

This change is needed to support adding `exclude:**/*` as the first
filter if `paths` include a glob, which currently causes bad behavior in
the Python extractor. However, we can first introduce that change once
this PR has been merged.

I realize this change can cause more folders and files to be traversed
(since they are not just skipped with --exclude). We plan to make a
better long term fix which should bring back the previous performance.
@aibaars
Copy link
Contributor

aibaars commented Jan 18, 2024

Q4 for QL is failing. Might be related to the change in this PR because that check excludes some paths using LGTM_INDEX_FILTERS

@RasmusWL
Copy link
Member Author

looks that way yes. I'll do some debugging 👍

LGTM_INDEX_FILTERS: |
exclude:ql/ql/test
exclude:*/ql/lib/upgrades/
exclude:java/ql/integration-tests

@RasmusWL
Copy link
Member Author

I had not thought it through properly in terms of the tree-sitter extractor and --also-match, so had to make another commit with a fix. It outlines the 3 different cases where filters are present. Although this is a bit tricky, I hope reviewers will be easily convinced the behavior is the same as before.

@RasmusWL
Copy link
Member Author

Ah yes, I should have mentioned that I struggled a bit with the rust code. I'll admit I'm not super proficient, so couldn't get rid of the tmp assignment. I'm more than happy to change this bit of the code if you have better solutions 😊

Copy link
Contributor

@henrymercer henrymercer left a comment

Choose a reason for hiding this comment

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

This makes sense to me, but I'd like someone more familiar with the tree-sitter extractor to approve.

.any(|s| s.starts_with("exclude:"));

if !lgtm_index_filters_has_include && lgtm_index_filters_has_exclude {
cmd.arg("--also-match=**/*");
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe --also-match=** is equivalent

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.

None yet

3 participants