Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [qtcreator] force completion of a name from code, also any word, also in comments and inside c-string

[qtcreator] force completion of a name from code, also any word, also in comments and inside c-string

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 429 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    egorski
    wrote on last edited by egorski
    #1

    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

    1. as if I would just be finishing any word (same as editor vim offers)
    2. 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.

    J.HilkJ 1 Reply Last reply
    0
    • E egorski

      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

      1. as if I would just be finishing any word (same as editor vim offers)
      2. 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.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #2

      @egorski

      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


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      E 1 Reply Last reply
      1
      • J.HilkJ J.Hilk

        @egorski

        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

        E Offline
        E Offline
        egorski
        wrote on last edited by
        #3

        @J-Hilk said in [qtcreator] force completion of a name from code:

        @egorski
        https://doc.qt.io/qtcreator/creator-keyboard-shortcuts.html#editing-keyboard-shortcuts

        Trigger 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?

        J.HilkJ 1 Reply Last reply
        0
        • E egorski

          @J-Hilk said in [qtcreator] force completion of a name from code:

          @egorski
          https://doc.qt.io/qtcreator/creator-keyboard-shortcuts.html#editing-keyboard-shortcuts

          Trigger 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?

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @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 🤔


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          E 1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @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 🤔

            E Offline
            E Offline
            egorski
            wrote on last edited by
            #5

            @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.

            J.HilkJ 1 Reply Last reply
            0
            • E egorski

              @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.

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @egorski well, there is Q_FUNC_INFO which is what I use in such a case at least for string construction


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              E 1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @egorski well, there is Q_FUNC_INFO which is what I use in such a case at least for string construction

                E Offline
                E Offline
                egorski
                wrote on last edited by egorski
                #7

                @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?

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved