-
Notifications
You must be signed in to change notification settings - Fork 588
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
[C] Improve Goto Definition and Goto Reference #1831
base: master
Are you sure you want to change the base?
Conversation
Could we add tests for this construct to the other C variants to make sure it get inherited? |
Done. I need to find some time to give the C syntax some love. |
Don't merge this yet... I have a couple other fixes for this. |
So correctly fixing this involved a lot more changes then I expected. Fixes sublimehq#1830 Signed-off-by: Raul E Rangel <[email protected]>
So actually fixing struct required a lot more work. I'm pushing up my WIP to get some initial feedback. You can ignore all the Feature Request, It would be cool if I could enable a syntax developer mode where the context that applied a scope could be determined. Then I could avoid adding all the `debug.* scopes manually. I was also wondering why the Monokai theme doesn't highlight function arguments?
I actually almost got them scoped correctly now, so it would be nice to see them highlighted by default. |
I chose to mark the struct name in a typedef as an entity because it's still possible to use `struct MyStruct` in code so we should be able to navigate to the symbol if it's referenced that way.
I fixed typedef used with struct declarations and function pointers. Let me know if I'm missing any other cases. I might start cleaning up |
The struct|union|enum keyword scopes now act like any other type. This reduces the number of specific scopes required.
So I simplified my changes. This reduces the number of top level struct scopes to 1 instead of the three I had. I also fixed There are still some failing cases that I need to work through. Thought I wonder how legit they are. Expressions in a function declaration?
Macro invocation return types. Should figure out a way to support this.
Function without the
Still a WIP, but if anyone wants to test it that would be appreciated :) |
Looks like the preprocessor-practical-workarounds are causing issues. I don't think they are needed anymore. I'll play around with removing them. |
So I fixed the highlighting for macro function calls and macros as types. I think it's looking pretty good except for the couple of edge cases I posted above. |
This doesn't support disabling a block with `#if 0`. That requires that we redefine `preprocessor-data-structures` since enum body has a different context.
linux kernel defines __macro as a prprocessor macro for setting attributes. I also found this style in other firmware type C code.
We don't want to gobble up actual function definitions.
Also made it so the assignment expressions highlight constants.
I think the function params block might need to be rewritten. It can't handle the case: fn(int var __attribute__((unused).
Merged in upstream/master. Should be ready for review again. |
@ismell maybe you could:
|
Oh no! Merge conflicts. 😞 |
Yeah, I stopped working on this since Will told me he wanted to fix |
That would be appreciated. Will isn't working for SublimeHQ anymore. The remaining team seems to be focused on other stuff (currently) and has assigned some collaborators to take care of syntaxes (for them). So this would be useful until somebody tackles a c languages rewrite using inheritance. |
Had to fix some integer naming changes.
Conflicts: C++/C.sublime-syntax C++/syntax_test_c.c Adapted to the new structure and updated tests.
My patch already had robust typedef support. I just added the additional test case.
Oops, I should have tested the cpp syntax as well. I'll push a fix. |
This file never conflicted in the chain of merges, so the merge algorithm missed it somehow. Signed-off-by: Raul E Rangel <[email protected]>
All tests are passing. |
Can one of the new reviewers take a look? |
Any hopes of getting this merged in? It will unblock others from improving upon it. |
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.
Maybe not enough package maintainers use C/C++ to feel a value in reviewing. There are other C/C++ related PRs pending.
Another reason might be the long pending idea of fully rewriting C family syntaxes from scratch to reduce duplication by ST4's inheritance feature and to fix all the open issues. The content of this PR would very likely be subject of heavy changes as well then.
I can't find major flaws with a shallow view at the sources, but don't use the syntaxes enough to judge the changes.
comment: Struct definition | ||
set: struct-body | ||
- match: '{{identifier}}' | ||
scope: support.type.c |
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.
Now that we use keyword.declaration
for struct
keyword, storage.type
or storage.type.struct
for user defined data types. But why do you distinguish declaration from definition? I'd call it entity.name.struct
in both cases.
@@ -395,23 +437,43 @@ contexts: | |||
|
|||
global: | |||
- include: early-expressions | |||
- match: '^\s*(?=\w+)' | |||
push: global-modifier |
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.
Named contexts help with inheritance. So turning them into anonyomous ones feels like a step backward.
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.
Yeah, this was all written before ST4 when the names weren't really useful for debugging. I can pull it out.
Right, there has been a lot of duplicated effort since this PR has sat for so long.
I agree, it could use some modernization, but getting all the test cases landed would be a huge benefit to aiding in the refactor. Side note, I have no idea how to use Github's PR interface... |
Merging requires approval from at least 2 authorized contributors. |
In my journey to fix #1830 I ended up re-writing a lot of the syntax. It now more accurately scopes
entity.name.*
and preprocessor macros. My goal is to makeGoto Definition
andGoto Reference
work a lot better then they currently do.Function parameters are also scoped better, so we should remove
source.c
from the MonokaiFunction argument
style.Tests have been greatly improved. I mostly tested this syntax on the linux kernel and various firmware projects.
My goal is to implement #1861. This will require theme changes though. I think we should blacklist
entity.name.variable
from theEntity name
style.Before
After