News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

RFC: ccmanager ignores requests for completion.

Started by Pecan, June 30, 2022, 07:44:10 PM

Previous topic - Next topic

Pecan

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.


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;


BlueHazzard

#1
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.next.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...

ollydbg

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.

Pecan

Quote from: BlueHazzard on July 01, 2022, 08:38:10 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?

BlueHazzard

Quote from: Pecan on July 02, 2022, 06:32:16 AM
Quote from: BlueHazzard on July 01, 2022, 08:38:10 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...