User forums > Using Code::Blocks

Code Completion with One Key Press

<< < (3/4) > >>

oBFusCATed:
I doubt, the only thing you can do is start debugging the CC plugin.
You can probably try the CC based on clang mentioned by yvesdm3000.

ollydbg:

--- Quote from: BlueHazzard on January 11, 2017, 11:13:21 pm ---settings->Editor->General settings->Code completion->Autolaunch after typing # letters

i don't know why the settings for code completion are split up ???

--- End quote ---
This is because the setting here will be shared by all kinds of code completion plugins, I mean we have a lot of cc plugins, such as the build in cc, the clang cc, the python cc.


--- Quote from: AlterEgo on January 15, 2017, 03:41:02 pm ---Any ideas oBFusCATed, is there a way to get the behaviour I'm looking for from the built in Code Completion?

--- End quote ---
Hi, I think it can be adjusted, but I don't know how to do that, in the source code:

--- Code: ---void CodeCompletion::DoCodeComplete(int caretPos, cbEditor* ed, std::vector<CCToken>& tokens, bool preprocessorOnly)
--- End code ---

There are some snippet:

--- Code: ---if (colour_set)
                {
                    wxString lastSearch = m_NativeParser.LastAIGlobalSearch().Lower();
                    int iidx = ilist->GetImageCount();
                    FileType fTp = FileTypeOf(ed->GetShortName());
                    bool isC = (fTp == ftHeader || fTp == ftSource|| fTp == ftTemplateSource);
                    // theme keywords
                    HighlightLanguage lang = ed->GetLanguage();
                    if (lang == HL_NONE)
                        lang = colour_set->GetLanguageForFilename(ed->GetFilename());
                    wxString strLang = colour_set->GetLanguageName(lang);
                    // if its sourcecode/header file and a known fileformat, show the corresponding icon
                    if (isC && strLang == wxT("C/C++"))
                        stc->RegisterImage(iidx, wxBitmap(cpp_keyword_xpm));
                    else if (isC && strLang == wxT("D"))
                        stc->RegisterImage(iidx, wxBitmap(d_keyword_xpm));
                    else
                        stc->RegisterImage(iidx, wxBitmap(unknown_keyword_xpm));
                    // the first two keyword sets are the primary and secondary keywords (for most lexers at least)
                    // but this is now configurable in global settings
                    for (int i = 0; i <= wxSCI_KEYWORDSET_MAX; ++i)
                    {
                        if (!m_LexerKeywordsToInclude[i])
                            continue;

                        wxString keywords = colour_set->GetKeywords(lang, i);
                        wxStringTokenizer tkz(keywords, wxT(" \t\r\n"), wxTOKEN_STRTOK);
                        while (tkz.HasMoreTokens())
                        {
                            wxString kw = tkz.GetNextToken();
                            if (   kw.Lower().StartsWith(lastSearch)
                                && uniqueStrings.find(kw) == uniqueStrings.end() )
                            {
                                tokens.push_back(CCToken(wxNOT_FOUND, kw, iidx));
                            }
                        }
                    }
                }

--- End code ---
You see, all the keywords were added directly to the "tokens", but I think they don't have much precedence, as I can see the cunstructor of CCToken.

--- Code: ---       /** Structure representing a generic token, passed between CC plugins and CCManager. */
        struct CCToken
        {
            /** @brief Convenience constructor.
              *
              * Represents a generic token, passed between CC plugins and CCManager.
              *
              * @param _id Internal identifier for a CC plugin to reference the token in its data structure.
              * @param dispNm The string CCManager will use to display this token.
              * @param categ The category corresponding to the index of the registered image (during autocomplete).
              *              Negative values are reserved for CCManager.
              */
            CCToken(int _id, const wxString& dispNm, int categ = -1) :
                id(_id), category(categ), weight(5), displayName(dispNm), name(dispNm) {}

            /** @brief Construct a fully specified CCToken.
              *
              * Represents a generic token, passed between CC plugins and CCManager.
              *
              * @param _id Internal identifier for a CC plugin to reference the token in its data structure.
              * @param dispNm The verbose string CCManager will use to display this token.
              * @param nm Minimal name of the token that CCManager may choose to display in restricted circumstances.
              * @param _weight Lower numbers are placed earlier in listing, 5 is default; try to keep 0-10.
              * @param categ The category corresponding to the index of the registered image (during autocomplete).
              *              Negative values are reserved for CCManager.
              */
            CCToken(int _id, const wxString& dispNm, const wxString& nm, int _weight, int categ = -1) :
                id(_id), category(categ), weight(_weight), displayName(dispNm), name(nm) {}

            int id;               //!< CCManager will pass this back unmodified. Use it as an internal identifier for the token.
            int category;         //!< The category corresponding to the index of the registered image (during autocomplete).
            int weight;           //!< Lower numbers are placed earlier in listing, 5 is default; try to keep 0-10.
            wxString displayName; //!< Verbose string representing the token.
            wxString name;        //!< Minimal name of the token that CCManager may choose to display in restricted circumstances.
        };

--- End code ---
So, we have to adjust the "weight" parameter. We need an algorithm to dynamically adjust the "weight" for each added keywords.  ;)

AlterEgo:
How do you use Clang Code Completion? I've never used any extra Code::Blocks plugins before.

yvesdm3000:

--- Code: ---[quote author=ollydbg link=topic=21656.msg147393#msg147393 date=1484542600]
[quote author=BlueHazzard link=topic=21656.msg147344#msg147344 date=1484172801]
settings->Editor->General settings->Code completion->Autolaunch after typing # letters

i don't know why the settings for code completion are split up ???
[/quote]
This is because the setting here will be shared by all kinds of code completion plugins, I mean we have a lot of cc plugins, such as the build in cc, the clang cc, the python cc.


--- End code ---

It's a bit simpler than that, it's a CodeBlocks setting that will instruct when the CC plugin will be called for code-completion.
It might be better if this setting would be language-specific, but it's not very important or high priority item...

Yves

AlterEgo:
Would someone explain to me how to set up Code::Blocks to use Clang Code Completion or link me to a good tutorial that explains how to do so please?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version