Skip to content

"Unresolved Reference" diagnostic persists after code-action file creation #419

Description

@VigneshR387

Description

After using the Create File code action to resolve a [[wikilink]], the "Unresolved Reference" diagnostic does not clear even though the file is successfully created on disk. The diagnostic only disappears after :LspRestart or manually closing and reopening the source file.

Steps to Reproduce

  1. Open a markdown file
  2. Type [[nonexistent-note]] and place cursor on the reference
  3. Observe the "Unresolved Reference" diagnostic from markdown_oxide
  4. Trigger code action to create a new based on the reference.
  5. The new .md file is created on disk
  6. The "Unresolved Reference" diagnostic still persist
  7. :w does not clear it
  8. gd (go to definition) also doesn't work
  9. :LspRestart diagnostic clears and gd works

Expected Behavior

The "Unresolved Reference" diagnostic should clear immediately (or on save) after the file is created via code action, without requiring an LSP restart.

Observed Behavior

Diagnostic persists until :LspRestart or buffer reopen. The issue is not reproducible in small workspaces like ~/.config/nvim/ where it works correctly.

Video:

Screencast_20260323_213619.webm

Nvim-lspconfig:

{
  -- Main LSP Configuration
  'neovim/nvim-lspconfig',
  dependencies = {
    -- Automatically install LSPs and related tools to stdpath for Neovim
    -- Mason must be loaded before its dependents so we need to set it up here.
    -- NOTE: `opts = {}` is the same as calling `require('mason').setup({})`
    'mason-org/mason.nvim',

    -- This plugin streamlines Neovim's LSP setup by automating server installation and activation, providing helpful management commands, and mapping mason.nvim packages to nvim-lspconfig configurations.
    'mason-org/mason-lspconfig.nvim',
  },
  event = { 'BufReadPost', 'BufNewFile' },
  config = vim.schedule_wrap(function()
    -- If you're wondering about lsp vs treesitter, you can check out the wonderfully
    -- and elegantly composed help section, `:help lsp-vs-treesitter`

    local snacks_words_group = vim.api.nvim_create_augroup('snacks-words', { clear = true })
    -- disable Snacks.words when lsp detachs

    vim.api.nvim_create_autocmd('LspDetach', {
      group = snacks_words_group,
      callback = function(event) Snacks.words.disable(event.buf) end,
    })

    -- Enable the following language servers
    --  Feel free to add/remove any LSPs that you want here. They will automatically be installed.
    --  See `:help lsp-config` for information about keys and how to configure
    ---@type table<string, vim.lsp.Config>
    local servers = {
      -- clangd = {},
      -- gopls = {},
      -- pyright = {},
      -- rust_analyzer = {},
      --
      -- Some languages (like typescript) have entire language plugins that can be useful:
      --    https://github.com/pmizio/typescript-tools.nvim
      --
      -- But for many setups, the LSP (`ts_ls`) will work just fine
      -- ts_ls = {},
      jsonls = {
        -- lazy-load schemastore when needed
        before_init = function(_, new_config)
          new_config.settings.json.schemas = new_config.settings.json.schemas or {}
          vim.list_extend(new_config.settings.json.schemas, require('schemastore').json.schemas())
        end,
        settings = {
          json = {
            format = {
              enable = true,
            },
            validate = { enable = true },
          },
        },
      },
      yamlls = {
        before_init = function(_, new_config)
          new_config.settings.yaml.schemas = vim.tbl_deep_extend('force', new_config.settings.yaml.schemas or {}, require('schemastore').yaml.schemas())
        end,
        settings = {
          yaml = {
            schemaStore = {
              enable = false,
              url = '',
            },
          },
        },
      },

      bashls = {},

      stylua = {}, -- Used to format Lua code

      -- Special Lua Config, as recommended by neovim help docs
      lua_ls = {
        settings = {
          Lua = {},
        },
      },
      basedpyright = {},

      markdown_oxide = {},

      harper_ls = {
        enabled = true,
        filetypes = { 'markdown', 'typst' },
        settings = {
          ['harper-ls'] = {
            isolateEnglish = true,
            markdown = {
              -- [ignores this part]()
              -- [[ also ignores my marksman links ]]
              IgnoreLinkTitle = true,
            },
          },
        },
      },
    }
    for name, server in pairs(servers) do
      vim.lsp.config(name, server)
      vim.lsp.enable(name)
    end
  end),
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions