Skip to main content

SageMath Language Server Protocol

Project description

sage-lsp

Description

Release Platform License GitHub repo size GitHub last commit Python SageMath PyPI Downloads

SageMath Language Server Protocol

[!TIP] This project may work well with SageMath 10.8+. Other versions lack stubs for Cython files, so they may have limited functionality.

However, until now (2026-2-13), SageMath 10.8 is not accessible from conda-forge (but it released on github). Meanwhile, maintainer doesn't include .pyi files in the build system, so you can't simply install it from pip either.

You may need to install it from source code. And edit some code.

git clone --branch 10.8 --single-branch https://github.com/sagemath/sage.git
cd sage
mamba env create --file environment-3.12-linux.yml --name sage10.8
mamba activate sage10.8

Edit ./tools/update-meson.py like this

@@ -93,3 +93,3 @@
       python_files = sorted(
-            list(folder.glob("*.py")) + list(folder.glob('*.pxd')) + list(folder.glob('*.pyx'))
+            list(folder.glob("*.py")) + list(folder.glob('*.pxd')) + list(folder.glob('*.pyx')) + list(folder.glob('*.pyi'))
       )  # + list(folder.glob('*.pxd')) + list(folder.glob('*.h')))

Run ./tools/update-meson.py to regenerate meson.build files. Then you can install it.

python ./tools/update-meson.py
pip install .

Using sage --version to check if successfully installed.

[!WARNING] If raising error about ImportError: cysignals.signals does not export expected C function _do_raise_exception, using following command to fix it.

pip uninstall cysignals
conda install cysignals

Features

Supported from plugins(very thanks to those projects, they finished a lot of work):

  • pygls basic LSP server framework
  • pycodestyle linter for style checking
  • autopep8 formatter for code formatting
  • pyflakes linter for error checking
  • jedi definition, type definiton, hover, references provider
  • parso(dependency of jedi) for folding
  • docstring-to-markdown praser for converting docstrings to markdown for hover information

Supported from native code:

  • Only support using from sage.xxx import xxx or import sage.xxx (no alias)
  • Local symbols cache for Sage
  • Custom formatting rules for Sage
  • Custom error checking for Sage
  • Custom definition for Sage symbols
  • Custom hover information for Sage symbols
  • Check references for Sage (only in current file)
  • Jump to definiton in Cython files (.pyx) from Stubs (.pyi) in Sage 10.8+
  • Support type inference for Sage (depend on .pyi in Sage 10.8+)
  • Support type hints hover info for unfollowed variables
  • Quick fix for undefined name in Sage
  • Completion for Sage (depend on .pyi in Sage 10.8+)

Install

From source code:

git clone https://github.com/SeanDictionary/sage-lsp && cd sage-lsp
pip install .

From pip:

pip install sage-lsp

Usage

Directly run the server

sagelsp --help  // print usage information
sagelsp --sage  // print if SageMath is available and its version
sagelsp -l      // set log level (default: INFO)
sagelsp --clear // clear local symbols cache and exit

Configuration

The server reads style-related configuration from:

  1. Global config: ~/.config/pycodestyle
  2. Project config in workspace root: .pycodestyle, setup.cfg, tox.ini

Project config overrides global config.

For project config files, only the first file found in this order is used:

  1. .pycodestyle
  2. setup.cfg
  3. tox.ini

The parser currently reads these sections:

  • [pycodestyle]
  • [autopep8]
  • [notebook]

Top 2 sections are

[pycodestyle]

Used for style diagnostics from pycodestyle.

Supported keys:

  • select
  • ignore
  • exclude
  • max-line-length
  • indent-size
  • hang-closing
  • experimental
  • aggressive

Example:

[pycodestyle]
ignore = E741, E742, E743, E722, E501
max-line-length = 160

[autopep8]

Used for formatting from autopep8.

Supported keys:

  • select
  • ignore
  • exclude
  • max-line-length
  • indent-size
  • hang-closing
  • experimental
  • aggressive

If [autopep8] is missing, the server falls back to [pycodestyle] for formatter config.

Example:

[autopep8]
max-line-length = 100
aggressive = 1

[notebook]

Used for Jupyter notebook cell-specific overrides.

At the moment, this section supports:

  • ignore

Its values are appended to the normal config when formatting or linting notebook cells.This is useful for rules that are often noisy in cells, such as trailing blank lines at the end of a cell.

Example: Usually, checking W391 (blank line at end of file) and W292 (no newline at end of file) is useless in notebook cells

[notebook]
ignore = W391, W292

Complete example

All sections can be empty.

[pycodestyle]
ignore = E741, E742, E743, E722, E501
max-line-length = 160

[autopep8]
max-line-length = 120
aggressive = 1

[notebook]
ignore = W391, W292

Using with extension SageMath-for-VScode

[!TIP] Make sure you have installed the package sage-lsp in the same Python environment as your SageMath installation, and that the extension can import it.

Install pre-release version 2.0.2-beta from Extension Market to try the new features.

The sorce code of the extension is in SeanDictionary/SageMath-for-VScode. You can also download the pre-release version from GitHub Releases

Change Logs

See CHANGELOG.md

Contributing

See CONTRIBUTING.md

License

This project is licensed under the GPL-3.0 License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sage_lsp-1.1.0.tar.gz (41.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sage_lsp-1.1.0-py3-none-any.whl (49.4 kB view details)

Uploaded Python 3

File details

Details for the file sage_lsp-1.1.0.tar.gz.

File metadata

  • Download URL: sage_lsp-1.1.0.tar.gz
  • Upload date:
  • Size: 41.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sage_lsp-1.1.0.tar.gz
Algorithm Hash digest
SHA256 e1c8abb9ab9101a071a37ce8dc926a7cb7d06ecc287fc502049ae57447cfa261
MD5 c6155f82a4fb732259a2c01ab7b81737
BLAKE2b-256 664bfeeb6a815dcd202f7a8f64e1627ac855956e6e9dae21e875f8fc3097d54c

See more details on using hashes here.

Provenance

The following attestation bundles were made for sage_lsp-1.1.0.tar.gz:

Publisher: publish.yml on SeanDictionary/sage-lsp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sage_lsp-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: sage_lsp-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 49.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sage_lsp-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9c347ef4d31d99e29500576fb545c45deee90c3ab676d257aff3c97c10ffc842
MD5 fffa5644aea45738207373e6e969ef84
BLAKE2b-256 8b4a9ef35693939c8ce9b00e7bfae395920b5d92a73e9e407782e5cded3b6213

See more details on using hashes here.

Provenance

The following attestation bundles were made for sage_lsp-1.1.0-py3-none-any.whl:

Publisher: publish.yml on SeanDictionary/sage-lsp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page