Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: LSP and completion #4

Merged
merged 34 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
386fe94
feat: basic autocompletion with snippets and buffer
grzuy Mar 14, 2024
841eb92
feat: LSP, autocompletions, go-to definition and autoformat
grzuy Mar 14, 2024
f89d574
docs
grzuy Mar 14, 2024
96c82a3
avoids undefined vim global in neovim lua configs
grzuy Mar 15, 2024
c38952a
docs: improve
grzuy Mar 15, 2024
5092af6
rename for clarity
grzuy Mar 15, 2024
a999f14
only show LSP diagnostics after buf write / file save
grzuy Mar 15, 2024
2090456
disable diagnostics for now - still immature
grzuy Mar 15, 2024
afc1828
Merge branch 'main' into lsp
grzuy Mar 15, 2024
edda05b
leave snippets out for now
grzuy Mar 15, 2024
0059db9
K for hover
grzuy Mar 15, 2024
cd6ca30
configures lsp hover window
grzuy Mar 15, 2024
0a9f6a3
fix lock newline
grzuy Mar 15, 2024
d6ee4f0
Merge branch 'main' into lsp
grzuy Mar 18, 2024
49b26e0
Merge branch 'main' into lsp
grzuy Mar 18, 2024
4ebbde3
update plugins
grzuy Mar 18, 2024
877aa47
Merge branch 'main' into lsp
grzuy Mar 19, 2024
6820f90
perf: defer loading nvim-cmp
grzuy Mar 19, 2024
3c1e85c
Merge branch 'main' into lsp
grzuy Mar 20, 2024
a6f28a5
feat: enable low-noise LSP diagnostics
grzuy Mar 20, 2024
c843511
Merge branch 'main' into lsp
grzuy Mar 20, 2024
77fd583
more clear argument name
grzuy Mar 20, 2024
df7c05b
consistent style
grzuy Mar 20, 2024
35b4cc8
don't set lsp keymaps in buffer if lsp server not support that capabi…
grzuy Mar 20, 2024
4b6b0a2
disable distracting/noisy autocomplete, completion manually via <C-n>
grzuy Mar 20, 2024
47b4a93
completion and doc windows bordered and consistent for proper contrast
grzuy Mar 20, 2024
cf439c6
Merge branch 'main' into lsp
grzuy Mar 21, 2024
e69eee6
Merge branch 'main' into lsp
grzuy Mar 21, 2024
a5fa939
Merge branch 'main' into lsp
grzuy Mar 22, 2024
7088834
Merge branch 'main' into lsp
grzuy Mar 22, 2024
da2348b
docs: keymaps
grzuy Mar 22, 2024
9b92f09
docs update
grzuy Mar 22, 2024
6764465
desc
grzuy Mar 22, 2024
b51017a
Merge branch 'main' into lsp
grzuy Mar 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 39 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ virtual text.
### Main features

