Skip to content

Commit

Permalink
Fix bug with cmp_obsidian_new on Linux (#508)
Browse files Browse the repository at this point in the history
* Fix bug with `cmp_obsidian_new` on Linux

Fixes #507.

* fix more path too
  • Loading branch information
epwalsh committed Mar 22, 2024
1 parent 6a81ca9 commit 271db15
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Fixed

- Fixed bug with created new notes from `nvim-cmp` on Linux.

## [v3.7.4](https://github.com/epwalsh/obsidian.nvim/releases/tag/v3.7.4) - 2024-03-19

### Fixed
Expand Down
11 changes: 11 additions & 0 deletions lua/cmp_obsidian_new.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,19 @@ source.complete = function(_, request, callback)
end

source.execute = function(_, item, callback)
local Note = require "obsidian.note"
local Path = require "obsidian.path"

local client = assert(obsidian.get_client())
local data = item.data

-- Make sure `data.note` is actually an `obsidian.Note` object. If it gets serialized at some
-- point (seems to happen on Linux), it will lose its metatable.
if not Note.is_note_obj(data.note) then
data.note = setmetatable(data.note, Note.mt)
data.note.path = setmetatable(data.note.path, Path.mt)
end

client:write_note(data.note, { template = data.template })
return callback {}
end
Expand Down

0 comments on commit 271db15

Please sign in to comment.