Sublime Forum

Understanding question about auto completion

#1

Hello,

I primarily use Sublime Text to write Python programs. What is important to me is a reasonable auto completion function. I installed Anaconda and Jedi as packages.

What’s not entirely clear to me is whether I even have to install both packages? Is Jedi already integrated into Anaconda? As of now, I have set “disable_anaconda_completion”: true in Anaconda’s user settings because I think that this will deactivate Anaconda’s auto completion function and use Jedi’s auto completion function. It is important to me that if I want to use the lower function, for example, auto completion also inserts the brackets of the function call.

What do you think is the best way to achieve this? Is my setup exactly right for this?

Best regards
gospat

0 Likes

#2

I am surprised you aren’t using the Language Servers which are likely more complete and more well maintained.

LSP + LSP-pyls and or LSP-pyright

0 Likes

#3

Hello,

thanks for your tip. If I understand you correctly, I don’t need Anaconda and Jedi anymore, right? With LSP and lsp-pyright, do I have both auto completion and linting for Python?

Can you tell me what I need to do to “enable” lsp-pyright? I have installed the two packages LSP and lsp-pyright.

To test whether it works, I wrote the following two lines:

for number in range(1, 11):
print(number)

So I deliberately left out the indentation in the second line. But now when I run the code with ctrl+b, I just get the “normal” error message from Sublime Text. I thought I would then get a hint or an error message from lsp-pyright. Do I have the wrong ideas?

0 Likes

#4

Can you tell me what I need to do to “enable” lsp-pyright? I have installed the two packages LSP and lsp-pyright.

It just works.


Some hints probably:

  • LSP-* works best with a project. Some server does support single file or even unsaved buffer. But still a project is supported best.
  • Maybe you need to restart ST (?) or re-open the file.
  • To make sure LSP-pyright is running for the current view, you should see “LSP-pyright” at the bottom-left corner of the window.
  • LSP-ruff is good for linting too.
0 Likes

#5

I can’t see pyright in the bottom left corner.

0 Likes

#6

Run image for LSP-pyright in the command palette and post the output here.

0 Likes

#7

Troubleshooting: LSP-pyright

Version

  • LSP: 1.26.0
  • Sublime Text: 4152

Server Test Run

  • exit code: 0
  • output

Server Configuration

  • command
[
  "${node_bin}", 
  "${server_path}", 
  "--stdio"
]
  • shell command
/usr/bin/node "/home/patrick/.cache/sublime-text/Package Storage/LSP-pyright/21.1.0/language-server/node_modules/pyright/langserver.index.js" --stdio
  • selector
source.python
  • priority_selector
(source.python - source.python.lsp)
  • init_options
{}
  • settings
{
  "pyright": {
    "dev_environment": "", 
    "disableLanguageServices": false, 
    "disableOrganizeImports": false
  }, 
  "python": {
    "analysis": {
      "autoImportCompletions": true, 
      "autoSearchPaths": true, 
      "diagnosticMode": "openFilesOnly", 
      "diagnosticSeverityOverrides": {
        "reportDuplicateImport": "warning", 
        "reportImplicitStringConcatenation": "warning", 
        "reportMissingParameterType": "none", 
        "reportUnboundVariable": "warning", 
        "reportUninitializedInstanceVariable": "none", 
        "reportUnusedClass": "information", 
        "reportUnusedFunction": "information", 
        "reportUnusedImport": "information", 
        "reportUnusedVariable": "information"
      }, 
      "extraPaths": [], 
      "logLevel": "Information", 
      "stubPath": "./typings", 
      "typeCheckingMode": "basic", 
      "typeshedPaths": [], 
      "useLibraryCodeForTypes": true
    }, 
    "pythonPath": "/usr/bin/python", 
    "venvPath": ""
  }
}
  • env
{
  "PATH": "/usr/bin:/usr/bin:"
}

Active view

  • File name
/home/patrick/Schreibtisch/Python/Projekt/test.py
  • Settings
{
  "auto_complete_selector": "meta.tag, source - comment - string.quoted.double.block - string.quoted.single.block - string.unquoted.heredoc", 
  "lsp_active": null, 
  "syntax": "Packages/Python/Python.sublime-syntax"
}
  • base scope
source.python

Project / Workspace

  • folders
[
  "/home/patrick/Schreibtisch/Python"
]
  • is project: True
  • project data:
{
  "build_systems": [
    {
      "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", 
      "name": "Anaconda Python Builder", 
      "selector": "source.python", 
      "shell_cmd": "\"python\" -u \"$file\""
    }
  ], 
  "folders": [
    {
      "path": "/home/patrick/Schreibtisch/Python"
    }
  ], 
  "settings": {
    "LSP": {
      "LSP-pyright": {
        "enabled": true
      }
    }
  }
}

LSP configuration

<not found>

System PATH

  • /usr/local/sbin
  • /usr/local/bin
  • /usr/sbin
  • /usr/bin
  • /sbin
  • /bin
  • /usr/games
  • /usr/local/games
  • /snap/bin
0 Likes

#8

