Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: plainzw on October 14, 2014, 09:36:29 am

Title: code completion settings do not take effect.
Post by: plainzw on October 14, 2014, 09:36:29 am
Code completion settings changing takes no effect on recently nightly builds.
Even when I disable code completion, it still works.
Title: Re: code completion settings do not take effect.
Post by: ollydbg on October 14, 2014, 10:04:10 am
Code completion settings changing takes no effect on recently nightly builds.
Even when I disable code completion, it still works.
Which one does not save correctly? Any settings?
I will look at it later.
Title: Re: code completion settings do not take effect.
Post by: ollydbg on October 14, 2014, 11:42:48 am
Bug confirmed in latest nightly builds, which is svn build  rev 9958 (2014-10-12 15:53:58)   gcc 4.8.1 Windows/unicode - 32 bit.
Title: Re: code completion settings do not take effect.
Post by: scarphin on October 14, 2014, 12:13:01 pm
I remember alpha mentioning that they were hardcoded on the clang code completion thread.
Title: Re: code completion settings do not take effect.
Post by: ollydbg on October 14, 2014, 03:28:07 pm
I remember alpha mentioning that they were hardcoded on the clang code completion thread.

But I believe this bug was cause by my commit rev9920.
Here, I have create two empty virtual function:

Code
    /** read Parser options from configure file */
    virtual void            ReadOptions() {}
    /** write Parse options to configure file */
    virtual void            WriteOptions() {}

But in NativeParser's constructor
Code
NativeParser::NativeParser() :
    m_TimerParsingOneByOne(this, idTimerParsingOneByOne),
    m_ClassBrowser(nullptr),
    m_ClassBrowserIsFloating(false),
    m_ImageList(nullptr),
    m_ParserPerWorkspace(false),
    m_EditorStartWord(-1),
    m_EditorEndWord(-1),
    m_LastAISearchWasGlobal(false),
    m_LastControl(nullptr),
    m_LastFunctionIndex(-1),
    m_LastFuncTokenIdx(-1),
    m_LastLine(-1),
    m_LastResult(-1)
{
    m_TempParser = new ParserBase;
    m_Parser     = m_TempParser;
The temp parser will call:
Code
ParserBase::ParserBase()
{
    m_TokenTree     = new TokenTree;
    m_TempTokenTree = new TokenTree;
    ReadOptions();
}

Thus, ReadOptions() does nothing.

But ReadOptions() does do some jobs in
Code
void Parser::ReadOptions()
{
    ConfigManager* cfg = Manager::Get()->GetConfigManager(_T("code_completion"));

    // one-time default settings change: upgrade everyone
    bool force_all_on = !cfg->ReadBool(_T("/parser_defaults_changed"), false);
    if (force_all_on)
    {
        cfg->Write(_T("/parser_defaults_changed"),       true);

        cfg->Write(_T("/parser_follow_local_includes"),  true);
        cfg->Write(_T("/parser_follow_global_includes"), true);
        cfg->Write(_T("/want_preprocessor"),             true);
        cfg->Write(_T("/parse_complex_macros"),          true);
    }

    // Page "Code Completion"
    m_Options.useSmartSense        = cfg->ReadBool(_T("/use_SmartSense"),                true);
    m_Options.whileTyping          = cfg->ReadBool(_T("/while_typing"),                  true);
    m_Options.caseSensitive        = cfg->ReadBool(_T("/case_sensitive"),                false);

    // Page "C / C++ parser"
    m_Options.followLocalIncludes  = cfg->ReadBool(_T("/parser_follow_local_includes"),  true);
    m_Options.followGlobalIncludes = cfg->ReadBool(_T("/parser_follow_global_includes"), true);
    m_Options.wantPreprocessor     = cfg->ReadBool(_T("/want_preprocessor"),             true);
    m_Options.parseComplexMacros   = cfg->ReadBool(_T("/parse_complex_macros"),          true);

    // Page "Symbol browser"
    m_BrowserOptions.showInheritance = cfg->ReadBool(_T("/browser_show_inheritance"),    false);
    m_BrowserOptions.expandNS        = cfg->ReadBool(_T("/browser_expand_ns"),           false);
    m_BrowserOptions.treeMembers     = cfg->ReadBool(_T("/browser_tree_members"),        true);

    // Token tree
    m_BrowserOptions.displayFilter   = (BrowserDisplayFilter)cfg->ReadInt(_T("/browser_display_filter"), bdfFile);
    m_BrowserOptions.sortType        = (BrowserSortType)cfg->ReadInt(_T("/browser_sort_type"),           bstKind);

    // Page "Documentation:
    m_Options.storeDocumentation     = cfg->ReadBool(_T("/use_documentation_helper"),         false);

    // force re-read of file types
    ParserCommon::EFileType ft_dummy = ParserCommon::FileType(wxEmptyString, true);
    wxUnusedVar(ft_dummy);
}

I'm thinking a solution.

Title: Re: code completion settings do not take effect.
Post by: ollydbg on October 14, 2014, 04:50:20 pm
Fixed in the trunk, rev 9991.  :)
Thanks for the report!

