'completion' related issues

SyntaxEditor for WPF Forum

Posted 2 years ago by SPF - Appeon
Version: 22.1.0
Avatar

I have such a need now

1. I need to change the value of "session. Items" when "complexity" is opened.

2. I need to customize the "session. Items" displayed by the filter.

3. I need to customize the setting "session. Selection" and take effect in "session".

How do I need to operate?

  • This is how I change "session. Items"
public override bool RequestSession(IEditorView view, bool canCommintWithoutPopup)
{
    _ = RequestionAsync().ContinueWith(m => 
    {
        var items = m.ConfigureAwait().GetAwaiter().GetResult();
        if(session.isOpen)
        {
            session.Items.Clear();
            session.Items.AddRange(Items);
        }
    });

    return false;
}

Please introduce some important attributes in "CompletionSession" and the related functions of "ICompletionItemMatcher" and "ICompletionFilter". It's best to give a plan that can meet my needs.

Comments (11)

Posted 2 years ago by SPF - Appeon
Avatar

The effects to be achieved are as follows:

1. The filtered items can have the same starting characters or contain these characters, but the priority starting characters of the selected items are the same.

https://postimg.cc/ZWfHdPMR

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

I do want to emphasize that our IntelliPrompt features are not officially supported in async scenarios. If you have concerns about any functionality with IntelliPrompt not working as expected, first test if the functionality works using synchronous code to isolate any issues related to async operations.

It is also worth noting that IntelliPrompt will need to make changes to the UI and should not execute on a worker thread. You may want to execute your async logic using the "view.VisualElement.Dispatcher" to avoid thread-related issues with updating UI controls.

I apologize in advance, but I'm not entirely clear on exactly what you're asking.

1) You ask about changing session items when "complexity" is opened, but I don't know what you mean by "complexity". My assumption is that a user has selected something from a completion list and then you want to present a new completion list with different items? This is typically handled by allowing the previous session to close and then starting a new session. If you are attempting to clear and repopulate the items of the existing session and are encountering issues, please be more specific about exactly what errors you are experiencing and that you are running your code on the dispatcher as noted above.

2) There are two similar concepts and I want to make sure we are talking about the correct one. A filter is used to limit the items that are displayed in the completion list. You might use this to only show methods, for instance. A matcher is used to determine which items in the session (including any filters) are matched by the partial text the user has typed and then the completion list only shows the matching items (also called "auto-shrink"). From the screenshot you posted in the follow-up comment, I assume what you want is a matcher. The Shorthand matcher should achieve a result similar to what you posted. Otherwise you can create a custom matcher to achieve what you are looking for. I posted links to both of those topics below as well as a link to the "Filters" topic for clarity on filter and matcher.

3) The ICompletionSession.Selection property is read-write. If you are having trouble setting a new selection, make sure you are running on the dispatcher as noted above. If you are having a specific issue setting selection and can reproduce it without async code, please let us know any error you are seeing.

Links to relevant topics...

Filters: https://www.actiprosoftware.com/docs/controls/wpf/syntaxeditor/user-interface/intelliprompt/completion-list#filters

Shorthand Matching: https://www.actiprosoftware.com/docs/controls/wpf/syntaxeditor/user-interface/intelliprompt/completion-list#shorthand-matching-algorithm

Custom Matching: https://www.actiprosoftware.com/docs/controls/wpf/syntaxeditor/user-interface/intelliprompt/completion-list#custom-matching-algorithms

ICompletionSession.Selection property: https://www.actiprosoftware.com/docs/controls/wpf/api/actiprosoftware.windows.controls.syntaxeditor.intelliprompt.icompletionsession#actiprosoftware_windows_controls_syntaxeditor_intelliprompt_icompletionsession_selection


Actipro Software Support

Posted 2 years ago by SPF - Appeon
Avatar

I'm sorry for your misunderstanding due to translation.

