Skip to content

Add zubanls as optional static inference completion backend#15143

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-zuban-language-server-support
Draft

Add zubanls as optional static inference completion backend#15143
Copilot wants to merge 2 commits intomainfrom
copilot/add-zuban-language-server-support

Conversation

Copy link
Contributor

Copilot AI commented Feb 24, 2026

Adds zubanls as an optional alternative to Jedi for static type inference completions in IPython's tab completer. Jedi remains the default and takes precedence when enabled.

Changes

  • Detection (completer.py): ZUBANLS_INSTALLED flag set via try/import zubanls block, mirroring the Jedi detection pattern.
  • New traitlet (Completer.use_zubanls): Bool, defaults to False, tagged configurable. No-op if use_jedi=True.
  • New matcher (IPCompleter._zubanls_matcher / _zubanls_matches): Context matcher calling zubanls.complete(source=text, position=offset), adapting results to SimpleCompletion. Exceptions caught gracefully; debug mode prints (ExceptionType: message).
  • matchers property: Added elif use_zubanls and ZUBANLS_INSTALLED branch — same matcher list structure as the Jedi branch but with _zubanls_matcher.
  • all_completions: Prefix join now triggers on use_jedi or use_zubanls.
  • Startup warning: UserWarning emitted in IPCompleter.__init__ if use_zubanls=True but package is absent.
  • Docs: Changelog entry and usage section in whatsnew/version9.rst.

Usage

# In ipython_config.py or via CLI:
c.Completer.use_jedi = False
c.Completer.use_zubanls = True

Or:

ipython --Completer.use_jedi=False --Completer.use_zubanls=True
Original prompt

Summary

Add support for Zuban Language Server (zubanls) as an optional alternative completion backend to Jedi in IPython's tab completer.

Motivation

IPython currently uses Jedi as its static analysis / type-inference completion backend (IPCompleter.jedi_matcher). zubanls is a Python completion library that can serve as an alternative or complement to Jedi. This PR should allow users to optionally configure IPython to use zubanls instead of (or alongside) Jedi for completions.

What to implement

1. Detection of zubanls

In IPython/core/completer.py, alongside the existing Jedi detection block:

try:
    import jedi
    jedi.settings.case_insensitive_completion = False
    import jedi.api.helpers
    import jedi.api.classes
    JEDI_INSTALLED = True
except ImportError:
    JEDI_INSTALLED = False

Add a similar detection block for zubanls:

try:
    import zubanls
    ZUBANLS_INSTALLED = True
except ImportError:
    ZUBANLS_INSTALLED = False

2. New configurable trait on Completer

In the Completer class (which is a Configurable), add a new traitlet:

use_zubanls = Bool(
    default_value=False,
    help=(
        "Use zubanls as the completion backend instead of Jedi. "
        "Requires the `zubanls` package to be installed. "
        "When enabled, zubanls will be used for static type inference completions. "
        "This setting has no effect if `use_jedi` is also True (Jedi takes precedence) "
        "unless `use_jedi` is set to False."
    ),
).tag(config=True)

3. New matcher: _zubanls_matcher

In IPCompleter, add a new context matcher analogous to _jedi_matcher:

@context_matcher(identifier="IPCompleter.zubanls_matcher")
def _zubanls_matcher(self, context: CompletionContext) -> SimpleMatcherResult:
    """Completion matcher using zubanls as the backend."""
    if not self.use_zubanls or not ZUBANLS_INSTALLED:
        return {"completions": [], "suppress": False}
    matches = self._zubanls_matches(
        cursor_column=context.cursor_position,
        cursor_line=context.cursor_line,
        text=context.full_text,
    )
    return {"completions": matches, "suppress": False}

Implement _zubanls_matches using the zubanls Python API (see https://docs.zubanls.com/en/latest/ for the API). The method should return an iterator of SimpleCompletion-compatible objects, adapting zubanls completions to IPython's internal SimpleCompletion format (with .text and .type attributes).

4. Register the matcher

Make sure _zubanls_matcher is included in the list of matchers used by IPCompleter._complete / _completions. It should be registered in the matchers list conditionally (only active when use_zubanls=True and zubanls is installed).

5. Interaction with use_jedi

  • If both use_jedi=True and use_zubanls=True, Jedi takes precedence (or raise a warning telling the user to disable Jedi first).
  • If use_jedi=False and use_zubanls=True and zubanls is installed, zubanls is used as the static inference backend.
  • If zubanls is not installed and use_zubanls=True, emit a warning at startup and fall back gracefully (no crash).

6. Update all_completions

The all_completions method currently has:

return ['.'.join([prefix, c.text]) if prefix and self.use_jedi else c.text
        for c in self.completions(text, len(text))]

Update this to also handle the use_zubanls case similarly.

7. Documentation / changelog

  • Add a brief entry in docs/source/whatsnew/version9.rst (under the appropriate section) mentioning the new Completer.use_zubanls option.
  • Update docstrings as appropriate.

Files to modify

  • IPython/core/completer.py — main implementation
  • docs/source/whatsnew/version9.rst — changelog entry

Notes

  • The zubanls Python API docs are at https://docs.zubanls.com/en/latest/. Use the appropriate completion API from zubanls that takes a source text and cursor position and returns completions with .name, .type, and related attributes.
  • The implementation should be resilient: if zubanls raises an exception, catch it and return an empty iterator (similar to how Jedi errors are handled).
  • Keep the change backward-compatible: use_zubanls defaults to False, so existing users see no change.

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: Carreau <335567+Carreau@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for Zuban Language Server in IPython Add zubanls as optional static inference completion backend Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants