Posted 3 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Version: 21.1.3
Avatar

Hi,

we would like to change some aspects of the automated intelli prompt, which is provided by the python add-on.

For instance there are two tabs "Public" and "All". We would like to only show the public items and hide the tabs.
I know the API documentation lists several options for that, but how do I access these properties if I am not the one creating them?
There seems to be no options in the SyntaxEditor or EditorView instances and the items are created by PythonCompletionProvider.


Best regards, Tobias Lingemann.

Comments (4)

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

Hi Tobias,

The Public and All tabs are added in the PythonCompletionProvider.RequestSession method.  If you make a MyPythonCompletionProvider class that inherits that class, override the OnSessionOpening method and that is passed the session before it's about to open. 

You could remove the two session.Filters that are CompletionFilter with DisplayMode == CompletionFilterDisplayMode.Tab.  Or for the Public filter, change its DisplayMode to None.

Then in your syntax language, unregister the default PythonCompletionProvider language service and register your MyPythonCompletionProvider language service instead to use it.


Actipro Software Support

Posted 3 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Avatar

Okay, this works when the "Public" filter is also activated. But the PythonCompletionProvider is only called when the user is typing. If the intelli prompt is opened manually with Control and Space, the callback is not called.


Best regards, Tobias Lingemann.

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

Hi Tobias,

I'm am not sure exactly what you are describing when you said the callback is not triggered when pressing CTRL+Space to trigger the completion list, but have verified that the following works to only show public items without any of the filter tabs. This test code was added to the Python Editor demo in our Sample Browser application. What I have done is the following:

Created this custom class to customize the PythonCompletionProvider to customize the tab filters:

public class MyPythonCompletionProvider : PythonCompletionProvider {
	protected override bool OnSessionOpening(ICompletionSession session) {
		for (int i = session.Filters.Count - 1; i >= 0; i--) {
			if (session.Filters[i] is CompletionFilter completionFilter) {
				// Remove the 'All' tab
				if (completionFilter.DisplayMode == CompletionFilterDisplayMode.AllTab)
					session.Filters.RemoveAt(i);

				// Hide the 'Public' tab and manually set it as active since it cannot be selected
				if (completionFilter.DisplayMode == CompletionFilterDisplayMode.Tab) {
					completionFilter.DisplayMode = CompletionFilterDisplayMode.None;
					completionFilter.IsActive = true;
				}
			}
		}

		return base.OnSessionOpening(session);
	}
}

Note that setting the filter "IsActive = true" is a necessary step not previously mentioned. Then I added the following to the end of the constructor for "MainControl" in the Sample Browser file "\ProductSamples\SyntaxEditorSamples\Demo\PythonAddonPythonEditor\MainControl.xaml.cs":

// Unregister default completion provider and replace with custom completion provider
var syntaxLanguage = codeEditor.Document.Language;
syntaxLanguage.UnregisterService<PythonCompletionProvider>();
syntaxLanguage.RegisterService(new MyPythonCompletionProvider());

With this code in place, I can run the Sample Browser and launch the Python Editor demo. When typing code like "self." (for example on Line 21 inside the definition for "__init__") the completion list does not display any of the filter tabs and only shows public items. If I close the completion list and press CTRL+Space with the caret positioned after the already typed text "self.", the completion list is the same with no tabs and public items only. If the callback you are referring to is the "OnSessionOpening" event handler, I've set a breakpoint on "OnSessionOpening" and it is hit every time. Even pressing CTRL+Space at the bottom of the sample my breakpoint is hit.

If you are still not seeing the behavior you expect, can you please try to reproduce what you are seeing with our Python Editor demo and, if successful, let us know how to reproduce?


Actipro Software Support

Posted 3 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Avatar

It looks like the problem was that I didn't unregister the default completion provider. I didn't think it was necessary and as a result the OnSessionOpening callback of my provider was not called.


Best regards, Tobias Lingemann.

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

Add Comment

Please log in to a validated account to post comments.