-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Rust: Improve lines-of-code counts. #17588
base: main
Are you sure you want to change the base?
Conversation
@@ -44,7 +45,9 @@ class File extends Container, Impl::File { | |||
result = | |||
count(int line | | |||
exists(AstNode node, Location loc | | |||
not node instanceof SourceFile and loc = node.getLocation() | |||
not node instanceof Module and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this change. The module isn't the problem. The problem are the /* */
comments which syntactically belong to the mod
, struct
, macrorule
, etc. that follows them. Just verify for yourself using the AST viewer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I see what you mean now, Module
is a module decl not a module. I'm going to have to get used to that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Is there an easy way to use the AST viewer on a test?
Is there an issue for the location problems (or should I create one)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the AST viewer works fine on test databases these days. I just built a database running codeql test run --keep-databases
, loaded it in vscode, ran from File f select f
, click on a file, and right-click "view AST" in that file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That method for tests is a bit of a fiddle unfortunately, but good to know the AST viewer now works for Rust. I had investigated using an adhoc query to print all the AstNode.toString()
s associated with each line of each file, which worked - though I didn't get a hierarchy.
Anyway I've created an issue for the locations problems.
In general using A pretty simple way to deal with this problem is to ignore the start line for top-level items. That would under count in cases like fn
my_function() {...} but that would be extremely rare. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good to me. However, you could implement special handling of top-level items to avoid counting doc comments as a line.
Improve lines-of-code counts:
Module
from the count, which was spuriously adding +1 LOC inmain.rs
.println!
in the tests, since these should be deterministically (if not correctly) extracted now.@aibaars - also note that we have a spuriously located
MacroRules
(onmy_macro.rs
line 1) andStruct
(onmy_struct.rs
line 2), which I discovered while debugging this query. I haven't done anything about them, I believe the right fix would be in the extractor.Obviously types are still not extracted, which is also affecting the counts.