Is there any noticeable error message in ST’s console? (ctrl+`)

The troubleshooting results look good to me. Don’t know why it’s not running for your file.

0 Likes

#9

Is it normal, that the troubleshooting output shows “Anaconda Python Builder”? I am using the regular Python build system.

0 Likes

#10

That should be irrelevant to LSP-pyright.

0 Likes

#11

And this is the output on the console.

  File "/home/patrick/Schreibtisch/Python/Projekt/test.py", line 2
    print(number)
    ^
IndentationError: expected an indented block after 'for' statement on line 1
[Finished in 245ms with exit code 1]
[cmd: ['python3', '-u', '/home/patrick/Schreibtisch/Python/Projekt/test.py']]
[dir: /home/patrick/Schreibtisch/Python/Projekt]
[path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin]
0 Likes

#12

Please answer to this. I am not asking build output, but ST’s console.

0 Likes

#13

Can you tell me what I have to do exactly? I am totally new to Sublime Text.

0 Likes

#14

Ah, I found it. Here is the output:

startup, version: 4152 linux x64 channel: stable
executable: /opt/sublime_text/sublime_text
application: /opt/sublime_text
working dir: /home/patrick
packages path: /home/patrick/.config/sublime-text/Packages
state path: /home/patrick/.config/sublime-text/Local
zip path: /opt/sublime_text/Packages
zip path: /home/patrick/.config/sublime-text/Installed Packages
ignored_packages: ["Vintage"]
pre session restore time: 0.343106
startup time: 0.444619
first paint time: 0.475875
reloading plugin Default.arithmetic
reloading plugin Default.auto_indent_tag
reloading plugin Default.block
reloading plugin Default.colors
reloading plugin Default.comment
reloading plugin Default.convert_color_scheme
reloading plugin Default.convert_syntax
reloading plugin Default.copy_path
reloading plugin Default.echo
reloading plugin Default.exec
reloading plugin Default.fold
reloading plugin Default.font
reloading plugin Default.goto_line
reloading plugin Default.history_list
reloading plugin Default.html_print
reloading plugin Default.indentation
reloading plugin Default.install_package_control
reloading plugin Default.keymap
reloading plugin Default.kill_ring
reloading plugin Default.mark
reloading plugin Default.new_templates
reloading plugin Default.open_context_url
reloading plugin Default.open_in_browser
reloading plugin Default.pane
reloading plugin Default.paragraph
reloading plugin Default.paste_from_history
reloading plugin Default.profile
reloading plugin Default.quick_panel
reloading plugin Default.rename
reloading plugin Default.run_syntax_tests
reloading plugin Default.save_on_focus_lost
reloading plugin Default.scroll
reloading plugin Default.set_unsaved_view_name
reloading plugin Default.settings
reloading plugin Default.show_scope_name
reloading plugin Default.side_bar
reloading plugin Default.sort
reloading plugin Default.switch_file
reloading plugin Default.symbol
reloading plugin Default.transform
reloading plugin Default.transpose
reloading plugin Default.ui
reloading python 3.3 plugin 0_package_control_loader.00-package_control
reloading python 3.3 plugin 0_package_control_loader.01-pygments
reloading plugin CSS.css_completions
reloading python 3.3 plugin 0_package_control_loader.01-sublime_lib
reloading python 3.3 plugin 0_package_control_loader.10-lsp_utils
reloading python 3.3 plugin 0_package_control_loader.50-backrefs
reloading python 3.3 plugin 0_package_control_loader.50-bracex
reloading python 3.3 plugin 0_package_control_loader.50-markupsafe
reloading python 3.3 plugin 0_package_control_loader.50-pathlib
reloading python 3.3 plugin 0_package_control_loader.50-pymdownx
reloading python 3.3 plugin 0_package_control_loader.50-python-markdown
reloading python 3.3 plugin 0_package_control_loader.50-pyyaml
reloading python 3.3 plugin 0_package_control_loader.51-python-jinja2
reloading python 3.3 plugin 0_package_control_loader.55-mdpopups
reloading python 3.3 plugin 0_package_control_loader.55-wcmatch
reloading python 3.3 plugin BracketHighlighter.bh_core
reloading plugin Diff.diff
reloading plugin HTML.encode_html_entities
reloading plugin HTML.html_completions
reloading python 3.3 plugin BracketHighlighter.bh_logging
reloading python 3.3 plugin BracketHighlighter.bh_plugin
reloading python 3.3 plugin BracketHighlighter.bh_popup
reloading python 3.3 plugin BracketHighlighter.bh_regions
reloading python 3.3 plugin BracketHighlighter.bh_remove
reloading python 3.3 plugin BracketHighlighter.bh_rules
reloading python 3.3 plugin BracketHighlighter.bh_search
reloading python 3.3 plugin BracketHighlighter.bh_swapping
reloading python 3.3 plugin BracketHighlighter.bh_wrapping
reloading python 3.3 plugin BracketHighlighter.support
reloading python 3.3 plugin LSP-pyright.commands
reloading python 3.3 plugin LSP-pyright.plugin
reloading python 3.3 plugin LSP.boot
reloading python 3.3 plugin Material Theme.MT
reloading python 3.3 plugin Package Control.1_reloader
reloading python 3.3 plugin Package Control.2_bootstrap
reloading python 3.3 plugin Package Control.Package Control
reloading python 3.3 plugin SideBarEnhancements.SideBar
reloading python 3.3 plugin SideBarEnhancements.SideBarAPI
reloading python 3.3 plugin SideBarEnhancements.SideBarDefaultDisable
reloading python 3.3 plugin SublimeREPL.__init__
reloading python 3.3 plugin SublimeREPL.completions
reloading python 3.3 plugin SublimeREPL.lang_integration
reloading python 3.3 plugin SublimeREPL.run_existing_command
reloading python 3.3 plugin SublimeREPL.sublimerepl
reloading python 3.3 plugin SublimeREPL.sublimerepl_build_system_hack
reloading python 3.3 plugin SublimeREPL.text_transfer
plugins loaded
Package Control: No updated packages
0 Likes

#15

Looks good to me. Now I am completely lost.

Just want to make sure but may be not relevant. You have tried all the followings, right?

  • Restart ST
  • Reopen the project
  • Reopen the file
0 Likes

#16

I installed Sublime Text and all plugins again. The permanent installation and uninstallation of plugins may have caused some problem. But now lsp-pyright works. Thank you for your patience and effort!

Best regards
gospat

0 Likes