aboutsummaryrefslogtreecommitdiffstats
path: root/lsp/astro.lua
blob: c9fc4c1c7bc911993fe447083bd33c9758c5d365 (plain) (blame)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
---@brief
---
--- https://github.com/withastro/language-tools/tree/main/packages/language-server
---
--- `astro-ls` can be installed via `npm`:
--- ```sh
--- npm install -g @astrojs/language-server
--- ```
---
--- If typescript is installed globally, you might get the `\`typescript.tsdk\` init option is required` error.
--- You will need to manually pass the typescript SDK path. Here is an example of a Nix configuration where typescript is installed via Nix's Home-manager:
---
--- ```nix
--- { config, pkgs, ... }:
---
--- {
---   home.packages = with pkgs; [
---     typescript
---   ];
---
---   programs.neovim = {
---     plugins = with pkgs.vimPlugins; [
---       nvim-lspconfig
---     ];
---     extraPackages = with pkgs; [
---       astro-language-server
---     ];
---     initLua = ''
---       vim.lsp.config['astro'] = {
---         init_options = {
---           typescript = {
---             tsdk = ${pkgs.typescript}/lib/node_modules/typescript/lib,
---           },
---         },
---       }
---
---       vim.lsp.enable('astro')
---
---       -- ...
---     '';
---   };
--- }
--- ```
--- The path can also be passed via a variable, like `vim.g.tsdk = "${pkgs.typescript}/lib/node_modules/typescript/lib"` and then used in the Lua Neovim config.

local util = require 'lspconfig.util'

---@type vim.lsp.Config
return {
  cmd = { 'astro-ls', '--stdio' },
  filetypes = { 'astro' },
  root_markers = { 'package.json', 'tsconfig.json', 'jsconfig.json', '.git' },
  init_options = {
    typescript = {},
  },
  before_init = function(_, config)
    if config.init_options and config.init_options.typescript and not config.init_options.typescript.tsdk then
      config.init_options.typescript.tsdk = util.get_typescript_server_path(config.root_dir)
    end
  end,
}