
Hello,
I would suggest that you make a class that inherits the PythonCompletionProvider class and override its OnSessionOpening method. In that, you can look at each item and remove the ones you want. Then call the base OnSessionOpening method and return its result. Unregister the default PythonCompletionProvider service from the language and register your custom one in its place.
Here's a quick example, and of course you could extend the logic a lot more.
private class MyPythonCompletionProvider : PythonCompletionProvider {
protected override bool OnSessionOpening(ICompletionSession session) {
for (var index = session.Items.Count - 1; index >= 0; index--) {
var item = session.Items[index];
var removeItem = false;
if (item.Tag is Text.Languages.Python.Resolution.ITypeResolverResult typeResult) {
// Exclude built-in types
if (typeResult.Type?.DeclaringModule?.IsBuiltin == true)
removeItem = true;
}
else if (item.Tag is Text.Languages.Python.Resolution.IFunctionResolverResult functionResult) {
// Exclude built-in functions
if (functionResult.Function?.DeclaringModule?.IsBuiltin == true)
removeItem = true;
}
else if (item.Tag is Text.Languages.Python.Resolution.IVariableResolverResult variableResult) {
// Exclude built-in variables
if (variableResult.Variable?.DeclaringModule?.IsBuiltin == true)
removeItem = true;
}
// NOTE: Examine other resolve result types in conditionals here too
else if (item.Tag == null) {
// Keywords
removeItem = true;
}
if (removeItem)
session.Items.RemoveAt(index);
}
return base.OnSessionOpening(session);
}
}
editor.Document.Language.UnregisterService<PythonCompletionProvider>();
editor.Document.Language.RegisterService(new MyPythonCompletionProvider());
I hope that helps!