How to setup LSP's for python and ansible?

I’m new to kakoune and so far I really like it. The configuration is much smaller than in other terminal based editors. Still, I have some difficulties with setup LSP’s. I want to use python and ansible with their corresponding LSP’s. I read through the documentation but didn’t find sense in it.

That’s a “me” problem in general, I don’t want to say the documentation is bad or so. I just did not get the hang of it.

So I’m asking here for help and I hope I got some. Please be patience with me, I will give my best to understand anything you would say.

Info
I installed kakoune new and deleted the configuration file to start from 0.

Greetings LxWulf

:penguin::wolf:

2 Likes
  1. Install Kakoune

From your message, you don’t seems very familiar with POSIX systems, I recommand to use you OS package manager (e.g. Apt for debian based Linux).

  1. Install Kakoune-lsp

If it is not packaged in your OS package manager, I recommand to use a pre-build binary

  1. Install a language server, e.g. Ruff

  2. Set Kakoune-lsp configuration file, in $HOME/.config/kak-lsp/kak-lsp.toml, uncomment the [language_server.ruff] paragraph

  3. Set Kakoune main configuration file in $HOME/.config/kak/kakrc: add to this file what is recommanded here

  4. Restart Kakoune and edit a Python file

3 Likes

Hey @tototest99,

Firstly, I will thank you for taking time to help, really appreciate this!

Not really, I know that POSIX standard exist but never used it, at least
never consciously. But why did you ask?

My set-up way:

  1. I installed kakoune via dnf successfully.
  2. I also installed kak-lsp via pre-build binary. And I can execute it.
  3. The ruff language server is installed in a virtual python environment.

So far so good, I guess, but in the next step where I should uncomment the
[language_server.ruff] paragraph I stuck, because my file is empty.

So I looked around and found a setup for the helix editor in the ruff-lsp
repository here, which also uses a toml configuration style.

I also added the recommended lines to my kakrc file.

That’s my kakrc file:

eval %sh{kak-lsp --kakoune -s $kak_session}

hook global WinSetOption filetype=(rust|python|go|json|javascript|typescript) %{
    lsp-enable-window
}

# mappings lsp

map global user l %{:enter-user-mode lsp<ret>} -docstring "LSP mode"
map global insert <tab> '<a-;>:try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks <lt>tab> }<ret>' -docstring 'Select next snippet placeholder'
map global object a '<a-semicolon>lsp-object<ret>' -docstring 'LSP any symbol'
map global object <a-a> '<a-semicolon>lsp-object<ret>' -docstring 'LSP any symbol'
map global object f '<a-semicolon>lsp-object Function Method<ret>' -docstring 'LSP function or method'
map global object t '<a-semicolon>lsp-object Class Interface Struct<ret>' -docstring 'LSP class interface or struct'
map global object d '<a-semicolon>lsp-diagnostic-object --include-warnings<ret>' -docstring 'LSP errors and warnings'
map global object D '<a-semicolon>lsp-diagnostic-object<ret>' -docstring 'LSP errors'

This is my kak-lsp.toml file:

[language-server.ruff]
command = "~/Downloads/.venv-lsp/bin/ruff"
 
[[language]]
name = "python"
language-servers = [ "ruff" ]
auto-format = true[language-server.ruff]

Because Kakoune being a relatively niche editor, and Kakoune-lsp being a plugin for said editor is a setup more accessible to people familiar with compiling, installing, and updating via Git under a typical file system hierarchy than by waiting OS package managers to take care of doing it, and most don’t event provide a framework to deploy config files, but anyway I digress…

Kakoune-lsp repo contains a default configuration for most of LSPs. So your kak-lsp.toml could be, I guess:

file_watch_support = false
snippet_support = true
verbosity = 2

[server]
# exit session if no requests were received during given period in seconds
# set to 0 to disable
timeout = 1800 # seconds = 30 minutes

[language_server.ruff]
filetypes = ["python"]
roots = ["requirements.txt", "setup.py", ".git", ".hg"]
command = "ruff-lsp"
settings_section = "_"
[language_server.ruff.settings._.globalSettings]
organizeImports = true
fixAll = true

given that ruff-lsp should be in your $PATH environment variable.

In case it’s not clear, you should have a file such as setup.py in your working directory (or a pyproject.toml as current practice goes).