Skip to content

Commit

Permalink
fix: refactor buffer manager (#1666)
Browse files Browse the repository at this point in the history
* chore: remove useless code and improve
integration notes

* chore: Remove unnecessary comments as the code is already self-explanatory

* chore: optional chaining, ternary

* refactor: Merge the logic for handling activeEditor and visibleEditors

Theoretically, there is an improvement for some edge cases

* fix: check if the buffer is valid when setting options

* refactor: cleanupWindowAndBuffers

* chore: await updateNeovimCursorPosition

* chore: simplify code

* chore: remove unused code

* fix: should await the client.window

* chore: Re-add comments about editor options

* refactor: read fallback editor options from settings
  • Loading branch information
xiyaowong committed Dec 2, 2023
1 parent 7311d2f commit 1a27694
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 200 deletions.
8 changes: 8 additions & 0 deletions runtime/lua/vscode-neovim/sync-options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ end
---@param buf number
---@param opts EditorOptions
local function set_options(buf, opts)
-- Due to debounce of editor options change event, in some special cases, buffer
-- may be deleted when starting to set options.
if not api.nvim_buf_is_valid(buf) then
return
end
api.nvim_buf_set_var(buf, "vscode_editor_options", opts)
if vim.bo[buf].ts ~= opts.tabSize then
vim.bo[buf].ts = opts.tabSize
Expand Down Expand Up @@ -127,6 +132,9 @@ end
function M.setup()
vscode.on("editor_options_changed", set_options)
vscode.on("document_buffer_init", function(buf)
if not api.nvim_buf_is_valid(buf) then
return
end
local has, opts = pcall(api.nvim_buf_get_var, buf, "vscode_editor_options")
if has then
set_options(buf, opts)
Expand Down

0 comments on commit 1a27694

Please sign in to comment.