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

# This section overrides language IDs.
# By default, kakoune-lsp uses filetypes for the IDs.
# See https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentItem
[language_ids]
c = "c_cpp"
cpp = "c_cpp"
javascript = "javascriptreact"
typescript = "typescriptreact"
protobuf = "proto"
sh = "shellscript"

[language_server.bash-language-server]
filetypes = ["sh"]
roots = [".git", ".hg"]
command = "bash-language-server"
args = ["start"]

[language_server.clangd]
filetypes = ["c", "cpp"]
roots = ["compile_commands.json", ".clangd", ".git", ".hg"]
command = "clangd"

[language_server.clojure-lsp]
filetypes = ["clojure"]
roots = ["project.clj", ".git", ".hg"]
command = "clojure-lsp"
settings_section = "_"
[language_server.clojure-lsp.settings._]
# See https://clojure-lsp.io/settings/#all-settings
# source-paths-ignore-regex = ["resources.*", "target.*"]

[language_server.cmake-language-server]
filetypes = ["cmake"]
roots = ["CMakeLists.txt", ".git", ".hg"]
command = "cmake-language-server"

[language_server.crystalline]
filetypes = ["crystal"]
roots = ["shard.yml"]
command = "crystalline"

[language_server.css-language-server]
filetypes = ["css"]
roots = ["package.json", ".git", ".hg"]
command = "vscode-css-language-server"
args = ["--stdio"]

# [language_server.deno-lsp]
# filetypes = ["javascript", "typescript"]
# roots = ["package.json", "tsconfig.json", ".git", ".hg"]
# command = "deno"
# args = ["lsp"]
# settings_section = "deno"
# [language_server.deno-lsp.settings.deno]
# enable = true
# lint = true

[language_server.less-language-server]
filetypes = ["less"]
roots = ["package.json", ".git", ".hg"]
command = "vscode-css-language-server"
args = ["--stdio"]


# See https://scalameta.org/metals/docs/integrations/new-editor
[language_server.metals]
filetypes = ["scala"]
roots = ["build.sbt", ".scala-build"]
command = "metals"
args = ["-Dmetals.extensions=false"]
settings_section = "metals"
[language_server.metals.settings.metals]
icons = "unicode"
isHttpEnabled = true
statusBarProvider = "show-message"
compilerOptions = { overrideDefFormat = "unicode" }
inlayHints.hintsInPatternMatch.enable = true
inlayHints.implicitArguments.enable = true
inlayHints.implicitConversions.enable = true
inlayHints.inferredTypes.enable = true
inlayHints.typeParameters.enable = true

[language_server.nil]
filetypes = ["nix"]
command = "nil"
roots = ["flake.nix", "shell.nix", ".git", ".hg"]

[language_server.scss-language-server]
filetypes = ["scss"]
roots = ["package.json", ".git", ".hg"]
command = "vscode-css-language-server"
args = ["--stdio"]

[language_server.dls]
filetypes = ["d", "di"]
roots = [".git", "dub.sdl", "dub.json"]
command = "dls"

[language_server.dart-lsp]
# start shell to find path to dart analysis server source
filetypes = ["dart"]
roots = ["pubspec.yaml", ".git", ".hg"]
command = "sh"
args = ["-c", "dart $(dirname $(command -v dart))/snapshots/analysis_server.dart.snapshot --lsp"]

[language_server.jdtls]
filetypes = ["java"]
roots = ["mvnw", "gradlew", ".git", ".hg"]
command = "jdtls"
[language_server.jdtls.settings]
# See https://github.dev/eclipse/eclipse.jdt.ls
# "java.format.insertSpaces" = true

[language_server.elixir-ls]
filetypes = ["elixir"]
roots = ["mix.exs"]
command = "elixir-ls"
settings_section = "elixirLS"
[language_server.elixir-ls.settings.elixirLS]
# See https://github.com/elixir-lsp/elixir-ls/blob/master/apps/language_server/lib/language_server/server.ex
# dialyzerEnable = true

[language_server.elm-language-server]
filetypes = ["elm"]
roots = ["elm.json"]
command = "elm-language-server"
args = ["--stdio"]
settings_section = "elmLS"
[language_server.elm-language-server.settings.elmLS]
# See https://github.com/elm-tooling/elm-language-server#server-settings
runtime = "node"
elmPath = "elm"
elmFormatPath = "elm-format"
elmTestPath = "elm-test"

