More things better

Hello everyone!

So I have more questions.

  1. Find and select files with FZF (not in Kakoune)

    I’m not referring to something like fzf.kak. I mean from your commandline like kak $(ls -R -i dir-pattern-to-ignore ~/path/to/dir | fzf) (don’t have the $ if you use Fish-shell).

    The above does run, however on selecting an option Kakoune will just open a new file in your current directory. You can instead use $(rg --files --glob !dir-glob --smart-case ~/path/to/dir | fzf), but I don’t know that feels like overkill.

  2. Language server fun

    I have a silly web project in Typescript that I’m trying to finish up. While I don’t really need it for this project, I use the typescript-language-server. The kak-lsp.toml I have has this for Typescript:

        filetype = ["typescript"]
        roots = ["package.json", "tsconfig.json"]
        command = "typescript-language-server"
        args = ["--stdio"]

    You can use this language server for Javascript as well. However opening my project I…don’t think the language server is started. *debug* shows nothing besides that kak-lsp was loaded. I don’t know if there’s something else I need to do to get typescript-language-server to work with kak-lsp, or if this is a kak-lsp internals thing.

    And to clarify, this language server works fine in Emacs with lsp-mode.

  3. Log file?

    While double checking if kak-lsp worked fine with other languages, I found I had an issue of when I saved a file and Kakoune was stuck perpetually in waiting for shell command to finish and I have to kill Kakoune manually. I have

     plug "ul/kak-lsp" do %{
        cargo install --force --path . --locked
        cargo clean
     } config %{
     define-command lsp-restart %{ lsp-stop; lsp-start }
     set-option global lsp_completion_trigger "execute-keys 'h<a-h><a-k>\S[^\s,=;*(){}\[\]]\z<ret>'"
     set-option global lsp_diagnostic_line_error_sign "!"
     set-option global lsp_diagnostic_line_warning_sign "?"
     hook global WinSetOption filetype=(c|cpp|objc|d|rust|haskell|nim|elixir|latex|javascript) %{
         eval %sh{
              kak-lsp --kakoune --config ~/.config/kak-lsp/kak-lsp.toml -vvv \
              --log "$XDG_CONFIG_HOME/kak-lsp/kak-lsp.log" -s $kak_session
         set-option global lsp_auto_highlight_references true
         set-option global lsp_hover_anchor true
         # Semantic highlighting
         hook window -group semantic-tokens BufReload .* lsp-semantic-tokens
         hook window -group semantic-tokens NormalIdle .* lsp-semantic-tokens
         hook window -group semantic-tokens InsertIdle .* lsp-semantic-tokens
         hook -once -always window WinSetOption filetype=.* %{
              remove-hooks window semantic-tokens
         # Other things
         hook window BufWritePre .* lsp-formatting-sync
         hook window BufWritePost .* lsp-diagnostics
         hook -always global KakEnd .* lsp-exit

    For my configuration for kak-lsp, and I would think there would be a log file in ~/.config/kak-lsp but there isn’t. I also don’t recall where or if there’s a default log file for Kakoune. I’m pretty sure I know what the issue is (it’s with linting or formatting), but I wish there was a log I could look at to see I’m correct in my assumption.

  4. Linting output

    One of the things I would like is to have is for the output of the lint command to show up in a split or something instead of me having to go over to the *lint-output* buffer.

    Another thing is that I’ve noticed some lint commands don’t actually output to the *lint-output* buffer, they output to *debug*. Is that suppose to happen?


  1. Copying, yanking, pasting

    So we all probably have something similar to this in our configs for pasting, yanking etc.:

    hook global NormalKey y|d|c %{
        nop %sh{
            printf %s "$kak_main_reg_dquote" | xsel --input --clipboard
    map global normal D     ';<a-l>d'
    map global normal <a-d> ';<a-h>d'
    evaluate-commands %sh{
        copy="xsel --input --clipboard"
        paste="xsel --output --clipboard"
        printf \
        "map global normal -docstring 'Paste (after) from clipboard' p '!%s<ret>'\n" "$paste"
        printf \
        "map global normal -docstring 'Paste (before) from clipboard' P '<a-!>%s<ret>'\n" "$paste"
        #printf \
        #"map global normal -docstring 'Replace selection with system clipboard' R '|%s<ret>'" "$paste"
        printf \
        "map global normal -docstring 'Copy to system clipboard' y '<a-|>%s<ret>'\n" "$copy"
        printf \
        "map global normal -docstring 'Copy to EOL to system clipboard' Y '<a-l><a-|>%s<ret><a-;>;'\n" "$copy"

    But some things are a little strange. My y and Y doesn’t actually append anything to the default yank/paste register, and neither do external copies. This is only an issue when I’m in insert mode. I don’t want to go back to normal mode just to paste (yes, I know you can press whatever key it is to enter 1 normal key or 1 command from insert mode), so I’d use C-r " but there’s nothing in the " register unless I delete something.

I believe you don’t really need that eval %sh{} block in your lsp config, since lsp-enable-window pretty much does that, so you enable lsp twice

I think you want to use -I (capital) instead of -i.

The small -i prints the inode of each file, so Kakoune basically receives 2 words: 12345 and foo. As 12345, the inode number, is not a file name, Kakoune starts with an empty buffer.

Oh whoops. I got it write trying it out in the commandline but mixed it up writing this out.

EDIT: though that doesn’t change that Kakoune doesn’t open the selected file in the containing directory. It just opens a new file of the selected ones name in the current directory. Ex. In the home directoy and doing kak $(ls -R ~/.config/kak | fzf) with selecting kakrc will just create an empty file in Kakoune that’s in the home directory named kakrc.

That does make sense.

This isn’t related to Kakoune. If you straight-up run:

ls -R -i dir-pattern-to-ignore ~/path/to/dir

…you’ll see it prints each path as relative to ~/path/to/dir, so fzf can only offer you those relative paths, and so when the result gets passed to Kakoune, it opens a relative path - but relative to the wrong directory. By contrast, rg always includes the start-point you provide at the beginning of each printed path, so by the time the paths make it through to Kakoune, it still has enough context to open the correct file.

There doesn’t appear to be a way to make ls include the full path with each filename it prints, so rg is probably the right choice here.

I know you need to source the kak-lsp configuration, and then run the lsp-enable command it creates, before LSP stuff will appear. Once you run lsp-enable, it will try to launch (or re-use) a language-server for each buffer you create, though, you don’t have to re-enable it every time.

I notice you set the log file to $XDG_CONFIG_HOME/kak-lsp/kak-lsp.log, but $XDG_CONFIG_HOME generally isn’t set, so it’s probably trying to write to /kak-lsp/kak-lsp.log, getting a “permission denied” error, and having nowhere to report it. Since you manually write out ~/.config for the config file, you might as well do it for the log file too.

Personally, when debugging kak-lsp issues I just launch it manually in another terminal like:

kak-lsp -s somesession

…and then I launch Kakoune with:

kak -s somesession

…and when Kakoune tries to communicate with kak-lsp, it communicates with the one that’s running where I can see it, instead of starting a background one whose errors and warnings vanish into the ether.

Kakoune itself doesn’t do splits, but if you create a separate window (with :new) and set it to be the “toolsclient”, then the output of commands like :lint and :make will automatically be displayed there. See IDE Mode in the wiki for more information.

Your mappings for Y and y (inside the evaluate-commands block) run instead of the default implementations, so they’ll only interact with the X11 clipboard and not with the rest of Kakoune.

I think the NormalKey hook at the top will run in addition to the default implementations, but it’s redundant with the mappings below it.

Hopefully one day somebody will implement register hooks and we can have simpler and more reliable clipboard integration.

There doesn’t appear to be a way to make ls include the full path with each filename it prints, so rg is probably the right choice here.

Yea looking around, the means to make ls also give the full path would be wonky. It’d be easier to just use rg --files.

I know you need to source the kak-lsp configuration, and then run the lsp-enable command it creates, before LSP stuff will appear. Once you run lsp-enable, it will try to launch (or re-use) a language-server for each buffer you create, though, you don’t have to re-enable it every time.

Mmmm, looking at the code for kak-lsp, I don’t know why I didn’t think there would be an option to set the command for kak-lsp.

So now I have

set-option global lsp_cmd "kak-lsp -vvv -c ~/.config/kak-lsp/kak-lsp.toml -s %val{session} --log ~/.config/kak-lsp/kak-lsp.log"

and hopefully that’ll get me somewhere.

I also put

echo -debug "Enabling LSP for filtetype %opt{filetype}"

Inside of a

hook global WinSetOption filetype=(c|cpp|objc|d|rust|haskell|nim|elixir|latex|javascript) %{}

So that way I have a starting indicator if something done fucked up.

Oh yea I remember looking at that.

Is there anything more needed to be done? Because all that’s given is the code snippet and then

Then it’s up to tmux or your window manager (dwm, i3, xmonad…) to fit them correctly on your monitor.

So is

def ide %{
    rename-client main
    set global jumpclient main

    new rename-client tools
    set global toolsclient tools

    new rename-client docs
    set global docsclient docs

all that’s needed?

I’m not sure how useful that option will be — before you can set the option that says how to run kak-lsp, you already need to have run kak-lsp to define the option. But, if it’s working for you, then great!

def is short for define-command. Nothing will happen until you run the :ide command, and then it will open a bunch of windows and set the *client options appropriately.