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

Code Actions sometimes use incorrect cspell.json file #25

Closed
mcDevnagh opened this issue Nov 8, 2023 · 3 comments · Fixed by #26
Closed

Code Actions sometimes use incorrect cspell.json file #25

mcDevnagh opened this issue Nov 8, 2023 · 3 comments · Fixed by #26

Comments

@mcDevnagh
Copy link
Contributor

Despite setting the find_json function to always return "/tmp/cspell.json" it sometimes returns the current working directory (vim.loop.cwd()), when all of the following conditions are met:

  1. the CWD is not in the LSP workspace folders (vim.lsp.buf.list_workspace_folders())
    • for example when in a sub-directory of a git repo (i.e. the parent directory of the CWD has a .git dir)
  2. it's the first code action used
    • If I activate the code action, cancel, then activate another one, the correct config JSON is used.

I believe this is the same issue specified here

Minimal Config:

local M = {}

function M.root(root)
	local f = debug.getinfo(1, "S").source:sub(2)
	return vim.fn.fnamemodify(f, ":p:h:h") .. "/" .. (root or "")
end

function M.setup()
	vim.loader.enable()
	vim.cmd([[set runtimepath=$VIMRUNTIME]])
	vim.opt.runtimepath:append(M.root())
	vim.opt.packpath = { M.root(".tests/site") }
	vim.env.XDG_CONFIG_HOME = M.root(".tests/config")
	vim.env.XDG_DATA_HOME = M.root(".tests/data")
	vim.env.XDG_STATE_HOME = M.root(".tests/state")
	vim.env.XDG_CACHE_HOME = M.root(".tests/cache")
	local lazypath = vim.env.XDG_DATA_HOME .. "/lazy/lazy.nvim"
	if not vim.loop.fs_stat(lazypath) then
		vim.fn.system({
			"git",
			"clone",
			"--filter=blob:none",
			"https://github.com/folke/lazy.nvim.git",
			"--branch=stable", -- latest stable release
			lazypath,
		})
	end
	vim.opt.rtp:prepend(lazypath)

	require("lazy").setup({
		spec = {
			{
				"nvimtools/none-ls.nvim",
				dependencies = {
					"nvim-lua/plenary.nvim",
					"neovim/nvim-lspconfig",
					{
						"williamboman/mason.nvim",
						config = function()
							require("mason").setup()
							local reg = require("mason-registry")
							local pkg = reg.get_package("cspell")
							if not pkg:is_installed() then
								pkg:install()
							end
						end,
					},
					"williamboman/mason-lspconfig.nvim",
					"davidmh/cspell.nvim",
				},
				opts = function(_, opts)
					local cspell = require("cspell")
					local json = "/tmp/cspell.json"
					local cspell_opts = {
						config = {
							config_file_preferred_name = "cspell.json",
							find_json = function(_)
								return json
							end,
						},
					}

					opts.sources = vim.list_extend(opts.sources or {}, {
						cspell.diagnostics.with(cspell_opts),
						cspell.code_actions.with(cspell_opts),
					})
				end,
			},
		},
		defaults = {
			lazy = false,
			version = false,
		},
	})

	vim.keymap.set({ "n", "v" }, "<CR>", vim.lsp.buf.code_action, { desc = "Code Action" })
end

vim.o.swapfile = false
_G.__TEST = true

M.setup()
@davidmh
Copy link
Owner

davidmh commented Nov 8, 2023

Thanks! I'll look into it by the end of this week

@davidmh
Copy link
Owner

davidmh commented Nov 13, 2023

@mcDevnagh this should be fixed now, please let me know if you keep experiencing issues.

@mcDevnagh
Copy link
Contributor Author

that fixed my issue. tysm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants