add vlang, update files

This commit is contained in:
RingOfStorms (Josh) 2024-05-14 10:01:47 -05:00
parent c8471e745f
commit aa687d7909
6 changed files with 194 additions and 155 deletions

View file

@ -39,6 +39,12 @@
"aarch64-darwin" "aarch64-darwin"
] ]
); );
systemToVAnalyzer = {
"x86_64-linux" = " v-analyzer-linux-x86_64.zip ";
"x86_64-darwin" = "v-analyzer-darwin-x86_64.zip ";
"aarch64-darwin" = "v-analyzer-darwin-arm64.zip ";
};
in in
# Takes all top level attributes and changes them to `attribute.${system} = old value` # Takes all top level attributes and changes them to `attribute.${system} = old value`
withSystem ( withSystem (
@ -48,6 +54,27 @@
overlays = [ (import inputs.rust-overlay) ]; overlays = [ (import inputs.rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; }; pkgs = import nixpkgs { inherit system overlays; };
# v_analyzer = pkgs.stdenv.mkDerivation rec {
# pname = "v_analyzer";
# version = "0.0.3-beta.1";
# src = pkgs.fetchgit {
# url = "https://github.com/v-analyzer/v-analyzer.git";
# rev = version;
# sha256 = "sha256-aZsStI/1/2CrMoRXrTRdNDRoBH/mA1FqC47tghSkCMo=";
# };
# buildInputs = with pkgs; [ vlang ];
# buildPhase = ''
# v install
# v build.vsh release
# '';
# installPhase = ''
# mkdir -p $out/bin
# cp -r ./bin/* $out/bin
# '';
# };
# Plugins provided in nixpkgs, match the naming scheme above for keys # Plugins provided in nixpkgs, match the naming scheme above for keys
lazyPath = pkgs.vimPlugins.lazy-nvim; lazyPath = pkgs.vimPlugins.lazy-nvim;
nixPkgsPlugins = with pkgs.vimPlugins; { nixPkgsPlugins = with pkgs.vimPlugins; {
@ -140,6 +167,7 @@
# LSPs # LSPs
nil # nix nil # nix
lua-language-server lua-language-server
# v_analyzer
vscode-langservers-extracted # HTML/CSS/JSON/ESLint vscode-langservers-extracted # HTML/CSS/JSON/ESLint
nodePackages.typescript-language-server nodePackages.typescript-language-server
tailwindcss-language-server tailwindcss-language-server
@ -154,8 +182,7 @@
nodejs_20 nodejs_20
clang clang
zig zig
(pkgs.rust-bin.stable.latest.default.override (pkgs.rust-bin.stable.latest.default.override {
{
extensions = [ extensions = [
"rust-src" "rust-src"
"rust-analyzer" "rust-analyzer"
@ -208,6 +235,8 @@
''export XDG_STATE_HOME="$NVIM_FLAKE_BASE_DIR/nvim_ringofstorms_${version}/state"'' ''export XDG_STATE_HOME="$NVIM_FLAKE_BASE_DIR/nvim_ringofstorms_${version}/state"''
"--run" "--run"
''export XDG_CACHE_HOME="$NVIM_FLAKE_BASE_DIR/nvim_ringofstorms_${version}/cache"'' ''export XDG_CACHE_HOME="$NVIM_FLAKE_BASE_DIR/nvim_ringofstorms_${version}/cache"''
"--run"
''export TESTASDASD="${lib.concatStringsSep "|" (lib.attrValues pkgs.vimPlugins.nvim-treesitter.grammarPlugins)}"''
]; ];
}); });
}; };

View file

@ -6,31 +6,35 @@ vim.api.nvim_create_autocmd("TextYankPost", {
group = group, group = group,
desc = "Highlight when yanking (copying) text", desc = "Highlight when yanking (copying) text",
callback = function() callback = function()
vim.highlight.on_yank({ timeout = 300 }) vim.highlight.on_yank({ timeout = 200 })
end, end,
}) })
-- TODO is there a better way for these? vim.filetype.add({
-- https://www.youtube.com/watch?v=NecszftvMFI vim.filetype.add pattern = {
vim.api.nvim_create_autocmd("BufRead", { [".*env*"] = "sh",
group = group, [".*rc"] = "sh",
pattern = ".env*", },
command = "set filetype=sh",
}) })
vim.api.nvim_create_autocmd("BufRead", { vim.filetype.add({
group = group, pattern = {
pattern = ".*rc", ["Dockerfile.*"] = "dockerfile",
command = "set filetype=sh", },
}) })
vim.api.nvim_create_autocmd("BufRead", { vim.filetype.add({
group = group, extension = {
pattern = "Dockerfile.*", http = "http",
command = "set filetype=dockerfile", },
}) })
vim.api.nvim_create_autocmd("BufRead", { vim.filetype.add({
group = group, extension = {
pattern = "*.http", v = "vlang",
command = "set filetype=http", vsh = "vlang",
vv = "vlang",
},
filename = {
["v.mod"] = "vlang",
},
}) })
-- Auto exit insert mode whenever we switch screens -- Auto exit insert mode whenever we switch screens
@ -66,11 +70,7 @@ vim.api.nvim_create_autocmd({ "InsertLeave", "TextChanged", "TextChangedI", "Buf
local modifiable = vim.api.nvim_buf_get_option(event.buf, "modifiable") local modifiable = vim.api.nvim_buf_get_option(event.buf, "modifiable")
local filetype = vim.api.nvim_buf_get_option(event.buf, "filetype") local filetype = vim.api.nvim_buf_get_option(event.buf, "filetype")
local modified = vim.api.nvim_buf_get_option(event.buf, "modified") local modified = vim.api.nvim_buf_get_option(event.buf, "modified")
if if modifiable and modified and U.table_not_contains(auto_save_disallowed_filetypes, filetype) then
modifiable
and modified
and U.table_not_contains(auto_save_disallowed_filetypes, filetype)
then
if auto_save_debounce[event.buf] ~= 1 then if auto_save_debounce[event.buf] ~= 1 then
auto_save_debounce[event.buf] = 1 auto_save_debounce[event.buf] = 1
vim.defer_fn(function() vim.defer_fn(function()

View file

@ -85,3 +85,5 @@ vim.opt.equalalways = false
-- enable colors for opacity changes -- enable colors for opacity changes
vim.opt.termguicolors = true vim.opt.termguicolors = true

View file

@ -20,10 +20,17 @@ return {
opts = { opts = {
-- https://github.com/stevearc/conform.nvim?tab=readme-ov-file#setup -- https://github.com/stevearc/conform.nvim?tab=readme-ov-file#setup
notify_on_error = true, notify_on_error = true,
formatters = {
v_fmt = {
command = "v",
args = { "fmt" },
},
},
-- Note that all these need to be available at runtime, add them to flake.nix#runtimeDependencies -- Note that all these need to be available at runtime, add them to flake.nix#runtimeDependencies
formatters_by_ft = { formatters_by_ft = {
lua = { "stylua" }, lua = { "stylua" },
nix = { "nixfmt" }, nix = { "nixfmt" },
vlang = { "v_fmt" },
typescript = { { "prettierd", "prettier" }, "rustywind" }, typescript = { { "prettierd", "prettier" }, "rustywind" },
typescriptreact = { { "prettierd", "prettier" }, "rustywind" }, typescriptreact = { { "prettierd", "prettier" }, "rustywind" },
javascript = { { "prettierd", "prettier" }, "rustywind" }, javascript = { { "prettierd", "prettier" }, "rustywind" },

View file

@ -1,139 +1,140 @@
-- Stolen from LazyVim https://github.com/LazyVim/LazyVim/tree/f086bcde253c29be9a2b9c90b413a516f5d5a3b2/lua/lazyvim/plugins -- Stolen from LazyVim https://github.com/LazyVim/LazyVim/tree/f086bcde253c29be9a2b9c90b413a516f5d5a3b2/lua/lazyvim/plugins
return { return {
"mfussenegger/nvim-lint", "mfussenegger/nvim-lint",
event = { "VeryLazy", "BufWritePost", "BufReadPost", "InsertLeave" }, event = { "VeryLazy", "BufWritePost", "BufReadPost", "InsertLeave" },
opts = { opts = {
-- Event to trigger linters -- Event to trigger linters
events = { "BufWritePost", "BufReadPost", "InsertLeave", "CursorHold", "CursorHoldI" }, events = { "BufWritePost", "BufReadPost", "InsertLeave", "CursorHold", "CursorHoldI" },
linters_by_ft = { linters_by_ft = {
-- Builtin: https://github.com/mfussenegger/nvim-lint/tree/master/lua/lint/linters -- Builtin: https://github.com/mfussenegger/nvim-lint/tree/master/lua/lint/linters
markdown = { "markdownlint" }, markdown = { "markdownlint" },
lua = { "luacheck" }, lua = { "luacheck" },
typescript = { "biomejs" }, typescript = { "biomejs" },
typescriptreact = { "biomejs" }, typescriptreact = { "biomejs" },
javascript = { "biomejs" }, javascript = { "biomejs" },
javascriptreact = { "biomejs" }, javascriptreact = { "biomejs" },
-- Use the "*" filetype to run linters on all filetypes. -- Use the "*" filetype to run linters on all filetypes.
-- ['*'] = { 'global linter' }, -- ['*'] = { 'global linter' },
-- Use the "_" filetype to run linters on filetypes that don't have other linters configured. -- Use the "_" filetype to run linters on filetypes that don't have other linters configured.
-- ['_'] = { 'fallback linter' }, -- ['_'] = { 'fallback linter' },
-- ["*"] = { "typos" }, -- ["*"] = { "typos" },
}, },
-- LazyVim extension to easily override linter options -- LazyVim extension to easily override linter options
-- or add custom linters. -- or add custom linters.
---@type table<string,table> ---@type table<string,table>
-- --
-- Options: -- Options:
-- cmd = 'linter_cmd', -- cmd = 'linter_cmd',
-- stdin = true, -- or false if it doesn't support content input via stdin. In that case the filename is automatically added to the arguments. -- stdin = true, -- or false if it doesn't support content input via stdin. In that case the filename is automatically added to the arguments.
-- append_fname = true, -- Automatically append the file name to `args` if `stdin = false` (default: true) -- append_fname = true, -- Automatically append the file name to `args` if `stdin = false` (default: true)
-- args = {}, -- list of arguments. Can contain functions with zero arguments that will be evaluated once the linter is used. -- args = {}, -- list of arguments. Can contain functions with zero arguments that will be evaluated once the linter is used.
-- stream = nil, -- ('stdout' | 'stderr' | 'both') configure the stream to which the linter outputs the linting result. -- stream = nil, -- ('stdout' | 'stderr' | 'both') configure the stream to which the linter outputs the linting result.
-- ignore_exitcode = false, -- set this to true if the linter exits with a code != 0 and that's considered normal. -- ignore_exitcode = false, -- set this to true if the linter exits with a code != 0 and that's considered normal.
-- env = nil, -- custom environment table to use with the external process. Note that this replaces the *entire* environment, it is not additive. -- env = nil, -- custom environment table to use with the external process. Note that this replaces the *entire* environment, it is not additive.
-- parser = your_parse_function -- parser = your_parse_function
-- --
-- your_parse_function can be a function which takes three arguments: -- your_parse_function can be a function which takes three arguments:
-- output -- output
-- bufnr -- bufnr
-- linter_cwd -- linter_cwd
-- The output is the output generated by the linter command. The function must return a list of diagnostics as specified in :help diagnostic-structure. -- The output is the output generated by the linter command. The function must return a list of diagnostics as specified in :help diagnostic-structure.
linters = { linters = {
luacheck = { luacheck = {
args = { args = {
"--globals", "--globals",
"vim", "vim",
"--globals", "--globals",
"NIX", "NIX",
"--globals", "--globals",
"U", "U",
"--max_line_length", "--max_line_length",
"240", "240",
"--max_code_line_length", "--max_code_line_length",
"240", "240",
"--max_string_line_length", "--max_string_line_length",
"240", "240",
"--max_comment_line_length", "--max_comment_line_length",
"240", "240",
"--formatter", "--formatter",
"plain", "plain",
"--codes", "--codes",
"--ranges", "--ranges",
"-", "-",
}, },
}, },
-- -- Example of using selene only when a selene.toml file is present -- TODO add v vet? for v-lang?
-- selene = { -- -- Example of using selene only when a selene.toml file is present
-- -- `condition` is another LazyVim extension that allows you to -- selene = {
-- -- dynamically enable/disable linters based on the context. -- -- `condition` is another LazyVim extension that allows you to
-- condition = function(ctx) -- -- dynamically enable/disable linters based on the context.
-- return vim.fs.find({ "selene.toml" }, { path = ctx.filename, upward = true })[1] -- condition = function(ctx)
-- end, -- return vim.fs.find({ "selene.toml" }, { path = ctx.filename, upward = true })[1]
-- }, -- end,
}, -- },
}, },
config = function(_, opts) },
local M = {} config = function(_, opts)
local M = {}
local lint = require("lint") local lint = require("lint")
for name, linter in pairs(opts.linters) do for name, linter in pairs(opts.linters) do
if type(linter) == "table" and type(lint.linters[name]) == "table" then if type(linter) == "table" and type(lint.linters[name]) == "table" then
lint.linters[name] = vim.tbl_deep_extend("force", lint.linters[name], linter) lint.linters[name] = vim.tbl_deep_extend("force", lint.linters[name], linter)
else else
lint.linters[name] = linter lint.linters[name] = linter
end end
end end
lint.linters_by_ft = opts.linters_by_ft lint.linters_by_ft = opts.linters_by_ft
function M.debounce(ms, fn) function M.debounce(ms, fn)
local timer = vim.uv.new_timer() local timer = vim.uv.new_timer()
return function(...) return function(...)
local argv = { ... } local argv = { ... }
timer:start(ms, 0, function() timer:start(ms, 0, function()
timer:stop() timer:stop()
vim.schedule_wrap(fn)(unpack(argv)) vim.schedule_wrap(fn)(unpack(argv))
end) end)
end end
end end
function M.lint() function M.lint()
-- Use nvim-lint's logic first: -- Use nvim-lint's logic first:
-- * checks if linters exist for the full filetype first -- * checks if linters exist for the full filetype first
-- * otherwise will split filetype by "." and add all those linters -- * otherwise will split filetype by "." and add all those linters
-- * this differs from conform.nvim which only uses the first filetype that has a formatter -- * this differs from conform.nvim which only uses the first filetype that has a formatter
local names = lint._resolve_linter_by_ft(vim.bo.filetype) local names = lint._resolve_linter_by_ft(vim.bo.filetype)
-- Create a copy of the names table to avoid modifying the original. -- Create a copy of the names table to avoid modifying the original.
names = vim.list_extend({}, names) names = vim.list_extend({}, names)
-- Add fallback linters. -- Add fallback linters.
if #names == 0 then if #names == 0 then
vim.list_extend(names, lint.linters_by_ft["_"] or {}) vim.list_extend(names, lint.linters_by_ft["_"] or {})
end end
-- Add global linters. -- Add global linters.
vim.list_extend(names, lint.linters_by_ft["*"] or {}) vim.list_extend(names, lint.linters_by_ft["*"] or {})
-- Filter out linters that don't exist or don't match the condition. -- Filter out linters that don't exist or don't match the condition.
local ctx = { filename = vim.api.nvim_buf_get_name(0) } local ctx = { filename = vim.api.nvim_buf_get_name(0) }
ctx.dirname = vim.fn.fnamemodify(ctx.filename, ":h") ctx.dirname = vim.fn.fnamemodify(ctx.filename, ":h")
names = vim.tbl_filter(function(name) names = vim.tbl_filter(function(name)
local linter = lint.linters[name] local linter = lint.linters[name]
if not linter then if not linter then
LazyVim.warn("Linter not found: " .. name, { title = "nvim-lint" }) LazyVim.warn("Linter not found: " .. name, { title = "nvim-lint" })
end end
return linter and not (type(linter) == "table" and linter.condition and not linter.condition(ctx)) return linter and not (type(linter) == "table" and linter.condition and not linter.condition(ctx))
end, names) end, names)
-- Run linters. -- Run linters.
if #names > 0 then if #names > 0 then
lint.try_lint(names) lint.try_lint(names)
end end
end end
vim.api.nvim_create_autocmd(opts.events, { vim.api.nvim_create_autocmd(opts.events, {
group = vim.api.nvim_create_augroup("nvim-lint", { clear = true }), group = vim.api.nvim_create_augroup("nvim-lint", { clear = true }),
callback = M.debounce(100, M.lint), callback = M.debounce(100, M.lint),
}) })
end, end,
} }

View file

@ -107,6 +107,7 @@ return {
}, },
}, },
nil_ls = {}, nil_ls = {},
v_analyzer = { filetypes = { "vlang", "v", "vsh", "vv" } },
tsserver = { tsserver = {
-- typescript/javascript -- typescript/javascript
implicitProjectConfiguration = { implicitProjectConfiguration = {
@ -153,7 +154,7 @@ return {
require("lspconfig")[server_name].setup(server_opts) require("lspconfig")[server_name].setup(server_opts)
end end
else else
-- TODO test this out on a non nix setup... -- TODO test this out on a non nix setup...
require("mason").setup() require("mason").setup()
local ensure_installed = vim.tbl_keys(servers or {}) local ensure_installed = vim.tbl_keys(servers or {})
vim.list_extend(ensure_installed, { vim.list_extend(ensure_installed, {
@ -174,4 +175,3 @@ return {
end, end,
}, },
} }