Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: koonschi on February 19, 2016, 12:35:02 pm

Title: Simple word completion for non-c++ files?
Post by: koonschi on February 19, 2016, 12:35:02 pm
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.
Title: Re: Simple word completion for non-c++ files?
Post by: 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:

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

Title: Re: Simple word completion for non-c++ files?
Post by: ollydbg on February 19, 2016, 02:22:03 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:
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

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.  :)

Title: Re: Simple word completion for non-c++ files?
Post by: yvesdm3000 on February 19, 2016, 05:23:22 pm
I agree this would be a good start.

Yves
Title: Re: Simple word completion for non-c++ files?
Post by: MortenMacFly on February 20, 2016, 04:46:46 pm
Remember that for word completion altering / adjusting the LUA lexer might be enough.