Skip to content

Commit

Permalink
feat(nvim): reload sourcekit server on compile
Browse files Browse the repository at this point in the history
  • Loading branch information
kkharji committed Jun 22, 2022
1 parent bdd0e6c commit ef92912
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -90,6 +90,7 @@ issue
## 🛠 Requirements

- [neovim] v0.7.0 or nightly
- [lspconfig]
- [rust] 1.60.0 or up (see [rust getting started])
- [telescope.nvim]
- [plenary.nvim]
Expand All @@ -101,6 +102,7 @@ To install [XBase] on your system you need run `make install`. This will run `ca
moved to `path/to/repo/bin` and the lua library will be moved to
`path/to/repo/lua/libxbase.so`.


#### With [packer]
```lua
use {
Expand All @@ -109,6 +111,7 @@ use {
requires = {
"nvim-lua/plenary.nvim",
"nvim-telescope/telescope.nvim"
"neovim/nvim-lspconfig"
},
config = function()
require'xbase'.setup({}) -- see default configuration bellow
Expand All @@ -120,6 +123,7 @@ use {
```vim
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'neovim/nvim-lspconfig'
Plug 'tami5/xbase', { 'do': 'make install' }
lua require'xbase'.setup()
```
Expand All @@ -128,10 +132,13 @@ lua require'xbase'.setup()
```vim
call dein#add('nvim-lua/plenary.nvim')
call dein#add('nvim-telescope/telescope.nvim')
call dein#add('neovim/nvim-lspconfig')
call dein#add('tami5/xbase', { 'build': 'make install' })
lua require'xbase'.setup()
```

**NOTE:** You need to setup sourcekit-lsp (see [sourcekit-setup])

## 🎮 Usage

TLDR:
Expand Down Expand Up @@ -236,6 +243,8 @@ statusline get updated.
[neovim]: https://github.com/neovim/neovim
[tuist]: https://github.com/tuist/tuist
[CONTRIBUTING.md]: ./CONTRIBUTING.md
[lspconfig]: https://github.com/neovim/nvim-lspconfig
[sourcekit-setup]: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#sourcekit

[👁 Overview]: #-motivation
[🌝 Motivation]: #-motivation
Expand Down
6 changes: 5 additions & 1 deletion daemon/src/compile.rs
Expand Up @@ -77,11 +77,15 @@ pub async fn ensure_server_support<'a>(
logger.append(first).await?;
logger.append(lines.join("\n")).await?;
}

return Ok(false);
};

project.update_compile_database().await?;
state
.clients
.get(&pid)?
.exec_lua("require'xbase.util'.reload_lsp_servers()", vec![])
.await?;
return Ok(true);
}
}
Expand Down
13 changes: 13 additions & 0 deletions lua/xbase/util.lua
Expand Up @@ -35,6 +35,19 @@ M.get_targets_runners = function(project)
return targets
end

M.reload_lsp_servers = function()
local clients = require("lspconfig.util").get_managed_clients()
local ids = ""
for _, client in ipairs(clients) do
if client.name == "sourcekit" then
ids = ids .. client.id
end
end

print "Restarting Sourcekit Server"
vim.cmd("LspRestart " .. ids)
end

M.is_watching = function(config, command, device)
local root = vim.loop.cwd()
local watching = vim.g.xbase.watcher[root]
Expand Down

0 comments on commit ef92912

Please sign in to comment.