Look, we now have revision number near 10000
Title: Re: code completion settings do not take effect.
Post by: plainzw on October 15, 2014, 03:05:36 am
Fixed in the trunk, rev 9991.  :)
Thanks for the report!

Look, we now have revision number near 10000

Hi,ollydbg,thank you for your reply.Is there a special edition when revision reaches 10000? :)
I've tested the new revision,but it looks like that the bug is not fixed yet.
Now code completion's setting can be saved correctly, but the setting does not take effect at all.
e.g, I disable the code completion first,then restart IDE.When opening a project and trying to type
something, code completion window poped up unexpected.
I'm sorry I can't upload two attachments once so I merge them into one.
Title: Re: code completion settings do not take effect.
Post by: ollydbg on October 15, 2014, 06:04:21 am
Hi,ollydbg,thank you for your reply.Is there a special edition when revision reaches 10000? :)
I don't know, you may ask our release managers.  ;D

Quote
I've tested the new revision,but it looks like that the bug is not fixed yet.
Now code completion's setting can be saved correctly, but the setting does not take effect at all.
e.g, I disable the code completion first,then restart IDE.When opening a project and trying to type
something, code completion window poped up unexpected.
I'm sorry I can't upload two attachments once so I merge them into one.
This is another but, currently all the codecompletion's settings were related to CodeCompletion plugin, not the SDK.
We have a general code completion interface in SDK(this was done by our dev Alpha), so I see that the SDK should have some options for this.

I just debugged a little.
Code
At F:\cb_sf_git\trunk\src\plugins\codecompletion\codecompletion.cpp:927