[language_server.elvish]
filetypes = ["elvish"]
roots = [".git", ".hg"]
command = "elvish"
args = ["-lsp"]

[language_server.erlang-ls]
filetypes = ["erlang"]
# See https://github.com/erlang-ls/erlang_ls.git for more information and
# how to configure. This default config should work in most cases though.
roots = ["rebar.config", "erlang.mk", ".git", ".hg"]
command = "erlang_ls"

[language_server.gopls]
filetypes = ["go"]
roots = ["Gopkg.toml", "go.mod", ".git", ".hg"]
command = "gopls"
[language_server.gopls.settings.gopls]
# See https://github.com/golang/tools/blob/master/gopls/doc/settings.md
# "build.buildFlags" = []
hints.assignVariableTypes = true
hints.compositeLiteralFields = true
hints.compositeLiteralTypes = true
hints.constantValues = true
hints.functionTypeParameters = true
hints.parameterNames = true
hints.rangeVariableTypes = true
"ui.completion.usePlaceholders" = true

[language_server.haskell-language-server]
filetypes = ["haskell"]
roots = ["hie.yaml", "cabal.project", "Setup.hs", "stack.yaml", "*.cabal"]
command = "haskell-language-server-wrapper"
args = ["--lsp"]
settings_section = "_"
[language_server.haskell-language-server.settings._]
# See https://haskell-language-server.readthedocs.io/en/latest/configuration.html
# haskell.formattingProvider = "ormolu"

[language_server.html-language-server]
filetypes = ["html"]
roots = ["package.json"]
command = "vscode-html-language-server"
args = ["--stdio"]
settings_section = "_"
[language_server.html-language-server.settings._]
# quotePreference = "single"
# javascript.format.semicolons = "insert"

[language_server.intelephense]
filetypes = ["php"]
roots = [".htaccess", "composer.json"]
command = "intelephense"
args = ["--stdio"]
settings_section = "intelephense"
[language_server.intelephense.settings.intelephense]
storagePath = "/tmp/intelephense"

[language_server.json-language-server]
filetypes = ["json"]
roots = ["package.json"]
command = "vscode-json-language-server"
args = ["--stdio"]

# Requires Julia package "LanguageServer"
# Run: `julia --project=@kak-lsp -e 'import Pkg; Pkg.add("LanguageServer")'` to install it
# Configuration adapted from https://github.com/neovim/nvim-lspconfig/blob/bcebfac7429cd8234960197dca8de1767f3ef5d3/lua/lspconfig/julials.lua
[language_server.julia-language-server]
filetypes = ["julia"]
roots = ["Project.toml", ".git", ".hg"]
command = "julia"
args = [
    "--startup-file=no",
    "--history-file=no",
    "-e",
    """
    ls_install_path = joinpath(get(DEPOT_PATH, 1, joinpath(homedir(), ".julia")), "environments", "kak-lsp");
    pushfirst!(LOAD_PATH, ls_install_path);
    using LanguageServer;
    popfirst!(LOAD_PATH);
    depot_path = get(ENV, "JULIA_DEPOT_PATH", "");
    buffer_file = ENV["kak_buffile"];
    project_path = let
      dirname(something(
        # 1. Check if there is an explicitly set project
        Base.load_path_expand((
          p = get(ENV, "JULIA_PROJECT", nothing);
          p === nothing ? nothing : isempty(p) ? nothing : p
        )),
        # 2. Check for Project.toml in current working directory
        Base.current_project(pwd()),
        # 3. Check for Project.toml from buffer's full file path excluding the file name
        Base.current_project(dirname(buffer_file)),
        # 4. Fallback to global environment
        Base.active_project()
      ))
    end
    server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path);
    server.runlinter = true;
    run(server);
    """,
]
[language_server.julia-language-server.settings]
# See https://github.com/julia-vscode/LanguageServer.jl/blob/master/src/requests/workspace.jl
# Format options. See https://github.com/julia-vscode/DocumentFormat.jl/blob/master/src/DocumentFormat.jl
# "julia.format.indent" = 4
# Lint options. See https://github.com/julia-vscode/StaticLint.jl/blob/master/src/linting/checks.jl
# "julia.lint.call" = true
# Other options, see https://github.com/julia-vscode/LanguageServer.jl/blob/master/src/requests/workspace.jl
# "julia.lint.run" = "true"

