Sublime Forum

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

#1

Hi,

Just giving ST3 a spin, and have found that ‘Goto Definition’ fails to go to enumeration values…

So with this example (test.cpp)…

typedef enum MyTestEnum
{
	enum1,
	enum2,
	enum3
} MyTestEnum;

MyTestEnum TestFunction(void)
{
	return enum2;
}

… selecting ‘enum2’ within TestFunction() and then pressing F12 results in ‘unable to find enum2’. Actualy, selecting ‘MyTestEnum’ and then pressing F12 also results in a failure to find the definition (‘unable to find MyTestEnum’).

Would it be possible to enhance the symbol indexing in ST3 to handle enumerations (and the enumerated values within)?

Many thanks,
Dean

0 Likes

#2

Not working for me too. Serious Issue.

0 Likes

#3

I was just trying st3 and hit this as well. Seeing as the first question was posted a year ago, there been any movement? Was hoping to switch to sublime, but without enum parsing that basically kills it for me

0 Likes

#4

With the help of C Improved package. Goto Definition (F12) can find the definition of MyTestEnum.

0 Likes

#5

I’ve installed the “C Improved” package, switched to the “C Improved” syntax for my .h file with enum definitions. But it is still now working - my enum usage will not jump to the enum definition on F12. Anything else need to be done ?

0 Likes

#6

The default C++ package included in recent builds of ST3 properly handles enums with Goto Definition. I just tested with build 3120.

0 Likes

#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