Sublime Forum

Class view for C++

#1

Hello, how are you doing Folks…

First time Sublime and it’s blazing fast :heart: :runner:

I am currently searching for a plugin or feature to list all functions in Class or even show the path of the function.

Yes, I know about Ctrl + R, but it’s not sufficient in a huge code base (Multiple files with +2K LoCs).

I am searching for something like Class View in Visual Studio… But I haven’t found one yet.

Thanks in Advance

0 Likes

#2

a quick search reveals:
https://packagecontrol.io/packages/CodeMap
https://packagecontrol.io/packages/Class%20Navigator


https://packagecontrol.io/packages/Outline

1 Like

#3

CodeMap is only for Python.

I will try Class Navigator and Outline

0 Likes

#4

Download CodeMap and then install mine on top… It adds mappers for other languages ( C / C++, etc… are planned ) but my mapping system makes it super easy to add them… If you’d like I don’t mind adding support for them today or close-to but I’d have to find some of my C++ files ( cpp, .h, .res others? ) to add the mappings for…

It also supports nested categories and much much more…

I’ll look into adding default support for them - for right now I’d suggest taking a look at a language similar to it such as JavaScript and copying that mapper - or, even better, take a look at the Python and Lua mappers - they add nested categories and support based on the type of information - until I get around to it…

