[qtcreator] force completion of a name from code, also any word, also in comments and inside c-string
-
While editing a comment, a C++ string, or other such place, how to force a C++ name completion?
That is, I want to ignore "smart" context and just force a dumb completion
- as if I would just be finishing any word (same as editor vim offers)
- using proper smart C++ syntax completion but assuming I am in "normal" context - inside some global function
Motivating example:
class Foobar {
public:
static int counter();
int state() const;
};
class ImageLoader : public Foobar { static int benchmark(); .......... }// this function demonstrates use of Imag___::ben___
void demo() {
Foobar x;
if (Foobar.state()<5) throw std::runtime_exception("Invalid state of my Foo___");
}In this place, where I press some hotkey, I want "Imag___" to auto-complete to ImageLoader,
then pressing again it after ImageLoader::ben___ I want to obtain ImageLoader::benchmark();
That is inside the comments.Inside the C-string, I wish to complete Foo___ into Foobar.
-
https://doc.qt.io/qtcreator/creator-keyboard-shortcuts.html#editing-keyboard-shortcuts
Trigger a completion in this scope Ctrl+Space
but I think it may be broken in newer version of QtC and only the auto complete one gets is the one from timeouts
-
@J-Hilk said in [qtcreator] force completion of a name from code:
@egorski
https://doc.qt.io/qtcreator/creator-keyboard-shortcuts.html#editing-keyboard-shortcutsTrigger a completion in this scope Ctrl+Space
I am on "Qt Creator 4.8.2 Based on Qt 5.11.3 (GCC 8.3.0, 64 bit)".
Ctrl+space inside comment (or string) does nothing, it works only when in normal proper context. In editing keyboard shortcuts I do not have "Trigger a completion in this scope", Ctrl+Space is instead assigned to "TextEditor > CompleteThis".
Does it mean that it works as described (in strings, in comments) but in newer versions of Qtcreator?
-
@egorski I'm referring to this:
https://bugreports.qt.io/browse/QTCREATORBUG-26959
I don't think it ever worked inside string quotes or comments 🤔
-
@J-Hilk said in [qtcreator] force completion of a name from code:
I don't think it ever worked inside string quotes or comments 🤔
Oh, right.
So then, wouldn't it be a good idea to have it working there? Entering names of classes, functions by hand (when you need to mention them) in comments (and error strings) is kinda redundant work.
Pressing Ctrl-N and Ctrl-P (while using FakeVim) does something else, dunno if there is even a way to access the Vim's completion in editor now.
-
@egorski well, there is Q_FUNC_INFO which is what I use in such a case at least for string construction
-
@egorski well, there is Q_FUNC_INFO which is what I use in such a case at least for string construction
@J-Hilk right, but that macro Q_FUNC_INFO just only will show the name of function I am in now. While I want to sometimes mention names of other functions, classes, types, enums, etc etc from elsewhere in code. Also - need to use them in the comments.
How one can go about getting such function to exist in Qt Creator? Like, create some ticket with a future request? I do not think I can implement it myself for Qt Creator, but I guess it wouldn't be very hard... a hack might be to "in memory" create a modification of code that has some void function_scope() { .... } function, and inside it put what you typed and then use auto-complete. Or perhaps the auto complete plugin/code simply has flags to do it.
Other approach might be to just reimplement simple word completion like vim does it.
A word completion would just collect a set of all existing words in current document and autocomplete on that.Ideally there might be separate completion commands:
-
complete the C++ code (as if we would be now in normal global function context) no matter where we are actually
-
complete any word, from code, of current file
-
complete any word, from code, of current file + includes
(should be very easy to implement in editor) -
complete any word, from entire file (also comments etc) of current file
-
complete any word, from entire file (also comments etc) of current file + include
That would rock.
Would it be easy to create editor plugin, that has access to string with all content of file, plus also get get access to all file with syntax (is this a c++ code, or string, or comment, or pre-processor)?
Heaving that available it should be quite easy to write a function that returns list of strings that complete given string. Can you point me to some example or tutorial for creating such plugin? -