Author Topic: RFC: ccmanager ignores requests for completion.  (Read 6179 times)

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2808
RFC: ccmanager ignores requests for completion.
« on: June 30, 2022, 07:44:10 pm »
Patch 1279 https://sourceforge.net/p/codeblocks/tickets/1279

This is a request for comments.

ccmanager ignores completion requests when its length is the same as the previously  mispelled request.
Example:
Create a virgin wx project. type "OnC", in the last method (OnAbout).
Completion will suggest OnClose. Hit escape.
Backup and change C to Q for OnQuit. No suggestions occur.
All three letter requests will be ignored until a 4th letter is typed.

This patch adds an additional test of the pattern text to determine if the last request is actually different from the current.

It works for both plugins codecompletion and clangd_client.

Code
Index: src/include/ccmanager.h
===================================================================
--- src/include/ccmanager.h (revision 12842)
+++ src/include/ccmanager.h (working copy)
@@ -223,6 +223,7 @@
             int caretStart;
             int tokenStart;
             int editorZoom;
+            wxString trigger;
         };
 
         LastACLaunchState m_LastACLaunchState;
Index: src/sdk/ccmanager.cpp
===================================================================
--- src/sdk/ccmanager.cpp (revision 12842)
+++ src/sdk/ccmanager.cpp (working copy)
@@ -516,14 +516,19 @@
 
     cbStyledTextCtrl* stc = ed->GetControl();
     int tknEnd = stc->GetCurrentPos();
+    int tknStart = stc->WordStartPosition(tknEnd, true);
+    wxString trigger = stc->GetTextRange(tknStart, tknEnd);
     if (tknEnd == m_LastACLaunchState.caretStart && stc->GetZoom() == m_LastACLaunchState.editorZoom && !m_AutocompTokens.empty())
     {
         DoBufferedCC(stc);
-        return;
+        // If the completion trigger is the same as last, the old cached completions have already been shown
+        // else they've just been cached, but not yet shown.
+        if (m_LastACLaunchState.trigger.Length() and (m_LastACLaunchState.trigger == trigger)) //(ph 2022/06/28)
+            return;
     }
+    // Record the new completion trigger
+    m_LastACLaunchState.trigger = stc->GetTextRange(tknStart,tknEnd); //(ph 2022/06/28)
 
-    int tknStart = stc->WordStartPosition(tknEnd, true);
-
     m_AutocompTokens = ccPlugin->GetAutocompList(event.GetInt() == FROM_TIMER, ed, tknStart, tknEnd);
     if (m_AutocompTokens.empty())
         return;

« Last Edit: June 30, 2022, 07:46:46 pm by Pecan »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3352
Re: RFC: ccmanager ignores requests for completion.
« Reply #1 on: July 01, 2022, 08:38:10 am »
Looks good to me...

[edit:] this side note is only tangentially to your patch and should not block it!
On a side note: This change and using semantic versioning (see: https://forums.codeblocks.org/index.php/topic,25003.msg170338.html) would mean we have to increse the PLUGIN_SDK_VERSION_RELEASE version, because this change introduces a incompatible binary change (signature of function changes). So i wonder if this could lead to quite high PLUGIN_SDK_VERSION_RELEASE  numbers in the future...
« Last Edit: July 01, 2022, 08:42:08 am by BlueHazzard »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: RFC: ccmanager ignores requests for completion.
« Reply #2 on: July 02, 2022, 01:51:27 am »
Hi, Pecan, thanks for the patch. It also looks good to me. :)
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 Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2808
Re: RFC: ccmanager ignores requests for completion.
« Reply #3 on: July 02, 2022, 06:32:16 am »
... because this change introduces a incompatible binary change (signature of function changes). So i wonder if this could lead to quite high PLUGIN_SDK_VERSION_RELEASE  numbers in the future...

For my education, where does this patch change the call or function signature?

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3352
Re: RFC: ccmanager ignores requests for completion.
« Reply #4 on: July 03, 2022, 01:58:47 am »
... because this change introduces a incompatible binary change (signature of function changes). So i wonder if this could lead to quite high PLUGIN_SDK_VERSION_RELEASE  numbers in the future...

For my education, where does this patch change the call or function signature?
Na, sry, was my fault.... i was thinking you add a new parameter, but the parameter was added to a struct...
generally speaking adding members to public structs would also be binary incompatible.... But if the struct is not used between main and plugins it is fine...