- Find, filter, preview files with [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim)
- Programming languages support with [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter)
- Syntax highlighting of any language with [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter)
- Autocompletions with [nvim-cmp](https://github.com/hrsh7th/nvim-cmp)
- LSP integration with [mason.nvim](https://github.com/williamboman/mason.nvim) and [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig)
- File explorer with [nvim-tree.lua](https://github.com/nvim-tree/nvim-tree.lua)
- Git integration with [vim-fugitive](https://github.com/tpope/vim-fugitive) and [vim-gitgutter](https://github.com/airblade/vim-gitgutter)
- GitHub integration with [vim-rhubarb](https://github.com/tpope/vim-rhubarb)
Expand Down Expand Up @@ -81,20 +83,53 @@ We don't overwrite \<Leader>. Defaults to the backslash (`\`) character.
| normal | `<C-p>` | **Search** for **files** (respecting .gitignore) | `:Telescope find_files` |
| normal | `<C-b>` | **Lists** open **buffers** in current neovim instance | `:Telescope buffers` |
| normal | `<C-g>` | **Search** for a **string** and get results live as you type (respects .gitignore) | `:Telescope live_grep` |
| normal | `gd` | Go **to** the **definition** of the symbol under the cursor | `:vim.lsp.buf.definition` |
| normal | `K` | Displays **hover information** about the symbol under the cursor in a floating window.<br>Calling the function twice will jump into the floating window. | `:vim.lsp.buf.hover` |
| normal | `<Space>f` | **Formats** a buffer using the attached language server clients | `:vim.lsp.buf.format({ async = true })` |
| normal | `<Space>e` | **Show diagnostics** in a floating window | `:vim.diagnostic.open_float` |
| normal | `]d` | Move to the **next diagnostic** | `:vim.diagnostic.goto_next` |
| normal | `[d` | Move to the **previous diagnostic** | `:vim.diagnostic.goto_prev` |
| normal<br>visual | `<C-Up>` | Move line(s) up | |
| normal<br>visual | `<C-Down>` | Move line(s) down | |
| normal<br>visual | `<Leader>c<Space>` | **Comment** or uncomment lines | `gcc`<br>`gc` |
| insert | `<C-n>` | Invoke **completion** | `:cmp.complete` |

## Install support for programming languages
## Support for programming languages

Using nvim-treesitter commands
### Syntax highlighting

Using nvim-treesitter commands:

```
# inside nvim

:TSInstall <language_to_install>
```

More details: https://github.com/nvim-treesitter/nvim-treesitter?tab=readme-ov-file#language-parsers
More details: https://github.com/nvim-treesitter/nvim-treesitter?tab=readme-ov-file#language-parsers.

### Autocompletion and LSP

Using mason-nvim commands:

```
# inside nvim

:MasonInstall <language_to_install>
```

or

```
# inside nvim

:Mason
```

to open the interactive mason window.

More details: https://github.com/williamboman/mason.nvim?tab=readme-ov-file#commands.


## Check installation health

Expand Down
6 changes: 6 additions & 0 deletions lazy-lock.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
"lazy.nvim": { "branch": "main", "commit": "83493db50a434a4c5c648faf41e2ead80f96e478" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "82c7cb08ddb836ad938b2708e50085f12a8825d2" },
"mason.nvim": { "branch": "main", "commit": "3b5068f0fc565f337d67a2d315d935f574848ee7" },
"nvim-cmp": { "branch": "main", "commit": "04e0ca376d6abdbfc8b52180f8ea236cbfddf782" },
"nvim-lspconfig": { "branch": "master", "commit": "8c1831817d40925d22cd8a555296c44c02fdaaf5" },
"nvim-tree.lua": { "branch": "master", "commit": "f7c09bd72e50e1795bd3afb9e2a2b157b4bfb3c3" },
"nvim-treesitter": { "branch": "master", "commit": "2014f8285e306f4c8a896c7d3af53fdd599e5a4f" },
"nvim-treesitter-endwise": { "branch": "master", "commit": "60e8c288e011403f248b5f6478dde12bed8a6c55" },
Expand Down
4 changes: 0 additions & 4 deletions lua/plugins.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
-- The below table will be merged with the rest of the plugin specs under `/lua/plugins/*.lua`
return {
{
"airblade/vim-gitgutter",
event = "VeryLazy"
},
{
"bronson/vim-trailing-whitespace",
event = "VeryLazy"
Expand Down
34 changes: 34 additions & 0 deletions lua/plugins/completion.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
return {
"hrsh7th/nvim-cmp",
dependencies = {
'hrsh7th/cmp-buffer',
'hrsh7th/cmp-nvim-lsp',
"neovim/nvim-lspconfig"
},
event = "VeryLazy",
config = function()
local cmp = require('cmp')

cmp.setup({
completion = {
-- Can be quite distracting if enabled.
-- Manual completion via <C-n> possible.
autocomplete = false
},
window = {
completion = cmp.config.window.bordered({ border = "rounded" }),
documentation = cmp.config.window.bordered({ border = "rounded" })
},
mapping = cmp.mapping.preset.insert({
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = false })
}),
sources = cmp.config.sources(
{
{ name = 'nvim_lsp' },
{ name = 'buffer' },
}
)
})
end
}
9 changes: 9 additions & 0 deletions lua/plugins/gitgutter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
return {
"airblade/vim-gitgutter",
event = "VeryLazy",
config = function()
-- Deprioritize gitgutter signs over any other that has the default of 10.
-- Example vim.diagnostics generated by LSP.
vim.g.gitgutter_sign_priority = 5
end
}
88 changes: 88 additions & 0 deletions lua/plugins/lsp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
return {
"neovim/nvim-lspconfig",
dependencies = {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim"
},
config = function()
require("mason").setup()
require("mason-lspconfig").setup()

require("mason-lspconfig").setup_handlers({
-- The first entry (without a key) will be the default handler
-- and will be called for each installed server that doesn't have
-- a dedicated handler.
function(server_name) -- default handler (optional)
require("lspconfig")[server_name].setup({})
end,
-- Next, you can provide a dedicated handler for specific servers.
-- For example, a handler override for the `rust_analyzer`:
["lua_ls"] = function()
require("lspconfig").lua_ls.setup({
settings = {
Lua = {
diagnostics = {
globals = {'vim'}
}
}
}
})
end
})

-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd(
'LspAttach',
{
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(args)
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = args.buf }
local client = vim.lsp.get_client_by_id(args.data.client_id)

if client.server_capabilities.definitionProvider then
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
end

if client.server_capabilities.hoverProvider then
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
end

if client.server_capabilities.documentFormattingProvider then
vim.keymap.set(
'n',
'<space>f',
function()
vim.lsp.buf.format({ async = true })
end,
opts
)
end
end
}
)

-- Reduce diagnostics noise by only keeping signcolumn signs enabled.
-- vim.diagnostic.open_float keymap below can be used to show more details.
vim.diagnostic.config({
signs = true,
underline = false,
virtual_text = false
})
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)

-- Configures LSP hover window
local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview
function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
opts = opts or {}
opts.max_height = opts.max_height or 30
opts.max_width = opts.max_width or 120
opts.border = opts.border or "rounded"
return orig_util_open_floating_preview(contents, syntax, opts, ...)
end
end
}