Code::Completion Rewrite

From CodeBlocks
Revision as of 17:09, 11 March 2008 by Stevenkaras (Talk | contribs) (Current Effort)

Jump to: navigation, search


The current Code::Completion plug-in has some flaws, and is currently development frozen. The current plug-in lacks full support for:

  1. function and class templates
  2. default arguments in some cases
  3. some of the more complicated c++ mucky business

Current Effort


The current C::C is a monolithic library of features, which could be de-coupled and split up for use in multiple plugins, providing extra functionality and flexibility in the future. Therefore, I propose the C::C be broken up into the following components:

  • Code::SymbolTable
    • Provide a list of valid symbols in the workspace, along with relevant scope information
  • Code::Completion
    • Provide Auto-complete features
  • Code::SymbolOutline
    • Provide Symbol browser, find symbol, function jump features
  • Code::Refactoring
    • Provide code refactoring features
  • Code::Documentation
    • Provide automatic code generation features


Purpose Statement

The current Code::Completion plugin is outdated, and needs a complete rewrite. The purpose of the Code::Completion plugin is thus:

  • Provide a list of likely symbols in the current scope as possible solutions to the current symbol.
  • Provide function tooltips
    • Parameter list
    • Relevant documentation
  • Provide completion features for class constructors
  • Provide completion features for initializer lists


  1. Generate a list of all valid symbols in the current scope
    1. Take global list from C::SymbolTable
    2. Add in local scope parsed on the fly
  2. Reduce that list to what is likely
  3. Show that list to the user in some fashion
  4. Insert the proper solution on user request


There will be 3 symbol lists:

  1. global namespace
  2. local scope
  3. class scope

Here's the current data proposal:

class symbol
    string name;              // name of the symbol
    int    id;                // Id of the symbol, should be unique in the workspace
    int    file_id;           // Id of file where the symbol has been declared
    int    filepos_begin;     // Position where declaration of the symbol starts
    int    filepos_end;       // Position where declaration of the symbol ends
    int    type;              // Type of the symbol: macro / class / typedef / variable / function
    flags  modifiers;         // Bitfield used to mark some estra properties of symbol
                              // like that it is static or inline
    int    value_type_id;     // Id of symbol which represents c++ type of current symbol
                              // (like type of variable or type of returned value from function)
    int    extra_type_id;     // Extra type used in some cases
    list   children;          // List of child elements of this symbol (members in class etc)
    list   extra_lists[3];    // See table below
    map    extra_values;      // int -> string map which can keep some extra data
class list_entry
    int    symbol_id;         // ID of the symbol referenced
    int    storage_class;     // Storage class of the symbol (private/protected/public)

Explanation of symbol::extra_lists[]

type modifiers value_type_id extra_type children extra_lists[0] extra_lists[1] extra_lists[2]
namespace declarations in namespace "using" namespaces
class / struct / union members of class base classes template args friends of class
variable extern, static, volatile, const type of variable
function static, inline, const ... returned value arguments template arguments
typedef pointer, array, reference, pointer_to_member base type type of class in pointer_to_member
enum items in enum
enum item id of enum
macro macro parts
macro part arg_to_string, va_args number of arg or -1


  • Such representation would require some extra "hidden" symbols - for example when some complex type is returned from function, extra symbol of typedef representing proper value would be required.
  • Also in case of templates, typeid's should be threated in special way - negative value could mean to use template argument instead of some real type. Base types (the POD ones) should have some predefined type ids.


  • why are we storing filepos_end? Wouldn't it be much more useful to store declaration, definition info?

More complex cases of C::C usage

Here we can put some more complex examples of c++ code where C::C may fail. Symbols that may be hard to find should be marked in bold

1: Fetching type of operator call

#include <string>
using namespace std;

int main(int,char**)
    ( string("first") + "second" + "third" ) . c_str();
    return 0;

2: Template classes

template<typename T> class Template
    T& GetInstance() { return m_Instance; }
    T m_Instance;

class Parameter
    void PrintfText() { printf("Text"); }

int main(int,char**)
    Template<Parameter> Object;