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
scip-ctags: Fix line number mismatch due to scopes #62345
Conversation
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.
This makes sense to me. We are emitting the lines for identifiers, so it's appropriate to use the identifier range. And I think the Python query was just an oversight on my part, the scope should indeed be the class definition.
I'm not an expert here and it'd be great to get @varungandhi-src 's thoughts too !
docker-images/syntax-highlighter/crates/syntax-analysis/src/ctags.rs
Outdated
Show resolved
Hide resolved
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.
The @scope
marking change is consistent with how we're handling it for other types, so that's OK. Unfortunately, the terminology scope
itself here is somewhat misleading/not appropriate (it should probably be something like declcontainer
or similar, I have not looked too closely at all usages). We also have @scope
for locals queries, and it means something quite different there.
Using ident_range
rather than scope_range
looks correct. However, I noticed that there aren't any doc comments on the field names at the struct definition, it would be worthwhile to fix that.
The C# test looks OK but you could trim it down further. The larger the test case, the more someone needs to read or skim over when they're looking at it.
For these kinds of PRs, generally, it is helpful to follow a 2-commit pattern. First commit is you add a test case and update the snapshot output showing the wrong result. Second commit you tweak the code and update the snapshot again. This way the diff in the snapshot resulting from the diff in the code becomes immediately understandable.
As for formatting, we previously had a rustfmt.toml
file but hadn't set up formatting using Bazel, I've opened a PR for that here. #62371
Not a fan of bundling several unrelated changes into the same PR. If you're having to write a summary with 3-4 unrelated points, that's a strong sign that the PR needs to be broken up. 👎🏽
docker-images/syntax-highlighter/crates/syntax-analysis/testdata/globals.cs
Show resolved
Hide resolved
56b163f
to
52b635d
Compare
Fixes PRIV-3054
scip-ctags is mis-attributing the some identifiers to the start of the scope versus the location of the identifier. I found this issue in both the C# and Python implementations of scip-ctags and saw two different reasons.
Quick Summary
ident_range
instead ofscope_range
(all tests pass) (Need @varungandhi-src to validate if this is fundamentally wrong)scip-tags.scm
to mark the scope as the whole class declaration and not just the body (technically not required with # 1 above but seems semantically correct to say the class declaration line is part of the scope)Details
Python
In python we have the @scope declared as the body of the class declaration, changing this to the whole declaration mitiages the issue
C#
However, for CSharp the issue is a bit different. In CSharp we are misattributing the line number whenever a class has an attirubte on it . For example
This is because the class declaration in the tree sitter grammar for C# includes the attributes as part of the scope.
C#
scip-tags.scm
C# grammar
There for I think in our scip-ctags logic, we should not use
scope.scope_range.start_line
and instead usescope.ident_range.start_line
since in for scip_ctags we care about the identifier location and not the start of the scope.Test plan