Sublime Forum

ST3 : 'Goto Definition' and C/C++ enumerations

#7

Hi,

Interesting. I’m using Build 3120 as well, created a file test.cpp containing the code from my original post back in February 2013, highlighted ‘enum2’ and pressed F12, and I continue to be told “unable to find enum2”.

Selecting ‘MyTestEnum’ and then pressing F12 results in it finding MyTestEnum, but enumeration member lookup still fails in the way originally described.

I have no packages installed… this is just an out-of-the-box ST3 installation with only a few minor settings changes for things like auto indent, tabs etc.

Dean

0 Likes

#8

You can try the process outlined at http://www.sublimetext.com/docs/3/revert.html to ensure you are using nothing but the default config. An alternative on Windows is to download a portable install.

0 Likes

#9

Hi Will,

Thanks for the reset advice.

I’ve just re-tested using nothing but default settings, and the observed results remain the same as just described. That is, F12 on the enumeration type (‘MyTestEnum’) associates with a definition correctly and results in going to the definition, but F12 on an enumeration value (‘enum2’) fails to associate with a definition, and consequently results in output to the status bar of ‘unable to find enum2’.

Dean

0 Likes

#10

Ah, I see the distinction now. Yes, currently we only index the enum type name (MyTestEnum), but not enum values.

0 Likes

#11

Ta for the confirmation as to current behaviour.

Going back to (part of) my original request/post from a few years ago, it would be great if symbol indexing in ST3 could be enhanced to handle enum values.

Cheers,
Dean

0 Likes

#12

You can post enhancement requests to the default packages at https://github.com/sublimehq/Packages/issues.

To implement such a feature, it needs to be decided what the appropriate scope for the enum value definitions should be, and then that scope just needs to be added to the Symbol Index.tmPreferences file.

0 Likes

Updating sublime text removes all my custom syntax fixes
#13

It works if you do 3 changes in the “C.sublime-syntax” file and another 3 changes in “C++.sublime-syntax” file. Due to forum rules I can only attach images.
You find these files if you go to /SublimeInstallDir/Packages/, rename the file “C++.sublime-package” to “C++.sublime-package.zip”. Open with zip editor and extract the upper files. Don’t forget to backup the original(s).

1 Like

#14

That’s excellent - it seems to work well in my initial tests. Thank you!

@wbond, if these changes look good to you, is there a chance that they would be considered for inclusion into the distributed C++ sublime package?

0 Likes

#15

You can create a PR at https://github.com/sublimehq/Packages and it will get reviewed/discussed :slight_smile:

3 Likes

#16

@christoph314, are you ok with me creating a PR as @kingkeith suggests above? Or would you prefer to do so yourself?

Thought it best to check, seeing as they’re your modifications! :slight_smile:

0 Likes

#17

Hi Dean, I am allright if you create this PR, thank you. Please make a remark anywhere that the original idea came from my side. Thanks again!

0 Likes

#18

What ever happened with this? As of today I can not get enumerations to show in Goto Definitions when I hover over the name of an enum type.
In my case the file types are mixed C / C++
Does it depend on the syntax of the enum entry?
enum keyword { type,… }; VS typedef enum { type,… } keyword;

0 Likes

#19

Yes. In C you need a typedef, in C++ you don’t.

0 Likes

#20

Adding the typedef did not help. Goto Definitions still did not display.

typedef enum
{
//! Standby
eHm0360ModeStandby = 0x0,

//! Continuous streaming
eHm0360ModeStreaming1 = 0x1,

//! Automatic wake up sleep cycles
eHm0360ModeStreaming2 = 0x2,

//! Snapshot with N frames output
eHm0360ModeStreaming3 = 0x3,

//! Hardware Trigger: Continuous streaming
eHm0360ModeStreaming4 = 0x4,

//! Hardware Trigger: Snapshot with N frames output
eHm0360ModeStreaming5 = 0x5,

//! Hardware Trigger: Automatic wake up sleep cycles
eHm0360ModeStreaming6 = 0x6

}
tHm0360Mode;

0 Likes

#21

Perhaps you have a plugin or custom syntax interfering. Have you tried reverting to a freshly installed state.

Peek%202021-05-12%2012-24

0 Likes

#22

Just 2 plug in, Compare Side-By-Side and Sync View Scroll.
And a couple of added Key bindings.

In your example you are hovering over the enum keyword not the type.
I need to be able to find the value of type in some include file.

enum one_enum {
abc=0,
def,
ghi
};

main(){

int a;

a=abc;   // will not find abc

one_enum b;  // will find one_enum

}

0 Likes

#23

Ah ok, yes the enumerations themselves aren’t currently parsed as definitions.

0 Likes

#24

So what can we do about fixing that?

0 Likes

#25

See https://github.com/sublimehq/Packages/issues/689

0 Likes

#26

Ok I tracked down that link and the links included in it. It lead to a dead end.

I left this comment at the end of the threads on git. Any chance we can get some kind of compromise solution for enum?

Can we change the definition of ready for release from completely working to mostly/somewhat working?
I get that what is mentioned below is the complete list. But how about the basics. C/C++, enum, typedef enum.
It is just a pain to use Find In Files to track down an enum type.
Thanks, Marc

We'll need tests for a number of variations on enum, enum class, typedef enum identifier identifier, typedef enum identifier {} identifier, and typedef enum { } identifier
The changes will need to be ported to the Objective-C and Objective-C++ syntaxes also. The differences in the languages prevent large-scale reuse, so most contexts are duplicated between C/Objective-C and C++/Objective
0 Likes