[debug]> bt 30
[debug]#0  CodeCompletion::GetAutocompList (this=0x6ceb368, isAuto=true, ed=0x14f76e80, tknStart=@0x22f8cc: 46, tknEnd=@0x22f8d0: 46) at F:\cb_sf_git\trunk\src\plugins\codecompletion\codecompletion.cpp:927
[debug]#1  0x0109f09b in CCManager::OnCompleteCode (this=0x14f291a8, event=...) at F:\cb_sf_git\trunk\src\sdk\ccmanager.cpp:427
[debug]#2  0x0129e4ab in cbEventFunctor<CCManager, CodeBlocksEvent>::Call (this=0x14f2ecc8, event=...) at F:\cb_sf_git\trunk\src\include\cbfunctor.h:49
[debug]#3  0x01108c2a in Manager::ProcessEvent (this=0x52fbda0, event=...) at F:\cb_sf_git\trunk\src\sdk\manager.cpp:263
[debug]#4  0x010a1ec6 in CCManager::OnTimer (this=0x14f291a8, event=...) at F:\cb_sf_git\trunk\src\sdk\ccmanager.cpp:957
[debug]#5  0x627015f1 in wxAppConsole::HandleEvent(wxEvtHandler*, void (wxEvtHandler::*)(wxEvent&), wxEvent&) const () from E:\code\wx-mingw-build-481-dw2\wxWidgets-2.8.12\lib\gcc_dll\wxmsw28u_gcc_custom.dll
[debug]#6  0x6276a07e in wxEvtHandler::ProcessEventIfMatches(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) () from E:\code\wx-mingw-build-481-dw2\wxWidgets-2.8.12\lib\gcc_dll\wxmsw28u_gcc_custom.dll
[debug]#7  0x6276a457 in wxEvtHandler::SearchDynamicEventTable(wxEvent&) () from E:\code\wx-mingw-build-481-dw2\wxWidgets-2.8.12\lib\gcc_dll\wxmsw28u_gcc_custom.dll
[debug]#8  0x6276a514 in wxEvtHandler::ProcessEvent(wxEvent&) () from E:\code\wx-mingw-build-481-dw2\wxWidgets-2.8.12\lib\gcc_dll\wxmsw28u_gcc_custom.dll
[debug]#9  0x62837a80 in wxTimerBase::Notify() () from E:\code\wx-mingw-build-481-dw2\wxWidgets-2.8.12\lib\gcc_dll\wxmsw28u_gcc_custom.dll
[debug]#10 0x62799836 in wxTimerWndProc(HWND__*, unsigned int, unsigned int, long)@16 () from E:\code\wx-mingw-build-481-dw2\wxWidgets-2.8.12\lib\gcc_dll\wxmsw28u_gcc_custom.dll
[debug]#11 0x7e418734 in USER32!GetDC () from C:\WINDOWS\system32\user32.dll
[debug]#12 0x00030a6c in ?? ()
[debug]#13 0x00000113 in ?? ()
[debug]#14 0x00000009 in ?? ()
[debug]#15 0x00000000 in ?? ()
[debug]>>>>>>cb_gdb:
And the code:
Code
std::vector<CodeCompletion::CCToken> CodeCompletion::GetAutocompList(bool isAuto, cbEditor* ed, int& tknStart, int& tknEnd)
{
    std::vector<CCToken> tokens;

    if (!IsAttached() || !m_InitDone)
        return tokens;

    cbStyledTextCtrl* stc = ed->GetControl();
    const int style = stc->GetStyleAt(tknEnd);
    const wxChar curChar = stc->GetCharAt(tknEnd - 1);

    if (isAuto) // filter illogical cases of auto-launch
    {
        if (   (   curChar == wxT(':') // scope operator
                && stc->GetCharAt(tknEnd - 2) != wxT(':') )
            || (   curChar == wxT('>') // '->'
                && stc->GetCharAt(tknEnd - 2) != wxT('-') )
            || (   wxString(wxT("<\"/")).Find(curChar) != wxNOT_FOUND // #include directive
                && !stc->IsPreprocessor(style) ) )
        {
            return tokens;
        }
    }

    const int lineIndentPos = stc->GetLineIndentPosition(stc->GetCurrentLine());
    const wxChar lineFirstChar = stc->GetCharAt(lineIndentPos);

    if (lineFirstChar == wxT('#'))
    {
        const int startPos = stc->WordStartPosition(lineIndentPos + 1, true);
        const int endPos = stc->WordEndPosition(lineIndentPos + 1, true);
        const wxString str = stc->GetTextRange(startPos, endPos);

        if (str == wxT("include") && tknEnd > endPos)
        {
            DoCodeCompleteIncludes(ed, tknStart, tknEnd, tokens);
        }
        else if (endPos >= tknEnd && tknEnd > lineIndentPos)
            DoCodeCompletePreprocessor(tknStart, tknEnd, ed, tokens);
        else if ( (   str == wxT("define")
                   || str == wxT("if")
                   || str == wxT("ifdef")
                   || str == wxT("ifndef")
                   || str == wxT("elif")
                   || str == wxT("elifdef")
                   || str == wxT("elifndef")
                   || str == wxT("undef") )
                 && tknEnd > endPos )
        {
            DoCodeComplete(tknEnd, ed, tokens, true);
        }
        return tokens;
    }
    else if (curChar == wxT('#'))
        return tokens;
    else if (lineFirstChar == wxT(':') && curChar == _T(':'))
        return tokens;

    if (   stc->IsString(style)
        || stc->IsComment(style)
        || stc->IsCharacter(style)
        || stc->IsPreprocessor(style) )
    {
        return tokens;
    }

    DoCodeComplete(tknEnd, ed, tokens);
    return tokens;
}

