Skip to content

Sublime Usage

Brendan Maginnis edited this page Nov 9, 2020 · 1 revision

Installation

  1. Install the sourcery-cli pypi package pip install --user sourcery-cli. Note down the full command path with
    which sourcery.
  2. Open the command palette and run Package Control: Install Package, then select LSP.
  3. Open Preferences > Package Settings > LSP > Settings from the menu and add the following settings:
{
  "clients": {
    "sourcery": {
      "command": [
        "<Command to run Sourcery>",  // Update this
        "lsp"
      ],
      "enabled": true,
      "languageId": "python",
      "scopes": ["source.python"],
      "syntaxes": [
        "Packages/Python/Python.sublime-syntax",
        "Packages/MagicPython/grammars/MagicPython.tmLanguage",
        "Packages/Djaneiro/Syntaxes/Python Django.tmLanguage",
      ],
      "initializationOptions": {
        "token": "<Your token here>",  // Update this
        "extension_version": "sublime lsp",
        "editor_version": "sublime"
      },
      "settings": {
        "sourcery": {
          "metricsEnabled": true
        }
      }
    }
  }
}

How does it work?

Sourcery scans the currently open Python file. If it finds improvements in your code it highlights the relevant lines of code. To show all the Sourcery suggestions run LSP: Toggle Diagnostics Panel from the command palette. Use F4/shift+F4 to jump to next/previous suggestion.

Hover on a suggestion line to view a description of the refactoring along with a diff. Then you can press super+. to show options to either make the suggested change or to disable it.

The extension can also show you inline code metrics, giving you an instant view of your code quality. Hover on a function's definition to get an instant view of its code quality. Functions with very low quality will additionally be highlighted as warnings.

See the Sourcery Tutorial for more detailed info.

How do I configure Sourcery?

Please see the Sourcery configuration section for details.

Clone this wiki locally