2

I want to make jedi (autocompletion, static analysis and refactoring library for python) to understand SageMath code (which is basically Python code with some minor additions and it is preparsing to Python). I want to integrate it with vim via jedi-vim.

There is a discussion with some evidence of possibility of that combo:

Well, I wound up figuring this out. I just had to turn the problem around and include the sage path in the normal python path (export PYTHONPATH=/usr/lib/sagemath/src) - not switch the Jedi interpreter to be the sage interpreter. Seems to work well now. Thanks for the response!

The question is: what should I do to force jedi to have in mind SageMath library?

UPD The idea is to have LSP-like support for Sage as we have for Python. May be jedi-vim isn't best option and jedi-language-server is. One of the reasons is that having LSP is editor-agnostic solution.

The Language Server protocol is used between a tool (the client) and a language smartness provider (the server) to integrate features like auto complete, go to definition, find all references and alike into the tool

There are a lot of editors (almost any famous) and IDE with support of that kind of language servers.

So reformulated question is: are there some adaptations of that solutions to SageMath (which is heavily based on Python and translated to Python)?

petRUShka
  • 9,812
  • 12
  • 61
  • 95
  • 1
    It might be hard to do this with jedi-vim. However if you use the latest Jedi version, there's a way to modify sys paths with `Project`, which is probably what you want. – Dave Halter Apr 17 '20 at 17:08
  • 1
    I'm a SageMath developer--I could have a look at it. I'm a little confused by your question though. What exactly are you trying to do with it? Your question title asks about making jedi "load some specific library from unusual place". What do you mean by that? In fact current versions of Sage already use Jedi indirectly (through IPython) for autocompletion of the Sage library itself. If you want it to work on your own `.sage` files for example, in terms of static analysis there's nothing special about Sage code--the Sage syntax can be converted directly to vanilla Python. – Iguananaut Aug 26 '21 at 21:48
  • I installed jedi-vim, and it seems to work fine with the `sage` package itself. If I enable the Sage environment with `./sage -sh` then run `vim test.py` and start editing a Python file, I can `from sage import ` and jedi-vim kicks in flawlessly. But I'm not really sure that's what you're asking. – Iguananaut Aug 26 '21 at 22:06
  • Playing around more and some things are definitely buggy. Loading `sage.all` takes a long time (not much to be done about that). I also found that it can display the source for classes and functions written in pure Python, but struggles with Cython code. That might be a general shortcoming (which could be fixed) – Iguananaut Aug 26 '21 at 22:15
  • @Iguananaut, very nice to see your comments! My dream is to have [LSP](https://langserver.org/)-like support for Sage as we have fro Python. May be jedi-vim isn't best option and [jedi-language-server](https://pypi.org/project/jedi-language-server/) is. – petRUShka Aug 27 '21 at 08:11
  • @Iguananaut, there are two disucssions on asksage on similar subject: [SageMath support in Jedi (hence in jedi-vim)](https://ask.sagemath.org/question/50801/sagemath-support-in-jedi-hence-in-jedi-vim/) and [LSP (Language Server Protocol) support for SageMath](https://ask.sagemath.org/question/50654/lsp-language-server-protocol-support-for-sagemath/). – petRUShka Aug 27 '21 at 08:19
  • But do you want it to work for the SageMath *library* (which already works since it's written in pure Python and Cython, modulo apparently flaky Cython support...), or are you saying you want to use it for editing new code written using the Sage-specific syntax (which existing Python support in Jedi dies on parsing)? – Iguananaut Aug 27 '21 at 08:40
  • @Iguananaut, Ideally I want some LSP solution which understand Sage code (may be doing some preparsing at background). But as workaround It would be great to at least have SageMath library working with this LSP. – petRUShka Aug 27 '21 at 08:48
  • @Iguananaut, in a perfect case I want to open `.sage`-file with standard sage additions like `x^2` or `load("myfile.sage")` and enjoy completion, documentation hover, go-to definition, symbol understanding, not having error signs on line with Sage code etc. – petRUShka Aug 27 '21 at 08:51

0 Answers0