I want to update "completionsession. Items" when "completionsession" is open.

I have a scenario where every time I input a character, I will use an asynchronous method to request the latest data of "completionsession" to replace the "completionsession. Items" in the open state. At the same time, let "completionsession" and select the most matching item.

The problem I encounter now is that "completionsession" will first select the most matching item and then update the data (session. Items. Clear(); session. Items. AddRange(items); )。 The selection of matching items will match incorrectly with the clearing of items. Is there a way to solve this problem.

[Modified 2 years ago]

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Another suggestion for when updating items is to wrap the update calls in a batch as shown in this documentation topic section.  You should wrap your Clear/AddRange calls with that.

I did a quick test here of clearing and adding items at run-time after the completion session was already open, and the selection seemed to pick the best matching item after the new items were added, which looks correct to me.  If you'd like us to help further, then we'd probably need you to make a new simple sample project that shows the issue and send that to our support address.  Reference this thread in your email and exclude the bin/obj folders from the .zip you send so they don't get spam blocked.  Thanks!


Actipro Software Support

Posted 2 years ago by SPF - Appeon
Avatar

Error range reduction

When "completionsession" is on, the

Do the following. "Matching" is invalid.

using (var batch = session.Items.CreateBatch()) {
        session.Items.Clear();
	session.Items.AddRange(...);
}

The project is at this address

https://github.com/spf-oss/deno

[Modified 2 years ago]

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Thank you for the sample.  We've updated our logic for the next maintenance release to watch for session.Items collection changes, and to reapply selection/filtering after changes are detected.  That change gets your sample working.


Actipro Software Support

Posted 2 years ago by SPF - Appeon
Avatar

OK, and in this demo, set the "canfilterunmatcheditems" property of "completionsession" to true, and the filtering will have performance problems. How to solve it.

[Modified 2 years ago]

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

If you set CanFilterUnmatchedItems, then it means it has to run the matching routines on every item in the completion session, each time a character is typed.  This is necessary to determine which items to filter out and remove from the session, if they don't match.

Another thing is that the UseShorthand option, which I assume you are using, is the more performance-intensive matching algorithm.  It is executing a Regex with a lot of "*" in it to do the matching.

When you combine having to run item matchers on all items, using the performance-intensive Shorthand algorithm, and if there are a lot of items in the completion session, performance can lag a little while typing.

If you want to use CanFilterUnmatchedItems, it would be better to not use the Shorthand algorithm.  Switching to the default or perhaps optionally applying UseAcronyms instead (which has some benefits like Shorthand but only works after capital letters and underscores) will dramatically increase performance.


Actipro Software Support

Posted 2 years ago by SPF - Appeon
Avatar

In VS and vscode, the "use shorthand" pattern is used for matching and filtering, but they can guarantee performance problems. What I want is to ensure the filtering effect of "useshorthand" while ensuring the performance. Do you have any suggestions?

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Unfortunately not since, as mentioned, the Regex to support shorthand effectively uses ".*" in between each letter typed.  If you are using CanFilterUnmatchedItems, then it has to run through all items in the completion session with that logic.  And if you have a lot of text typed and a lot of items, the performance degradation lies in the Regex matching code. Even if you don't use CanFilterUnmatchedItems and the typed text does not have a match, it will search through the entire collection attempting to find a match.

I just profiled it, and 95%+ of the time while typing in this scenario is spent purely in the Regex.IsMatch calls for the items.

We poured over the Regex-related logic for the completion session and found a few areas where we optimized performance, but any additional changes would require major refactoring of the completion session that we are unable to take on at this time. The performance updates will be in the next release.


Actipro Software Support

Answer - Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

We wanted to let you know that for the upcoming v22.1.3 maintenance release, we have refactored the Shorthand item matcher algorithm so that it now runs several times faster.  It can finally be used with the CanFilterUnmatchedItems option with no performance degradation.


Actipro Software Support

The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.