Adding support is as easy as self.AddSyntax( CATEGORY_CLASS, SEARCH_TYPE_STARTSWITH, 'class ', 'function ’ )

I allow VarArgs for a lot of my functions - left is called first - don’t add 'function ’ first if you want to organize ‘function Acecool.C.’ differently because 'function ’ will be triggered for all cases where the other would be too…

I’m trying to add support as quickly as possible for all of the main / important languages in addition to adding a rule system to make scope-detection easier to setup for different languages and other things… along with supporting sublime-settings file-types so I can get rid of all of the CFG_ values, automatically create the accessorfuncs based on data in the config file, and much much more…

I just added a plain-text variant today for someone so I don’t see the issue with adding some basic cpp support…

Edit: Starting work on it… On a side note I found this:

file_extensions:
  - cpp
  - cc
  - cp
  - cxx
  - c++
  - C
  - h
  - hh
  - hpp
  - hxx
  - h++
  - inl
  - ipp

This is one of the reasons why I have been wanting CodeMap back-end to change how it loads mappers because cpp.py can only work for *.cpp - so I’m working on a system to allow classes to be in different files and all of the ext.py files will all be 100% identical ( loading through the sublime-settings files ) so the mapper class for cpp can be used for cpp and other extensions for it ( headers will use similar maps too so… ) and then allow multiple languages to be used per file ( PHP allows 6 or so languages for it’s file-extension and ASP does too… PHP, HTML, CSS, JavaScript, RegEx for PHP and JavaScript, and SQL )

So expect some huge improvements soon! Also I may turn it into a standalone mapping system because it takes too long for the main plugin to be updated not to mention it takes a long time for hotfixes to be propagated to users.

0 Likes

#5

Some good news - I have partial mapping added - I’m working on a larger update but if you want better support for it right now…

Edit xcodemapper.py and add these: to the XCodeMapper base class…




	##
	## Returns the Character Offset from the start of the file to the beginning of the row + num chars to the chosen column
	##
	def GetSublimeViewTextPoint( self, _row = 0, _col = 0 ):
		return self.GetMappedFileView( ).text_point( _row - 1, _col )


	##
	## Returns a region from the lines provided
	##
	def GetSublimeViewRegionByLines( self, _line_number, _line_number_2 ):
		##
		_file_view = self.GetMappedFileView( )
		_region = sublime.Region( self.GetSublimeViewTextPoint( _line_number ), self.GetSublimeViewTextPoint( _line_number ) )

		return _file_view.line( _region )


	##
	## Returns the region of a single entire-line
	##
	def GetSublimeViewLineRegion( self, _line_number ):
		## Grabs the starting point of the line
		_start = self.GetSublimeViewTextPoint( _line_number )

		## Grabs the starting point of the line after it - then subtracts 1 char which should put us on the previous line at the end...
		_end = self.GetSublimeViewTextPoint( _line_number + 1 ) - 1

		return sublime.Region( _start, _end )


	##
	## Return the line number from a provided Region Tuple, or from the char value...
	##
	def GetSublimeViewLineNumberByRegion( self, _region ):
		return self.GetMappedFileView( ).rowcol( _region.begin( ) )[ 0 ] + 1

These work together with the already existing Symbols mapping system ( you will need to edit Run func in the main XCodeMapper so that )

		## Process symbols for the file...
		if ( _file_view != None ):
			self.MappingFileSymbols( _file_view, _file_view.symbols( ) )

is just above the for loop for the lines so


		## Process symbols for the file...
		if ( _file_view != None ):
			self.MappingFileSymbols( _file_view, _file_view.symbols( ) )

		## For Each Line...
		for _line_number, _line in enumerate( _lines, 1 ):

which ensures the view etc… is set…

Then add

	##
	## Callback - these are the symbols from the file we're currently editings symbols( ) from the view - ie all extracted symbols from Sublime Text...
	## In Short: If working this should give us all of the information from the Command Palette when we look at @, :, etc.. for function names and everything... A potentially almost perfect way to create a universal mapper...
	##
	## Task: Allow symbols to be processed through the AddSyntax processor ( Make a syntax processor function outside of Run to do this ) - Then the full-line of code can be grabbed from the symbols SublimeText provides us and we'll have a basic universal mapping system....
	##
	def OnMappingFileSymbols( self, _view, _symbols ):
		## pass
		print( ' >> Symbols: ' + str( _symbols ) )
		## Symbols also don't give their function prefix...
		## if ( _code.startswith( 'def' ):

		## Symbols appear in a list, in a tuple with a region and the symbol...[((515, 525), 'PANEL:Init'), ((891, 910), 'PANEL:ControlValues'), ((1159, 1178), 'PANEL:PerformLayout')]

		## So for each entry
		for _entry in _symbols:
			## Tuples and lists use numerical indices
			## Grab the region object ( chars from start of file to X, and Total Chars in Region + X )
			_region = _entry[ 0 ]

			## Grab the partial code we're given - we can grab the full line using a helper function...
			_code = _entry[ 1 ]

			## Grab the line number using another helper...
			_line_number = self.GetSublimeViewLineNumberByRegion( _region )
			## _line_number = 1

			## Grab the line code by another helper...
			_line = self.GetFileDataByLine( _line_number )

			_file_view = self.GetMappedFileView( )
			_scope_name = _file_view.scope_name( _region.begin( ) )

			## Note - Symbols use regions meaning the starting char of from the entire code blob to the end... not line numbering so this has to be calculated...
			## Since other info is also lost we can really only guess at the data unless we check the file and look at other infomration...
			## self.AddEntry( CATEGORY_FUNCTION, _line_number, _code, _depth, _mode, _pattern, _class_cat )
			self.AddSimpleEntry( CATEGORY_DEFINITION, _line_number, _line.strip( ), 0 )

To your mapper - since the old version doesn’t have CATEGORY_SYMBOLS that other one will work… This uses Sublime Text Symbols meaning it will mean universal mapping for most languages… Or at least close to it…

The next update is pretty large - moves everything into a single folder, still adding sublime-settings support, and a ton of extra things,…

If you want - OnMappingfileSymbols exists without the latest update but the helper function won’t exist - so for _entry in _symbols: will return ( Region, String ) or Tuple with Region and String - Region.begin( ) or .a and Region.end( ) or .b for the first and second element to it… the string is what it finds from the command palette @ menu … I’m working on adding the others and getting more info…

Increased resolution will mean I can make a super light-weight universal mapper based on the back-end systems and the extension addon for those who want more control…

0 Likes