Skip to content

Commit

Permalink
perf(lsp): defer attaching client to BufEnter (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb authored May 24, 2024
1 parent 3f0e8b4 commit 90bfbc5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- LSP: Defer attaching the LSP client to `BufEnter` for a smoother experience
on low-end devices.

## [4.23.5] - 2024-05-24

### Fixed
Expand Down
11 changes: 9 additions & 2 deletions ftplugin/rust.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,19 @@ end

vim.g.loaded_rustaceanvim = true

local bufnr = vim.api.nvim_get_current_buf()
local auto_attach = config.server.auto_attach
if type(auto_attach) == 'function' then
local bufnr = vim.api.nvim_get_current_buf()
auto_attach = auto_attach(bufnr)
end

if auto_attach then
require('rustaceanvim.lsp').start()
-- Defer for a smoother experience on low-end devices
vim.api.nvim_create_autocmd('BufEnter', {
buffer = bufnr,
group = vim.api.nvim_create_augroup('RustaceanvimAttach', { clear = true }),
callback = function()
require('rustaceanvim.lsp').start()
end,
})
end

0 comments on commit 90bfbc5

Please sign in to comment.