summaryrefslogtreecommitdiff
path: root/.config/nvim/ftplugin/kotlin.lua
blob: eb5f5f542e4a01964c4851fe930788a313679fef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
if require("cfg.utils").check_lsp_client_active "kotlin_language_server" then
  return
end

--- default config for gradle-projects of the
--- kotlin-language-server: https://github.com/fwcd/kotlin-language-server
---
--- This server requires vim to be aware of the kotlin-filetype.
--- You could refer for this capability to:
--- 	https://github.com/udalov/kotlin-vim (recommended)
--- 	Note that there is no LICENSE specified yet.

local util = require "lspconfig/util"

local bin_name = DATA_PATH .. "/lspinstall/kotlin/server/bin/kotlin-language-server"
if vim.fn.has "win32" == 1 then
  bin_name = bin_name .. ".bat"
end

local root_files = {
  "settings.gradle", -- Gradle (multi-project)
  "settings.gradle.kts", -- Gradle (multi-project)
  "build.xml", -- Ant
  "pom.xml", -- Maven
}

local fallback_root_files = {
  "build.gradle", -- Gradle
  "build.gradle.kts", -- Gradle
}

require("lspconfig").kotlin_language_server.setup {
  cmd = { bin_name },
  on_attach = require("cfg.lsp").common_on_attach,
  root_dir = function(fname)
    return util.root_pattern(unpack(root_files))(fname) or util.root_pattern(unpack(fallback_root_files))(fname)
  end,
}