POC: formatted Lua configuration

This commit is contained in:
NotAShelf 2024-04-21 04:57:42 +03:00
parent 72a5e6c684
commit 8d716135af
No known key found for this signature in database
GPG key ID: 02D1DD3FA08B6B29
3 changed files with 30 additions and 9 deletions

View file

@ -39,7 +39,6 @@ in {
(mkIf cfg.lsp.enable { (mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true; vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.dart-lsp = servers.${cfg.lsp.server}.lspConfig; vim.lsp.lspconfig.sources.dart-lsp = servers.${cfg.lsp.server}.lspConfig;
}) })
@ -52,12 +51,12 @@ in {
vim.luaConfigRC.flutter-tools = entryAnywhere '' vim.luaConfigRC.flutter-tools = entryAnywhere ''
require('flutter-tools').setup { require('flutter-tools').setup {
lsp = { lsp = {
color = { -- show the derived colours for dart variables color = {
enabled = ${boolToString ftcfg.color.enable}, -- whether or not to highlight color variables at all, only supported on flutter >= 2.10 enabled = ${boolToString ftcfg.color.enable},
background = ${boolToString ftcfg.color.highlightBackground}, -- highlight the background background = ${boolToString ftcfg.color.highlightBackground},
foreground = ${boolToString ftcfg.color.highlightForeground}, -- highlight the foreground foreground = ${boolToString ftcfg.color.highlightForeground},
virtual_text = ${boolToString ftcfg.color.virtualText.enable}, -- show the highlight using virtual text virtual_text = ${boolToString ftcfg.color.virtualText.enable},
virtual_text_str = ${ftcfg.color.virtualText.character} -- the virtual text character to highlight virtual_text_str = ${toString ftcfg.color.virtualText.character}
}, },
capabilities = capabilities, capabilities = capabilities,

View file

@ -105,7 +105,7 @@ in {
character = mkOption { character = mkOption {
type = str; type = str;
default = ""; default = "...";
description = "Virtual text character to highlight"; description = "Virtual text character to highlight";
}; };
}; };

View file

@ -1,5 +1,6 @@
{ {
config, config,
pkgs,
lib, lib,
... ...
}: let }: let
@ -128,6 +129,24 @@ in {
else abort ("Dependency cycle in ${name}: " + toJSON sortedDag); else abort ("Dependency cycle in ${name}: " + toJSON sortedDag);
in in
result; result;
formatLua = {
name,
contents,
...
}:
pkgs.runCommand name {inherit contents;} ''
touch $out
echo -n "$text" > "$out"
${pkgs.stylua}/bin/stylua \
--column-width 80 \
--no-editorconfig \
--indent-type Spaces \
--indent-width 4 \
--collapse-simple-statement Never \
"$out"
'';
in { in {
vim = { vim = {
configRC = { configRC = {
@ -138,8 +157,11 @@ in {
luaScript = let luaScript = let
mapResult = result: (wrapLuaConfig { mapResult = result: (wrapLuaConfig {
luaBefore = "${cfg.luaConfigPre}"; luaBefore = "${cfg.luaConfigPre}";
luaConfig = concatStringsSep "\n" (map mkLuarcSection result);
luaAfter = "${cfg.luaConfigPost}"; luaAfter = "${cfg.luaConfigPost}";
luaConfig = formatLua {
name = "lua";
contents = concatStringsSep "\n" (map mkLuarcSection result);
};
}); });
luaConfig = resolveDag { luaConfig = resolveDag {