-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #200 from NotAShelf/css-and-tailwind
languages: add css and tailwind language support
- Loading branch information
Showing
5 changed files
with
157 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
config, | ||
pkgs, | ||
lib, | ||
... | ||
}: let | ||
inherit (builtins) attrNames; | ||
inherit (lib) mkEnableOption mkOption mkIf mkMerge isList types nvim; | ||
|
||
cfg = config.vim.languages.css; | ||
|
||
defaultServer = "vscode-langservers-extracted"; | ||
servers = { | ||
vscode-langservers-extracted = { | ||
package = pkgs.nodePackages.vscode-langservers-extracted; | ||
lspConfig = '' | ||
-- enable (broadcasting) snippet capability for completion | ||
-- see <https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#cssls> | ||
local css_capabilities = vim.lsp.protocol.make_client_capabilities() | ||
css_capabilities.textDocument.completion.completionItem.snippetSupport = true | ||
-- cssls setup | ||
lspconfig.cssls.setup { | ||
capabilities = css_capabilities; | ||
on_attach = default_on_attach; | ||
cmd = ${ | ||
if isList cfg.lsp.package | ||
then nvim.lua.expToLua cfg.lsp.package | ||
else ''{"${cfg.lsp.package}/bin/vscode-css-language-server", "--stdio"}'' | ||
} | ||
} | ||
''; | ||
}; | ||
}; | ||
in { | ||
options.vim.languages.css = { | ||
enable = mkEnableOption "CSS language support"; | ||
|
||
treesitter = { | ||
enable = mkEnableOption "CSS treesitter" // {default = config.vim.languages.enableTreesitter;}; | ||
|
||
package = nvim.types.mkGrammarOption pkgs "css"; | ||
}; | ||
|
||
lsp = { | ||
enable = mkEnableOption "CSS LSP support" // {default = config.vim.languages.enableLSP;}; | ||
|
||
server = mkOption { | ||
description = "CSS LSP server to use"; | ||
type = with types; enum (attrNames servers); | ||
default = defaultServer; | ||
}; | ||
|
||
package = mkOption { | ||
description = "CSS LSP server package, or the command to run as a list of strings"; | ||
example = ''[lib.getExe pkgs.jdt-language-server " - data " " ~/.cache/jdtls/workspace "]''; | ||
type = with types; either package (listOf str); | ||
default = servers.${cfg.lsp.server}.package; | ||
}; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable (mkMerge [ | ||
(mkIf cfg.treesitter.enable { | ||
vim.treesitter.enable = true; | ||
vim.treesitter.grammars = [cfg.treesitter.package]; | ||
}) | ||
|
||
(mkIf cfg.lsp.enable { | ||
vim.lsp.lspconfig.enable = true; | ||
vim.lsp.lspconfig.sources.tailwindcss-lsp = servers.${cfg.lsp.server}.lspConfig; | ||
}) | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
config, | ||
pkgs, | ||
lib, | ||
... | ||
}: let | ||
inherit (builtins) attrNames; | ||
inherit (lib) mkEnableOption mkOption mkIf mkMerge isList types nvim; | ||
|
||
cfg = config.vim.languages.tailwind; | ||
|
||
defaultServer = "tailwindcss-language-server"; | ||
servers = { | ||
tailwindcss-language-server = { | ||
package = pkgs.tailwindcss-language-server; | ||
lspConfig = '' | ||
lspconfig.tailwindcss.setup { | ||
capabilities = capabilities; | ||
on_attach = default_on_attach; | ||
cmd = ${ | ||
if isList cfg.lsp.package | ||
then nvim.lua.expToLua cfg.lsp.package | ||
else ''{"${cfg.lsp.package}/bin/tailwindcss-language-server", "--stdio"}'' | ||
} | ||
} | ||
''; | ||
}; | ||
}; | ||
in { | ||
options.vim.languages.tailwind = { | ||
enable = mkEnableOption "Tailwindcss language support"; | ||
|
||
lsp = { | ||
enable = mkEnableOption "Tailwindcss LSP support" // {default = config.vim.languages.enableLSP;}; | ||
|
||
server = mkOption { | ||
description = "Tailwindcss LSP server to use"; | ||
type = with types; enum (attrNames servers); | ||
default = defaultServer; | ||
}; | ||
|
||
package = mkOption { | ||
description = "Tailwindcss LSP server package, or the command to run as a list of strings"; | ||
example = ''[lib.getExe pkgs.jdt-language-server " - data " " ~/.cache/jdtls/workspace "]''; | ||
type = with types; either package (listOf str); | ||
default = servers.${cfg.lsp.server}.package; | ||
}; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable (mkMerge [ | ||
(mkIf cfg.lsp.enable { | ||
vim.lsp.lspconfig.enable = true; | ||
vim.lsp.lspconfig.sources.css-lsp = servers.${cfg.lsp.server}.lspConfig; | ||
}) | ||
]); | ||
} |