# How to setup LSP's for python and ansible?

**URL:** <https://discuss.kakoune.com/t/how-to-setup-lsps-for-python-and-ansible/2422>\
**Category:** Help\
**Tags:** lsp, plugins\
**Created:** [March 5, 2024, 8:49am UTC](https://discuss.kakoune.com/t/how-to-setup-lsps-for-python-and-ansible/2422 "2024-03-05T08:49:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![LxWulf](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/lxwulf/32/1440_2.png) [@LxWulf](https://discuss.kakoune.com/u/LxWulf)\
**Post date:** [March 5, 2024, 8:49am UTC](https://discuss.kakoune.com/t/how-to-setup-lsps-for-python-and-ansible/2422/1 "2024-03-05T08:49:00Z")

</div>

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

🐧🐺

---

<div class="post-metadata">

**Author:** ![tototest99](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/tototest99/32/629_2.png) [@tototest99](https://discuss.kakoune.com/u/tototest99)\
**Post date:** [March 6, 2024, 6:27pm UTC](https://discuss.kakoune.com/t/how-to-setup-lsps-for-python-and-ansible/2422/2 "2024-03-06T18:27:50Z")

</div>

1. [Install Kakoune](https://github.com/mawww/kakoune?tab=readme-ov-file#installing)

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](https://github.com/kakoune-lsp/kakoune-lsp?tab=readme-ov-file#installing)

If it is not packaged in your OS package manager, I recommand to use a [pre-build binary](https://github.com/kakoune-lsp/kakoune-lsp?tab=readme-ov-file#others)

1. [Install a language server, e.g. Ruff](https://docs.astral.sh/ruff/installation/)

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](https://github.com/kakoune-lsp/kakoune-lsp?tab=readme-ov-file#configure-kakoune-to-enable-lsp)

4. Restart Kakoune and edit a Python file

---

<div class="post-metadata">

**Author:** ![LxWulf](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/lxwulf/32/1440_2.png) [@LxWulf](https://discuss.kakoune.com/u/LxWulf)\
**Post date:** [March 9, 2024, 11:55am UTC](https://discuss.kakoune.com/t/how-to-setup-lsps-for-python-and-ansible/2422/3 "2024-03-09T11:55:56Z")

</div>

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](https://github.com/astral-sh/ruff-lsp?tab=readme-ov-file#example-helix), which also uses a `toml` configuration style.

I also added the recommended lines to my `kakrc` file.

**That’s my kakrc file:**

```sh
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:**

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

```

---

<div class="post-metadata">

**Author:** ![tototest99](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/tototest99/32/629_2.png) [@tototest99](https://discuss.kakoune.com/u/tototest99)\
**Post date:** [March 9, 2024, 12:41pm UTC](https://discuss.kakoune.com/t/how-to-setup-lsps-for-python-and-ansible/2422/4 "2024-03-09T12:41:57Z")

</div>

> [@LxWulf](#):
>
> But why did you ask?

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](https://github.com/kakoune-lsp/kakoune-lsp/blob/master/kak-lsp.toml) contains a default configuration for most of LSPs. So your `kak-lsp.toml` could be, I guess:

```auto
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).