[language_server.lua-language-server]
filetypes = ["lua"]
roots = [".git", ".hg"]
command = "lua-language-server"
settings_section = "Lua"
[language_server.lua-language-server.settings.Lua]
# See https://github.com/sumneko/vscode-lua/blob/master/setting/schema.json
# diagnostics.enable = true

[language_server.markdown]
filetypes = ["markdown"]
roots = [".marksman.toml"]
command = "marksman"
args = ["server"]

# [language_server.zk]
# filetypes = ["markdown"]
# roots = [".zk"]
# command = "zk"
# args = ["lsp"]

[language_server.nimlsp]
filetypes = ["nim"]
roots = ["*.nimble", ".git", ".hg"]
command = "nimlsp"

[language_server.ocamllsp]
filetypes = ["ocaml"]
# Often useful to simply do a `touch dune-workspace` in your project root folder if you have problems with root detection
roots = ["dune-workspace", "dune-project", "Makefile", "opam", "*.opam", "esy.json", ".git", ".hg", "dune"]
command = "ocamllsp"

[language_server.pls]
filetypes = ["protobuf"]
roots = [".git", ".hg"]
command = "pls" # https://github.com/lasorda/protobuf-language-server

[language_server.purescript-language-server]
filetypes = ["purescript"]
roots = ["spago.dhall", "spago.yaml", "package.json", ".git", ".hg"]
command = "purescript-language-server"
args = ["--stdio"]

[language_server.pylsp]
filetypes = ["python"]
roots = ["requirements.txt", "setup.py", ".git", ".hg"]
command = "pylsp"
settings_section = "_"
[language_server.pylsp.settings._]
# See https://github.com/python-lsp/python-lsp-server#configuration
# pylsp.configurationSources = ["flake8"]
pylsp.plugins.jedi_completion.include_params = true

# [language_server.pyright]
# filetypes = ["python"]
# roots = ["requirements.txt", "setup.py", "pyrightconfig.json", ".git", ".hg"]
# command = "pyright-langserver"
# args = ["--stdio"]

# [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

[language_server.r-language-server]
filetypes = ["r"]
roots = ["DESCRIPTION", ".git", ".hg"]
command = "R"
args = ["--slave", "-e", "languageserver::run()"]

[language_server.racket-language-server]
filetypes = ["racket"]
roots = ["info.rkt"]
command = "racket"
args = ["-l", "racket-langserver"]

[language_server.reason-ocamllsp]
filetypes = ["reason"]
roots = ["package.json", "Makefile", ".git", ".hg"]
command = "ocamllsp"

# [language_server.rls]
# filetypes = ["rust"]
# roots = ["Cargo.toml"]
# command = "sh"
# args = [
#     "-c",
#     """
#         if path=$(rustup which rls 2>/dev/null); then
#             exec "$path"
#         else
#             exec rls
#         fi
#     """,
# ]
# settings_section = "rust"
# [language_server.rls.settings.rust]
# # See https://github.com/rust-lang/rls#configuration
# # features = []


[language_server.rust-analyzer]
filetypes = ["rust"]
roots = ["Cargo.toml"]
command = "sh"
args = [
    "-c",
    """
        if path=$(rustup which rust-analyzer 2>/dev/null); then
            exec "$path"
        else
            exec rust-analyzer
        fi
    """,
]
[language_server.rust-analyzer.settings.rust-analyzer]
# See https://rust-analyzer.github.io/manual.html#configuration
# cargo.features = []
check.command = "clippy"

[language_server.solargraph]
filetypes = ["ruby"]
roots = ["Gemfile"]
command = "solargraph"
args = ["stdio"]
settings_section = "_"
[language_server.solargraph.settings._]
# See https://github.com/castwide/solargraph/blob/master/lib/solargraph/language_server/host.rb
# diagnostics = false

[language_server.svelte-language-server]
filetypes = ["svelte"]
roots = ["package.json", "tsconfig.json", "jsconfig.json", ".git", ".hg"]
command = "svelteserver"
args = ["--stdio"]

