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

WARNING: The file has been changed since reading it!!! #540

Closed
NikolaM-Dev opened this issue Apr 10, 2024 · 4 comments
Closed

WARNING: The file has been changed since reading it!!! #540

NikolaM-Dev opened this issue Apr 10, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@NikolaM-Dev
Copy link

🐛 Describe the bug

Description

After using ObsidianNew, ObsidianRename or ObsidianExtractNode and saving, I get this invasive warning, I already tried to leave the note_frontmatter_func by default and it doesn't work either.

Preview

image

Disclaimer

I don't know if this is a bug in obsidian.nvim or if it is some kind of vim.opt

Config

return {
	'epwalsh/obsidian.nvim',
	version = '*',
	ft = 'markdown',
	enabled = true,
	keys = {
		{ '<leader>ob', '<cmd>ObsidianBacklinks<cr>', desc = '[O]bisidan [B]acklinks' },
		{ '<leader>od', '<cmd>ObsidianDailies<cr>', '[O]sidian [D]ailies' },
		{
			'<leader>oe',
			function()
				vim.ui.input({ prompt = 'Enter Note Title: ' }, function(title)
					if title == nil or title == '' then
						return
					end

					vim.cmd('ObsidianExtractNote ' .. title)
				end)
			end,
			desc = '[O]sidian [E]xtract Note',
			mode = { 'v' },
		},
		{ '<leader>ol', '<cmd>ObsidianLinks<cr>', '[O]sidian [L]inks' },
		{ '<leader>on', '<cmd>ObsidianNew<cr>', '[O]sidian [N]ew' },
		{ '<leader>oo', '<cmd>ObsidianOpen<cr>', desc = '[O]pen in [O]bsidian' },
		{ '<leader>oq', '<cmd>ObsidianQuickSwitch<cr>', '[O]sidian [Q]uick Swith' },
		{ '<leader>or', '<cmd>ObsidianRename<cr>', '[O]sidian [R]ename' },
		{ '<leader>os', '<cmd>ObsidianSearch<cr>', '[O]sidian [S]earch' },
		{ '<leader>ot', '<cmd>ObsidianTags<cr>', '[O]sidian [T]ags' },
	},
	config = function()
		---@diagnostic disable: missing-fields
		require('obsidian').setup({
			workspaces = {
				{
					name = 'second-brain.md',
					path = '~/Documents/second-brain.md',
				},
			},
			completion = {
				min_chars = 2,
			},
			attachments = {
				img_folder = '900-assets',
			},
			mappings = {
				['<leader>ch'] = {
					action = function()
						return require('obsidian').util.toggle_checkbox()
					end,
					opts = { buffer = true, desc = 'Toggle [C][H]eck boxes' },
				},
			},
			ui = {
				bullets = { char = '', hl_group = 'ObsidianBullet' },
				checkboxes = {},
				enable = true,
				external_link_icon = { char = '', hl_group = 'ObsidianExtLinkIcon' },
				highlight_text = { hl_group = 'ObsidianHighlightText' },
				reference_text = { hl_group = 'ObsidianRefText' },
				tags = { hl_group = 'ObsidianTag' },
				update_debounce = 284,
				hl_groups = {
					ObsidianBullet = { bold = true, fg = '#89ddff' },
					ObsidianDone = { bold = true, fg = '#89ddff' },
					ObsidianExtLinkIcon = { fg = '#c792ea' },
					ObsidianHighlightText = { bg = '#75662e' },
					ObsidianRefText = { underline = true, fg = '#c792ea' },
					ObsidianRightArrow = { bold = true, fg = '#f78c6c' },
					ObsidianTag = { italic = true, fg = '#89ddff' },
					ObsidianTilde = { bold = true, fg = '#ff5370' },
					ObsidianTodo = { bold = true, fg = '#f78c6c' },
				},
			},
			wiki_link_func = 'prepend_note_path',
			note_frontmatter_func = function(note)
				if note.title then
					note:add_alias(note.title)
				end

				local current_date = os.date('%Y-%m-%d, %I:%M %p')
				local out = {
					aliases = note.aliases,
					created_at = current_date,
					id = note.id,
					tags = note.tags,
					updated_at = current_date,
				}

				if note.metadata ~= nil and not vim.tbl_isempty(note.metadata) then
					for k, v in pairs(note.metadata) do
						out[k] = v
					end
				end

				out.updated_at = current_date

				---@diagnostic disable-next-line: redundant-return-value
				return out
			end,

			new_notes_location = 'current_dir',

			note_id_func = function(title)
				local suffix = ''

				if title ~= nil then
					-- If title is given, transform it into valid file name.
					suffix = title:gsub(' ', '-'):gsub('[^A-Za-z0-9-]', ''):lower()
				else
					-- If title is nil, just add 4 random uppercase letters to the suffix.
					for _ = 1, 4 do
						suffix = suffix .. string.char(math.random(65, 90))
					end
				end

				return tostring(os.date('%Y%m%d%H%M%S')) .. '-' .. suffix
			end,
			daily_notes = {
				folder = '000-calendar/00-dailies',
				date_format = '%Y-%m-%d',
				alias_format = '%A, %d %B %Y',
				template = nil,
			},
			follow_url_func = function(url)
				vim.fn.jobstart({ 'brave', url })
			end,
		})
	end,
}

Environment

nvim --headless -c 'lua require("obsidian").info()' -c q
NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1702233742

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info
Obsidian.nvim v3.7.6 (d70f3289399c25153b7f503b838afbf981124a37)
Status:
  • buffer directory: nil
  • working directory: /home/nikola/Documents/second-brain.md
Workspaces:
  ✓ active workspace: Workspace(name='second-brain.md', path='/home/nikola/Documents/second-brain.md', root='/home/nikola/Documents/second-brain.md')
Dependencies:
  ✓ plenary.nvim: 8aad4396840be7fc42896e3011751b7609ca4119
  ✓ nvim-cmp: ce16de5665c766f39c271705b17fff06f7bcb84f
Integrations:
  ✓ picker: TelescopePicker()
  ✓ completion: enabled (nvim-cmp) ✗ refs, ✗ tags, ✗ new
    all sources:
      • copilot
      • nvim_lsp
      • nvim_lua
      • luasnip
      • emmet
      • nvim_lsp_signature_help
      • buffer
      • path
      • calc
      • rg
Tools:
  ✓ rg: ripgrep 14.1.0
Environment:
  • operating system: Linux
Config:
  • notes_subdir: nil%
@NikolaM-Dev NikolaM-Dev added the bug Something isn't working label Apr 10, 2024
@jemag
Copy link
Contributor

jemag commented Apr 18, 2024

I actually get the same problem just saving :w the note.

I think (in my case) it might be related to the updated field changing:
image

Edit: autoread is enabled in my config, but it often does not work the best. Seems this is something upstream Neovim might work on in the future (neovim/neovim#1380). The fact that the files are stored on the windows side of WSL, might not help either

@a1401358759
Copy link

I'm having the same problem, strangely enough some projects have it and some don't!

@NikolaM-Dev
Copy link
Author

The problem was having nvim & obsidian open at the same time, I suppose due to plugins that I have in obsidian and plugins that I have in nvim that do actions when I save, such as lint, formatting etc...

Btw, I still have my functions for updated_at and it is not the problem in case anyone considers it

Should I close the issue?

@jorgeavaldez
Copy link

I'm also having this issue. Unrelated to having obsidian open in my case.

One thing I've found is that I get some weird error message when I preemptively run :e! in a file.
image

It seems once I open at least one file and go through this dance, subsequent files seem fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants