Author Topic: Enable CC on file extensions  (Read 11810 times)

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Enable CC on file extensions
« on: January 03, 2012, 02:59:21 am »
Is their a setting somewhere to tell the CodeCompletion plugin to run on file extensions other than the registered C/C++ ones?

I would like to add *.java files - Java is close enough to C++ that I find CC's suggestions are able to be helpful (when I already have Code::Blocks open and do not want to launch Eclipse).

(P.S. Java lexer available.)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Enable CC on file extensions
« Reply #1 on: January 03, 2012, 03:38:21 am »
Look at Token.cpp

Code
CCFileType CCFileTypeOf(const wxString& filename)
{
    const wxString file = filename.AfterLast(wxFILE_SEP_PATH).Lower();
    const int pos = file.Find(_T('.'), true);
    wxString ext;
    if (pos != wxNOT_FOUND)
        ext = file.SubString(pos + 1, file.Len());

    if (   ext.IsEmpty()
        || ext == _T("h")
        || ext == _T("hpp")
        || ext == _T("tcc")
        || ext == _T("xpm") )
    {
        return ccftHeader;
    }
    else if (   ext == _T("cpp")
             || ext == _T("c")
             || ext == _T("cxx")
             || ext == _T("cc")
             || ext == _T("c++") )
    {
        return ccftSource;
    }
    else
        return ccftOther;
}

So, you can add the java file extension here.

The best way is that it can have a wxTextCtrl in the CC setting dialog.

PS: I'm not sure our CC's parser can correctly parse java source files.
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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Enable CC on file extensions
« Reply #2 on: January 03, 2012, 08:29:02 am »
The best way is that it can have a wxTextCtrl in the CC setting dialog.
That's what I played around with recently. The outcome is attached... That's how it should look like (implementation is still not complete due to a lack of time).
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

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Enable CC on file extensions
« Reply #3 on: January 03, 2012, 08:42:21 am »
In your new design, I found in the new page(C/C++ parser adv), you have:

Keyword sets to additionally include:

But this I think is belong to "code completion" page, not the parser page.
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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Enable CC on file extensions
« Reply #4 on: January 03, 2012, 09:12:02 am »
But this I think is belong to "code completion" page, not the parser page.
True, I actually had in mind to save space... I'll change it.
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

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Enable CC on file extensions
« Reply #5 on: January 03, 2012, 10:49:38 am »
Implemented in trunk.
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

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Enable CC on file extensions
« Reply #6 on: January 03, 2012, 11:45:38 pm »
PS: I'm not sure our CC's parser can correctly parse java source files.
You are right that it cannot really understand it, but for simple/quick matters in which it is not worth my time to open a different program, CC works well enough to be useful.

Implemented in trunk.
Thank you, I will be sure to try it.

A related question: is there any structure in place that I can use to create "on demand" code completion (similar to being able to select the lexer with Edit->Highlight mode)?

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Enable CC on file extensions
« Reply #7 on: January 04, 2012, 01:59:53 am »
I just realized I forgot to tag the category when I submitted the Java lexer patch.

Is there a way I can add it to the appropriate category?  (I am relatively new to BerliOS, so I am unsure if I am simply missing the button.)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Enable CC on file extensions
« Reply #8 on: January 04, 2012, 02:03:57 am »
I've set the category to Lexer, is this the correct one?
Probably only developers can change the 'advanced' settings of patches, bugs and features.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Enable CC on file extensions
« Reply #9 on: January 04, 2012, 02:08:11 am »
I've set the category to Lexer, is this the correct one?
Yes, that is the one; thank you.  (You have saved me from being bugged at seeing something out of place :).)

Probably only developers can change the 'advanced' settings of patches, bugs and features.
OK.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Enable CC on file extensions
« Reply #10 on: January 04, 2012, 07:18:39 am »
is there any structure in place that I can use to create "on demand" code completion (similar to being able to select the lexer with Edit->Highlight mode)?
No. And I think it wouldn't really make sense. However, If you change the CC options, usually the project(s) is(are re-scanned.
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

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Enable CC on file extensions
« Reply #11 on: January 08, 2012, 06:44:59 am »
But this I think is belong to "code completion" page, not the parser page.
True, I actually had in mind to save space... I'll change it.
One question:
How did you move items from one panel to another.

You just select one, then ctrl+X(cut), then ctrl+V(paste) to another panel?

As we can't not multiply select many items, so even cut/paste every items in "Keyword sets to additionally include" are quite annoying.  :)

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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Enable CC on file extensions
« Reply #12 on: January 08, 2012, 07:01:01 am »
As we can't not multiply select many items, so even cut/paste every items in "Keyword sets to additionally include" are quite annoying.  :)
No, sure not. You can copy/paste by container, so e.g. by wxStaticBoxSizer.
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