-- Check Lspconfig.
-- local status_lspconfig, lspconfig = pcall(require, 'lspconfig')
-- if (not status_lspconfig) then return end

-- Check Mason.
local status_mason, mason = pcall(require, 'mason')
if (not status_mason) then return end

-- Check Mason lsp installer.
local status_mason_lspconfig, mason_lspconfig = pcall(require, 'mason-lspconfig')
if (not status_mason_lspconfig) then return end

-- Config servers.
local servers = {
	'ts_ls',
	'lua_ls',
	'bashls',
	'cmake',
	'html',
	'dockerls',
	'jsonls',
	'yamlls',
	'graphql'
}

vim.lsp.config('lua_ls', {
	settings = {
		Lua = {
			runtime = {
				version = 'LuaJIT',
			},
			diagnostics = {
				globals = {
					'vim',
					'require',
				},
			},
		},
	}
})

vim.lsp.config('ts_ls', {
	init_options = {
		plugins = {
			{
				name = '@vue/typescript-plugin',
				location = '/home/antoxa/.nvm/versions/node/v22.12.0/lib/node_modules/@vue/typescript-plugin',
				languages = { 'vue' }
			}
		}
	},
	settings = {
		typescript = {
			tsserver = {
				useSyntaxServer = false,
			},
			inlayHints = {
				includeInlayParameterNameHints = 'all',
				includeInlayParameterNameHintsWhenArgumentMatchesName = true,
				includeInlayFunctionParameterTypeHints = true,
				includeInlayVariableTypeHints = true,
				includeInlayVariableTypeHintsWhenTypeMatchesName = true,
				includeInlayPropertyDeclarationTypeHints = true,
				includeInlayFunctionLikeReturnTypeHints = true,
				includeInlayEnumMemberValueHints = true,
			},
		},
	},
	filetypes = { 'javascript', 'typescript', 'vue' }
})

-- Mason.
mason.setup {}

-- Mason lsp installer.
mason_lspconfig.setup {
	ensure_installed = servers,
	automatic_enable = true
}
