Author Topic: Auto brackets for built in function is not working in cpp  (Read 8425 times)

Offline ahs_58

  • Single posting newcomer
  • *
  • Posts: 2
Auto brackets for built in function is not working in cpp
« on: May 31, 2020, 07:35:13 pm »
Auto brackets after built in function in c++ was working fine when I  was using older version of codeblocks. But after installing latest version (20.03) of codeblock I need to press brackets manually.Let me clarify the matter with an example:

say I want to use sort() function for sorting a array:

In older version I just wrote sort and press ENTER key then I got like this

write sort  [Press ENTER key]  sort()

but in new version I need to press opening bracket key after writing sort
example:

write sort   [Press opening first braket key]  [Press ENTER key]   sort()


How to solve this problem? How to get old version feature that I have described above in my new codeblocks?

Thanks In Advance  :)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Auto brackets for built in function is not working in cpp
« Reply #1 on: May 31, 2020, 07:42:08 pm »
There is a setting for this. Are you sure it is still enabled?
(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 ahs_58

  • Single posting newcomer
  • *
  • Posts: 2
Re: Auto brackets for built in function is not working in cpp
« Reply #2 on: May 31, 2020, 07:45:44 pm »
Can you tell me exactly what that setting is?I don't know about this.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Auto brackets for built in function is not working in cpp
« Reply #3 on: May 31, 2020, 08:21:11 pm »
Something related to braces and completion :)
There are two settings related to this and I'm not sure which one is the one you need.
Inspect the Settings -> Editor.

p.s. I don't use this so I cannot help you more. But we have not removed it.
(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 huycan

  • Multiple posting newcomer
  • *
  • Posts: 34
Re: Auto brackets for built in function is not working in cpp
« Reply #4 on: June 10, 2020, 12:51:18 am »
Let me reiterate what the OP means to say.

The problem is with the Code completion. There is an option "Add parentheses after function name auto completion" when checked, parentheses are automatically added to the function name. It worked in the past version of CB. But starting with 20.03 and all the nightly builds, it stops working.

For example, if I start typing "std:abs" ... the Code completion will give me a list of choices and after I choose (let say the first one), it will display in the editor "std::abs" (for the 20.03 ver)... but in the past, CB 17 and older... the display will be "std::abs()" ... Notice the parentheses...

Edit: This bug only happens under Windows... Linux working fine...
« Last Edit: June 10, 2020, 01:15:10 am by huycan »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Auto brackets for built in function is not working in cpp
« Reply #5 on: June 10, 2020, 10:51:20 am »
Can you find the night build which broke this?
(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 huycan

  • Multiple posting newcomer
  • *
  • Posts: 34
Re: Auto brackets for built in function is not working in cpp
« Reply #6 on: June 10, 2020, 01:44:18 pm »
The April 20, 2019 svn11628 still working...
The Nov 18, 2020 svn11954 already broken...

In between, I don't know.. I cannot tested... because the required file "wxmsw31u_gcc_cb_wx311_2D_gcc810-mingw64.7z" is missing in download....

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Auto brackets for built in function is not working in cpp
« Reply #7 on: June 10, 2020, 06:43:13 pm »
@killerbot: Do you know something about this? Can you re-upload the file?
(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 Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Auto brackets for built in function is not working in cpp
« Reply #8 on: June 10, 2020, 07:37:30 pm »
The Nov 18, 2020 svn11954 already broken...

Do you mean Nov 18, 2019?
« Last Edit: June 10, 2020, 07:39:05 pm by Miguel Gimenez »

Offline huycan

  • Multiple posting newcomer
  • *
  • Posts: 34
Re: Auto brackets for built in function is not working in cpp
« Reply #9 on: June 10, 2020, 08:49:35 pm »
The Nov 18, 2020 svn11954 already broken...

Do you mean Nov 18, 2019?

Oops...I misread 0118... I mean the January 18, 2020.... is broken... svn11954....

Offline huycan

  • Multiple posting newcomer
  • *
  • Posts: 34
Re: Auto brackets for built in function is not working in cpp
« Reply #10 on: July 14, 2020, 10:56:47 pm »
Any updating on this bug.... (happens in Windows only)...

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Auto brackets for built in function is not working in cpp
« Reply #11 on: September 11, 2020, 02:04:00 pm »
I debugged this issue for a while, in the latest svn code.

In the function, in my condition m_CCAutoAddParentheses is true.

Code
void CodeCompletion::DoAutocomplete(const CCToken& token, cbEditor* ed)
{
    wxString itemText = CodeCompletionHelper::AutocompGetName(token.displayName);
    cbStyledTextCtrl* stc = ed->GetControl();
...
...
    if (token.id != -1 && m_CCAutoAddParentheses)
    {
        CC_LOCKER_TRACK_TT_MTX_LOCK(s_TokenTreeMutex)

        TokenTree* tree = m_NativeParser.GetParser().GetTokenTree();
        const Token* tkn = tree->at(token.id);
...


I see that the token.id is always -1, this is the call stack:

Code
#0  CodeCompletion::DoAutocomplete (this=0x5c38db8, token=..., ed=0xd09d5a8) at D:\code\cb\cb_sf_git\cccrash2019\src\plugins\codecompletion\codecompletion.cpp:1335
#1  0x694a5ac9 in cbCodeCompletionPlugin::DoAutocomplete (this=0x5c38db8, token=L"gggggccccc(): int", ed=0xd09d5a8) at D:\code\cb\cb_sf_git\cccrash2019\src\sdk\cbplugin.cpp:1028
#2  0x694bbedd in CCManager::OnEditorHook (this=0xd069478, ed=0xd09d5a8, event=...) at D:\code\cb\cb_sf_git\cccrash2019\src\sdk\ccmanager.cpp:885
#3  0x69797921 in EditorHooks::HookFunctor<CCManager>::Call (this=0xcd3ebd0, editor=0xd09d5a8, event=...) at D:\code\cb\cb_sf_git\cccrash2019\src\include\editor_hooks.h:61
#4  0x694f3b73 in EditorHooks::CallHooks (editor=0xd09d5a8, event=...) at D:\code\cb\cb_sf_git\cccrash2019\src\sdk\editor_hooks.cpp:122
...


I see that in the

Code
void cbCodeCompletionPlugin::DoAutocomplete(const wxString& token, cbEditor* ed)
{
    DoAutocomplete(CCToken(-1, token), ed);
}

You see, the first argument of the CCToken constructor is -1, and this is actually the token.id.

I'm not sure why.
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 Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Auto brackets for built in function is not working in cpp
« Reply #12 on: September 11, 2020, 02:56:53 pm »
There is a ticket about this issue, see https://sourceforge.net/p/codeblocks/tickets/1001/

There is also a related thread discussing scope of the bug, see http://forums.codeblocks.org/index.php/topic,24119.0.html . Looks like it stopped working when poup code for MSW was changed just before wx3.1.2 release.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Auto brackets for built in function is not working in cpp
« Reply #13 on: September 12, 2020, 04:31:40 pm »
There is a ticket about this issue, see https://sourceforge.net/p/codeblocks/tickets/1001/

There is also a related thread discussing scope of the bug, see http://forums.codeblocks.org/index.php/topic,24119.0.html . Looks like it stopped working when poup code for MSW was changed just before wx3.1.2 release.
Thanks. There are some discussion in those links.

It looks like some issue happens in the wx related code, especially the mechanism to trigger the code completion event inside C::B's SDK.
« Last Edit: September 12, 2020, 04:33:31 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.