Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: Pecan on June 30, 2022, 07:44:10 pm

Title: RFC: ccmanager ignores requests for completion.
Post by: Pecan on June 30, 2022, 07:44:10 pm
Patch 1279 https://sourceforge.net/p/codeblocks/tickets/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;

Title: Re: RFC: ccmanager ignores requests for completion.
Post by: BlueHazzard 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...
Title: Re: RFC: ccmanager ignores requests for completion.
Post by: ollydbg on July 02, 2022, 01:51:27 am
Hi, Pecan, thanks for the patch. It also looks good to me. :)
Title: Re: RFC: ccmanager ignores requests for completion.
Post by: Pecan 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?
Title: Re: RFC: ccmanager ignores requests for completion.
Post by: BlueHazzard 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...