TreeSitter for c-sharp in nvim

This commit is contained in:
Jeremy Wall 2023-08-22 17:53:41 -04:00
parent 6f7d202eeb
commit 9364b5c328
4 changed files with 90 additions and 26 deletions

View File

@ -27,7 +27,27 @@
sile = sile-flake.defaultPackage.${system};
jj = jj-flake.packages."${system}".jujutsu;
age = agenix-flake.packages."${system}".default;
in { config, pkgs, ... }: {
in { config, pkgs, ... }: let
nvim-treesitter-csharp = pkgs.callPackage ./nvim-treesitter-csharp.nix {
buildGrammar = pkgs.tree-sitter.buildGrammar;
fetchFromGitHub = pkgs.fetchFromGitHub;
};
expected-parsers = (pkgs.lib.attrVals [
"tree-sitter-rust"
"tree-sitter-lua"
"tree-sitter-toml"
"tree-sitter-yaml"
"tree-sitter-json"
#"tree-sitter-ini"
"tree-sitter-html"
"tree-sitter-css"
"tree-sitter-nix"
"tree-sitter-latex"
"tree-sitter-ocaml"
"tree-sitter-tlaplus"
"tree-sitter-julia"
] pkgs.tree-sitter.builtGrammars) ++ [nvim-treesitter-csharp];
in {
imports = [
agenix-flake.nixosModules.default
@ -69,7 +89,9 @@ EOF";
vimspector
vimagit
hoon-vim
nvim-treesitter
(nvim-treesitter.withPlugins (_: expected-parsers))
nvim-treesitter-context
nvim-treesitter-parsers.ini
omnisharp-extended-lsp-nvim
#neotest-dotnet
nix-develop-nvim
@ -80,21 +102,7 @@ EOF";
telescope-nvim
telescope-lsp-handlers-nvim
plenary-nvim
] ++ (with nvim-treesitter-parsers; [
rust
lua
toml
yaml
json
ini
html
css
nix
latex
ocaml
tlaplus
julia
]);
];
};
};

View File

@ -6,7 +6,7 @@ vim.cmd.colorscheme 'duskfox'
-- turn on relative line numbers
vim.opt.relativenumber = true
vim.opt.number = true
vim.o.expandtab = false
vim.o.expandtab = true
vim.o.paste = false
vim.o.autoindent = true
vim.o.linebreak = true
@ -62,8 +62,8 @@ lspconfig.nil_ls.setup{{
local vim_pid = vim.fn.getpid()
-- "FormatterOptions:EnableEditorConfigSupport=true"
local omnisharp_cmd = { tostring(vim.env.OMNISHARP_BIN), '--languageserver', '--hostPID', tostring(vim_pid), }
-- This needs a path to the omnisharp dll provided. We depend on the OMNISHARP_BIN environment variable being set to make this work.
local omnisharp_cmd = { 'omnisharp', '--languageserver', '-v', '--hostPID', tostring(vim_pid), }
lspconfig.omnisharp.setup {
cmd = omnisharp_cmd,
enable_roslyn_analyzers = true,
@ -76,7 +76,6 @@ lspconfig.omnisharp.setup {
handlers = {
["textDocument/definition"] = require('omnisharp_extended').handler,
},
-- TODO(jwall): See if init_options can assist in getting our lint setting correct.
}
--ocaml
@ -106,10 +105,17 @@ vim.api.nvim_create_autocmd('LspAttach', {
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
vim.keymap.set("n", "<Leader>f", vim.lsp.buf.format, opts)
-- We use F2 to rename things
vim.keymap.set("n", "<F2>", vim.lsp.buf.rename, opts)
end,
})
vim.api.nvim_create_autocmd({'LspAttach', 'BufEnter', 'InsertLeave', 'CursorHold'}, {
callback = function(ev)
if vim.lsp.buf.server_ready() then
vim.lsp.codelens.refresh()
end
end,
})
-- LSP Diagnostics Options Setup
local sign = function(opts)
vim.fn.sign_define(opts.name, {
@ -180,7 +186,46 @@ require('nvim-treesitter.configs').setup {
enable = true,
extended_mode = true,
max_file_lines = nil,
}
},
textobjects = {
select = {
enable = true,
lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
keymaps = {
-- You can use the capture groups defined in textobjects.scm
['aa'] = '@parameter.outer',
['ia'] = '@parameter.inner',
['af'] = '@function.outer',
['if'] = '@function.inner',
['ac'] = '@class.outer',
['ic'] = '@class.inner',
},
},
},
--incremental_selection = {
-- enable = true,
-- keymaps = {
-- init_selection = '<Leader>c',
-- node_incremental = '<Leader>c',
-- scope_incremental = '<Leader>ci',
-- node_decremental = '<Leader>cx',
-- },
--},
}
require'treesitter-context'.setup {
enable = true, -- Enable this plugin (Can be enabled/disabled later via commands)
max_lines = 0, -- How many lines the window should span. Values <= 0 mean no limit.
min_window_height = 0, -- Minimum editor window height to enable context. Values <= 0 mean no limit.
line_numbers = true,
multiline_threshold = 20, -- Maximum number of lines to collapse for a single context line
trim_scope = 'outer', -- Which context lines to discard if `max_lines` is exceeded. Choices: 'inner', 'outer'
mode = 'cursor', -- Line used to calculate context. Choices: 'cursor', 'topline'
-- Separator between context and content. Should be a single character string, like '-'.
-- When separator is set, the context will only show up when there are at least 2 lines above cursorline.
separator = nil,
zindex = 20, -- The Z-index of the context window
on_attach = nil, -- (fun(buf: integer): boolean) return false to disable attaching
}
vim.g.loaded_netrw = 1

View File

@ -0,0 +1,11 @@
{ buildGrammar, fetchFromGitHub, pkgs, }:
buildGrammar {
language = "c-sharp";
version = "0.20.0-master";
src = fetchFromGitHub {
owner = "tree-sitter";
repo = "tree-sitter-c-sharp";
rev = "1648e21b4f087963abf0101ee5221bb413107b07";
hash = "sha256-WvkHtw8t14UNqiJvmS9dbGYQSVVzHS9mcWzxq+KLMnU=";#pkgs.lib.fakeHash;
};
}

6
nix/darwin/flake.lock generated
View File

@ -34,12 +34,12 @@
},
"locked": {
"lastModified": 1,
"narHash": "sha256-RUsYDEHzM9vCyjCifvicGOS/Bnj/vFPFz7WVdjId6U0=",
"path": "/nix/store/zpffamlg727zid5pkx7vs1ca7q07vkgk-source/nix/base-system",
"narHash": "sha256-LdDXr6idLkkTeHwlq0ZA7kri4HMr124xABHowvooD/c=",
"path": "/nix/store/hhwybysgssx8f4ivff8yhagm6iyqgis9-source/nix/base-system",
"type": "path"
},
"original": {
"path": "/nix/store/zpffamlg727zid5pkx7vs1ca7q07vkgk-source/nix/base-system",
"path": "/nix/store/hhwybysgssx8f4ivff8yhagm6iyqgis9-source/nix/base-system",
"type": "path"
}
},