-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathastro.lua
More file actions
70 lines (68 loc) · 2.05 KB
/
astro.lua
File metadata and controls
70 lines (68 loc) · 2.05 KB
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
62
63
64
65
66
67
68
69
70
---@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 = function(dispatchers, config)
local cmd = 'astro-ls'
if (config or {}).root_dir then
local local_cmd = vim.fs.joinpath(config.root_dir, 'node_modules/.bin', cmd)
if vim.fn.executable(local_cmd) == 1 then
cmd = local_cmd
end
end
return vim.lsp.rpc.start({ cmd, '--stdio' }, dispatchers)
end,
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,
}