Author Topic: Simple word completion for non-c++ files?  (Read 2728 times)

Offline koonschi

  • Multiple posting newcomer
  • *
  • Posts: 27
    • My personal project
Simple word completion for non-c++ files?
« 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.
"As a general rule, the compiler is smarter than you, and working in your best interest. Do not question it." - Terry Mahaffey

#define TRUE FALSE // happy debugging suckers

Offline yvesdm3000

  • Almost regular
  • **
  • Posts: 225
Re: Simple word completion for non-c++ files?
« Reply #1 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

Clang based code completion for Code::Blocks:   http://github.com/yvesdm3000/ClangLib

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5915
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Simple word completion for non-c++ files?
« Reply #2 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.  :)

« Last Edit: February 19, 2016, 03:29:27 pm by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline yvesdm3000

  • Almost regular
  • **
  • Posts: 225
Re: Simple word completion for non-c++ files?
« Reply #3 on: February 19, 2016, 05:23:22 pm »
I agree this would be a good start.

Yves
Clang based code completion for Code::Blocks:   http://github.com/yvesdm3000/ClangLib

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Simple word completion for non-c++ files?
« Reply #4 on: February 20, 2016, 04:46:46 pm »
Remember that for word completion altering / adjusting the LUA lexer might be enough.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