Here, we can add a if condition to solve(workaround) this issue.
Code
std::vector<CodeCompletion::CCToken> CodeCompletion::GetAutocompList(bool isAuto, cbEditor* ed, int& tknStart, int& tknEnd)
{
    std::vector<CCToken> tokens;

    if (!IsAttached() || !m_InitDone || Code suggestion is not allowed)
        return tokens;
But I think the condition should be put in SDK, not the single codecompletion plugin.

EDIT:
We can use this variable
Code
    // for CC
    m_UseCodeCompletion      = cfg->ReadBool(_T("/use_code_completion"),   true);
Similar like the usage below:
Code
void CodeCompletion::EditorEventHook(cbEditor* editor, wxScintillaEvent& event)
{
    if (!IsAttached() || !m_InitDone || !m_UseCodeCompletion)
    {
        event.Skip();
        return;
    }

    if ( !IsProviderFor(editor) )
    {
        event.Skip();
        return;
    }

    cbStyledTextCtrl* control = editor->GetControl();

    if      (event.GetEventType() == wxEVT_SCI_CHARADDED)
    {   TRACE(_T("wxEVT_SCI_CHARADDED")); }
    else if (event.GetEventType() == wxEVT_SCI_CHANGE)
    {   TRACE(_T("wxEVT_SCI_CHANGE")); }
    else if (event.GetEventType() == wxEVT_SCI_KEY)
    {   TRACE(_T("wxEVT_SCI_KEY")); }
    else if (event.GetEventType() == wxEVT_SCI_MODIFIED)
    {   TRACE(_T("wxEVT_SCI_MODIFIED")); }
    else if (event.GetEventType() == wxEVT_SCI_AUTOCOMP_SELECTION)
    {   TRACE(_T("wxEVT_SCI_AUTOCOMP_SELECTION")); }
    else if (event.GetEventType() == wxEVT_SCI_AUTOCOMP_CANCELLED)
    {   TRACE(_T("wxEVT_SCI_AUTOCOMP_CANCELLED")); }

    if (   m_NativeParser.GetParser().Options().whileTyping
        && (   (event.GetModificationType() & wxSCI_MOD_INSERTTEXT)
            || (event.GetModificationType() & wxSCI_MOD_DELETETEXT) ) )
    {
        m_NeedReparse = true;
    }

    if (control->GetCurrentLine() != m_CurrentLine)
    {
        if (m_NeedReparse)
        {
            TRACE(_T("CodeCompletion::EditorEventHook: Starting m_TimerRealtimeParsing."));
            m_TimerRealtimeParsing.Start(REALTIME_PARSING_DELAY, wxTIMER_ONE_SHOT);
            m_CurrentLength = control->GetLength();
            m_NeedReparse = false;
        }

        if (event.GetEventType() == wxEVT_SCI_UPDATEUI)
        {
            m_ToolbarNeedRefresh = true;
            TRACE(_T("CodeCompletion::EditorEventHook: Starting m_TimerToolbar."));
            if (m_TimerEditorActivated.IsRunning())
                m_TimerToolbar.Start(EDITOR_ACTIVATED_DELAY + 1, wxTIMER_ONE_SHOT);
            else
                m_TimerToolbar.Start(TOOLBAR_REFRESH_DELAY, wxTIMER_ONE_SHOT);
        }
    }

    // allow others to handle this event
    event.Skip();
}


Title: Re: code completion settings do not take effect.
Post by: Alpha on October 15, 2014, 07:30:32 am
If it is this CC plugin specifically that we do not want acting (but allow another xyzCC plugin to still run), then CC should return ccpsInactive from CodeCompletion::GetProviderStatusFor() (possibly needing to call CCManager::NotifyPluginStatus() if this is changed during runtime to force a recheck of options).
If all code completion should be globally disabled, then that is a config option that should be implemented within CCManager (probably at the top of CCManager::OnCompleteCode()).  I guess I never did build a dialogue for CCManager though... :-\
Title: Re: code completion settings do not take effect.
Post by: plainzw on October 15, 2014, 09:31:32 am
If it is this CC plugin specifically that we do not want acting (but allow another xyzCC plugin to still run), then CC should return ccpsInactive from CodeCompletion::GetProviderStatusFor() (possibly needing to call CCManager::NotifyPluginStatus() if this is changed during runtime to force a recheck of options).
If all code completion should be globally disabled, then that is a config option that should be implemented within CCManager (probably at the top of CCManager::OnCompleteCode()).  I guess I never did build a dialogue for CCManager though... :-\

Hi, Alpha, I add the code at the beginning of CodeCompletion::GetProviderStatusFor(cbEditor* ed), and code completion is diabled correctly.
Code
if (!m_UseCodeCompletion)
        return ccpsInactive;

Some member variables about code completion options,  like m_CCAutoLaunch, m_CCAutoLaunchChars, m_CCLaunchDelay, m_CCFillupChars, are declared but never used. I remember these options worked fine in previous revision. I compare working copy with previous copy, and find that they were removed from CodeCompletion::EditorEventHook in rev 9690 as dead code,  so changing these settings of code completion takes no effect.
Title: Re: code completion settings do not take effect.
Post by: ollydbg on October 15, 2014, 04:33:15 pm
Hi, Alpha, I add the code at the beginning of CodeCompletion::GetProviderStatusFor(cbEditor* ed), and code completion is diabled correctly.
Good to see.



Quote
Some member variables about code completion options,  like m_CCAutoLaunch, m_CCAutoLaunchChars, m_CCLaunchDelay, m_CCFillupChars, are declared but never used. I remember these options worked fine in previous revision. I compare working copy with previous copy, and find that they were removed from CodeCompletion::EditorEventHook in rev 9690 as dead code,  so changing these settings of code completion takes no effect.
rev 9690 are the code refactoring about CCManager. Yeah, as Alpha said, those options should be put in some SDK's setting dialog.
Title: Re: code completion settings do not take effect.
Post by: plainzw on October 15, 2014, 04:56:00 pm
Yes, I see that some code from CodeCompletion::EditorEventHook is moved to CCManager::OnEditorHook, except reading setting has not been implemented such as auto lauch chars is hard coded.
Then will these settings be removed from code completion setting and create a new SDK setting dialog?
Title: Re: code completion settings do not take effect.
Post by: ollydbg on October 16, 2014, 08:31:02 am
Then will these settings be removed from code completion setting and create a new SDK setting dialog?
True. We should have a SDK setting dialog for those "common code completion settings". (As we can have many code completion plugins, like native-cc-plugin, clang-cc-plugin, python-cc-plugin, FORTRAN-cc-plugin.)
Title: Re: code completion settings do not take effect.
Post by: MortenMacFly on October 16, 2014, 08:35:46 am
True. We should have a SDK setting dialog for those "common code completion settings".
...or just file an "CodeCompletion is saving settings" event (where CC plugins can connect to) from CC manager.
Title: Re: code completion settings do not take effect.
Post by: ollydbg on October 16, 2014, 09:52:37 am
True. We should have a SDK setting dialog for those "common code completion settings".
...or just file an "CodeCompletion is saving settings" event (where CC plugins can connect to) from CC manager.
What does this event used for? Who and to whom?
CCManager to our C++ code completion plugin?

Maybe, an workaround could be that both CCManager and c++ codecompletion plugin share the settings. (configure file)
And CCManager follow the settings in the configure file. Thus, we don't need a SDK setting dialog.
Title: Re: code completion settings do not take effect.
Post by: MortenMacFly on October 17, 2014, 07:52:05 am
What does this event used for? Who and to whom?
CCManager to our C++ code completion plugin?
Yes, CCManager triggers all CC plugins to save their settings after this you can assume settings are up-to-date when continuing your work in CC(Manager). (I was under the assumption that CCManager needs that...)