Skip to content

Add queries for VS Code jump-to-definition #3308

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 9 commits into from
May 8, 2020

Conversation

jcreedcmu
Copy link
Contributor

The tags on these queries are a tentative proposal for how to signal to the vscode extension that they are the right template queries to run for jump-to-definition and find-references. I am very open to anything from bikeshedding their exact names, to arguments for using other mechanisms instead of tags.

* for jump-to-definition in the code viewer.
* @kind definitions
* @id cpp/jump-to-definition
* @tags local-definitions
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about:

@tags ide-contextual-queries/local-definitions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, done.

@jcreedcmu jcreedcmu force-pushed the jcreed/jump-to-def branch from d9729c2 to 6a59ce3 Compare April 21, 2020 20:11
@jcreedcmu
Copy link
Contributor Author

Possible arguments for "why use @tags and not @id to locate the distinguished query/queries" include
(1) Maybe we would in principle want multiple queries that all contribute definition-use pairs, instead of one?
(2) The extension can always look for the same specific tag name, across all languages, as opposed to needing to map "ok this is the c++ qlpack, so I need to prefix cpp/ to some chosen string like jump-to-definition, at least assuming we're required to follow the convention that all query ids for $LANGUAGE begin $LANGUAGE/.

@jbj
Copy link
Contributor

jbj commented Apr 22, 2020

Possible arguments for "why use @tags and not @id to locate the distinguished query/queries" include ...

Those are good arguments, so let's focus on the possibility of using @kind instead.

@alexet
Copy link
Contributor

alexet commented Apr 22, 2020

The reason is that @kind is meant to represent the type of the output of the query and how it should be processed. This is exactly the same for this definitions query as the original query. Originally I added a new kind but it shares all code paths with the existing kind. The only other use of @kind is for filtering but tags also exist for that case. I think tags make more sense for filtering than kinds (although we will have to swtich the existing suite to find the definitions query by a new tag rather than by kind) as that is the purpose of tags. I am not completely opposed to adding a new @kind but I do feel like that is bending the purpose of @kind.

@alexet
Copy link
Contributor

alexet commented Apr 22, 2020

Note that classify files does require different processing so it does need a new kind.

@jbj
Copy link
Contributor

jbj commented Apr 22, 2020

although we will have to swtich the existing suite to find the definitions query by a new tag rather than by kind

Yes, and that can be done without changing LGTM since we'll just tweak the scripts to produce a suite with exactly one @kind definitions query.

Thanks for clarifying. I have no further objections to classifying by tag.

jbj
jbj previously approved these changes Apr 22, 2020
Copy link
Contributor

@jbj jbj left a comment

Choose a reason for hiding this comment

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

LGTM except formatting

@alexet
Copy link
Contributor

alexet commented Apr 22, 2020

We do need to tweak the current codeql suites though.

@jcreedcmu
Copy link
Contributor Author

Is the above commit sufficient for 'tweak the current codeql suites'? semmle/code/ql/cpp/ql/src/codeql-suites/cpp-lgtm.qls already doesn't include localDefinitions.ql and localReferences.ql when I codeql query resolve it, and I don't see any other .qls files in cpp.

@rdmarsh2
Copy link
Contributor

Perhaps the @kind should be something like codenav rather than definitions?

@jcreedcmu jcreedcmu force-pushed the jcreed/jump-to-def branch from 6f13e30 to d49e936 Compare April 23, 2020 14:20
@max-schaefer
Copy link
Contributor

Does the script for generating the LGTM query suites need to be updated as well?

external string selectedSourceFile();

cached
File getEncodedFile(string name) { result.getAbsolutePath().replaceAll(":", "_") = name }
Copy link
Contributor

Choose a reason for hiding this comment

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

Move to definitions.qll?

@jcreedcmu
Copy link
Contributor Author

Does the script for generating the LGTM query suites need to be updated as well?

Good question; I'm trying to find a ./build target that actually erroneously includes localDefinitions.ql and localReferences.ql and I'm failing so far. I see in Semmle/code/build the build rule

    genrule(lang+'-lgtm-suite',
            inputs = [ 'buildutils-internal/scripts/generate-lgtm-suites.py' ],
            rec_inputs = [ [ 'language-packs/' + lang + '/ql/src', 'language-packs/' + lang + '/ql/src' ] ],
            outputs = [ lang + '-lgtm' ],
            commands = [
                'python2 generate-lgtm-suites.py ' +
                ' -a' +
                ' -l ' + lang +
                ' -o ' + lang + '-lgtm' +
                ' -p ' + lang +
                ' -r ' + '\'$${semmle_dist}/language-packs/' + lang + '/ql/\''
                ' language-packs/' + lang + '/ql/src'
            ])

but when I run ./build target/packs/pack-cpp-lgtm-suite.zip the invocation of generate-lgtm-suites.py I see

cd target/general/lgtm-query-suites/working && python2 /home/jcreed/semmle/code/buildutils-internal/scripts/generate-lgtm-suites.py -o cpp-alerts-lgtm semmlecode-cpp-queries

which lacks the -a flag, which consequently doesn't include localDefinitions and localReferences. (When I run the script manually with -a, it does include them)

Any idea where that script is invoked with -a somewhere? If so, then I might agree we need to modify it to exclude queries tagged ide-contextual-queries/local-{definitions,references}.

@max-schaefer
Copy link
Contributor

max-schaefer commented Apr 29, 2020

I think ./build target/packs/pack-go-lgtm-suite.zip should do the trick.

EDIT: No, I lie. Try ./build target/general/go-lgtm-suite/output/go-lgtm.

@jcreedcmu jcreedcmu force-pushed the jcreed/jump-to-def branch from e20dd5d to b82db2f Compare April 29, 2020 13:54
@jcreedcmu
Copy link
Contributor Author

I think ./build target/packs/pack-go-lgtm-suite.zip should do the trick.

EDIT: No, I lie. Try ./build target/general/go-lgtm-suite/output/go-lgtm.

Ok, both of those generated a commandline with -a for me. Any explanation for why that happens with golang and not the other languages?

@jcreedcmu
Copy link
Contributor Author

In any event, raised https://git.semmle.com/Semmle/code/pull/36810 to exclude queries by tag.

@jcreedcmu jcreedcmu force-pushed the jcreed/jump-to-def branch from b82db2f to e73833e Compare April 29, 2020 14:15
@max-schaefer
Copy link
Contributor

Any explanation for why that happens with golang and not the other languages?

The legacy languages specify parts of their LGTM suites manually. For Go everything is auto-generated.

@jbj
Copy link
Contributor

jbj commented May 4, 2020

Since this can have performance implications for the LGTM suite, I’d like to wait until the CPP-Differences jobs for #3400 have finished and then run CPP-differences for this PR too.

I assume it’s not urgent to merge this since it’s targeted at master, and the lgtm.com branch will be based on 1.24 for a while yet.

@jbj
Copy link
Contributor

jbj commented May 7, 2020

I've started https://jenkins.internal.semmle.com/job/Changes/job/CPP-Differences/1107/ to test this PR for performance.

Copy link
Contributor

@jbj jbj left a comment

Choose a reason for hiding this comment

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

Performance LGTM. There's a noticeable slowdown on Wireshark, but that affects other queries too, so I think it's just noise.

@jcreedcmu jcreedcmu merged commit c9788a7 into github:master May 8, 2020
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.

7 participants