repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

neovim/lsp/lua_ls.lua

Raw
local project = require 'std.project'
local normalize = vim.fs.normalize
local realpath = vim.uv.fs_realpath

return {
	cmd = { 'lua-language-server' },
	filetypes = { 'lua' },
	root_dir = function ( _, set_root_dir )
		local root = project.find_lua_project_root()
		if not root then return end
		set_root_dir( root )
	end,
	settings = {
		Lua = {
			hint = { enable = true, setType = true },
		},
	},
	on_init = function ( client )
		if client.workspace_folders then
			local root = client.workspace_folders[1].name
			local abs_root = assert( realpath( root ) )
			local path = normalize( abs_root )
			local abs_config = assert( realpath( vim.fn.stdpath 'config' ) )
			local config_path = normalize( abs_config )
			if path ~= config_path then
				return
			end
		end

		client.config.settings.Lua = vim.tbl_deep_extend( 'force', client.config.settings.Lua, {
			runtime = {
				version = 'LuaJIT',
				path = {
					'lua/?.lua',
					'lua/?/init.lua',
				},
			},
			diagnostics = {
				globals = {
					'vim',
					'describe',
					'it',
				},
			},
			workspace = {
				checkThirdParty = false,
				library = {
					vim.env.VIMRUNTIME,
					'${3rd}/luv/library',
				},
			},
		} )
	end,
}