[language_server.taplo]
filetypes = ["toml"]
roots = [".git", ".hg"]
command = "taplo"
args = ["lsp", "stdio"]

[language_server.terraform-ls]
filetypes = ["terraform"]
roots = ["*.tf"]
command = "terraform-ls"
args = ["serve"]
[language_server.terraform-ls.settings.terraform-ls]
# See https://github.com/hashicorp/terraform-ls/blob/main/docs/SETTINGS.md
# rootModulePaths = []

[language_server.texlab]
filetypes = ["latex"]
roots = [".git", ".hg"]
command = "texlab"
[language_server.texlab.settings.texlab]
# See https://github.com/latex-lsp/texlab/wiki/Configuration
#
# Preview configuration for zathura with SyncTeX search.
# For other PDF viewers see https://github.com/latex-lsp/texlab/wiki/Previewing
forwardSearch.executable = "zathura"
forwardSearch.args = [
    "%p",
    "--synctex-forward", # Support texlab-forward-search
    "%l:1:%f",
    "--synctex-editor-command", # Inverse search: use Control+Left-Mouse-Button to jump to source.
    """
        sh -c '
            echo "
                evaluate-commands -client %%opt{texlab_client} %%{
                    evaluate-commands -try-client %%opt{jumpclient} %%{
                        edit -- %%{input} %%{line}
                    }
                }
            " | kak -p $kak_session
        '
    """,
]

[language_server.typescript-language-server]
filetypes = ["javascript", "typescript"]
roots = ["package.json", "tsconfig.json", "jsconfig.json", ".git", ".hg"]
command = "typescript-language-server"
args = ["--stdio"]
settings_section = "_"
[language_server.typescript-language-server.settings._]
# quotePreference = "double"
# typescript.format.semicolons = "insert"

# [language_server.biome]
# filetypes = ["typescript", "javascript"]
# roots = ["biome.json", "package.json", "tsconfig.json", "jsconfig.json", ".git", ".hg"]
# command = "biome"
# args = ["lsp-proxy"]

# [language_server.eslint]
# filetypes = ["javascript", "typescript"]
# roots = [".eslintrc", ".eslintrc.json"]
# command = "eslint-language-server"
# args = ["--stdio"]
# workaround_eslint = true
# [language_server.eslint.settings]
# codeActionsOnSave = { mode = "all", "source.fixAll.eslint" = true }
# format = { enable = true }
# quiet = false
# rulesCustomizations = []
# run = "onType"
# validate = "on"
# experimental = {}
# problems = { shortenToSingleLine = false }
# codeAction.disableRuleComment = { enable = true, location = "separateLine" }
# codeAction.showDocumentation = { enable = false }

[language_server.yaml-language-server]
filetypes = ["yaml"]
roots = [".git", ".hg"]
command = "yaml-language-server"
args = ["--stdio"]
settings_section = "yaml"
[language_server.yaml-language-server.settings.yaml]
# See https://github.com/redhat-developer/yaml-language-server#language-server-settings
# Defaults are at https://github.com/redhat-developer/yaml-language-server/blob/master/src/yamlSettings.ts
# format.enable = true

[language_server.zls]
filetypes = ["zig"]
roots = ["build.zig"]
command = "zls"

# Semantic tokens support
# See https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_semanticTokens
# for the default list of tokens and modifiers.
# However, many language servers implement their own values.
# Make sure to check the output of `lsp-capabilities` and each server's documentation and source code as well.
# Examples:
# - TypeScript: https://github.com/microsoft/vscode-languageserver-node/blob/main/client/src/common/semanticTokens.ts
# - Rust Analyzer: https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide/src/syntax_highlighting.rs
[semantic_tokens]
faces = [
    {face="documentation", token="comment", modifiers=["documentation"]},
    {face="comment", token="comment"},
    {face="function", token="function"},
    {face="keyword", token="keyword"},
    {face="module", token="namespace"},
    {face="operator", token="operator"},
    {face="string", token="string"},
    {face="type", token="type"},
    {face="default+d", token="variable", modifiers=["readonly"]},
    {face="default+d", token="variable", modifiers=["constant"]},
    {face="variable", token="variable"},
]

