User forums > Using Code::Blocks

Simple word completion for non-c++ files?

(1/1)

koonschi:
I have a project that includes lots of lua files, and since codeblocks is by far my favorite IDE I edit those in codeblocks, too. The problem is that lua is very context sensitive and normal code completion is basically impossible. But I've noticed that other editors have a word completion feature, where basically all words in the current document are parsed and proposed for completion (see geany, scite or notepad++).

Does codeblocks have such a word completion feature? Even if just for non-c++ files?

If not, is it on the radar? I'd be happy to provide a patch if you give me some pointers as to where to start.

yvesdm3000:
I don't think this should be difficult.

You can create a plugin and on top of the normal plugin-functions implement following functions:

cbCodeCompletionPlugin::CCProviderStatus YourPlugin::GetProviderStatusFor( cbEditor* ed )
--> Return 'ccActive' if you support this file

std::vector<cbCodeCompletionPlugin::CCToken> YourPlugin::GetAutocompList( bool isAuto, cbEditor* ed, int& tknStart, int& tknEnd )
--> Return your codecompletion results, in your case maybe your full list

bool YourPlugin::DoAutocomplete(cbCodeCompletionPlugin::CCToken& token, cbEditor* ed)
--> To insert your code completion result

Now building your database might be a little bit more tricky since you need to parse your document, but you can install an EditorHook where your plugin gets triggered every time the user changes the document, you could even just reparse the current line to keep the operation lightweight.

Yves

ollydbg:

--- Quote from: yvesdm3000 on February 19, 2016, 01:58:01 pm ---I don't think this should be difficult.

You can create a plugin and on top of the normal plugin-functions implement following functions:

--- End quote ---
I totally agree, I think creating a tiny plugin is needed.



--- Quote ---cbCodeCompletionPlugin::CCProviderStatus YourPlugin::GetProviderStatusFor( cbEditor* ed )
--> Return 'ccActive' if you support this file

std::vector<cbCodeCompletionPlugin::CCToken> YourPlugin::GetAutocompList( bool isAuto, cbEditor* ed, int& tknStart, int& tknEnd )
--> Return your codecompletion results, in your case maybe your full list

bool YourPlugin::DoAutocomplete(cbCodeCompletionPlugin::CCToken& token, cbEditor* ed)
--> To insert your code completion result

Now building your database might be a little bit more tricky since you need to parse your document, but you can install an EditorHook where your plugin gets triggered every time the user changes the document, you could even just reparse the current line to keep the operation lightweight.

Yves

--- End quote ---

To parse the current active editor's content, I think the only interested events are:

cbEVT_EDITOR_ACTIVATED, when this event is received, read the content of the editor, and use a simple lexer to get all the tokens, and store them in a database.

cbEVT_EDITOR_SAVE, when this event is received, this means the user has changed the content of the editor, so you may need to reparse the database.

For simplicity reasons, I think you don't need to use EditorHook.  :)

yvesdm3000:
I agree this would be a good start.

Yves

MortenMacFly:
Remember that for word completion altering / adjusting the LUA lexer might be enough.

Navigation

[0] Message Index

Go to full version