Giter VIP home page Giter VIP logo

ltex_extra.nvim's Introduction

Hello there! ๐Ÿ‘‹

I'm Leo from Argentina ๐Ÿ‡ฆ๐Ÿ‡ท.

Close to graduating as an electromechanical engineer.

Now working as a game dev backend with C++.

Freelance since 2016 on electronic projects using C & C++ for embedded and Python for tooling.

I'm a nerd who loves Linux, enjoys customizing his development environment, and trying out new technologies.

Metrics

ltex_extra.nvim's People

Contributors

barreiroleo avatar chomosuke avatar christoffer avatar dbucher97 avatar fhfuih avatar fymyte avatar iljo avatar jkub6 avatar jmanch avatar moreka avatar nawordar avatar paysancorrezien avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ltex_extra.nvim's Issues

Problem with creating a directory when absolute path is specified

There is a problem if path is set as absolute path, and last directory in the path is missing, i.e. should be created. So, an error is displayed when trying to add some word to a dictionary in that case. This is what is displayed:

Failed making directory:
Error executing vim.schedule lua callback: ...efined/start/ltex_extra.nvim/lua/ltex_extra/utils/fs.lua:56: attempt to index local 'stat' (a nil value)
stack traceback:
        ...efined/start/ltex_extra.nvim/lua/ltex_extra/utils/fs.lua:56: in function 'check_dir'
        ...efined/start/ltex_extra.nvim/lua/ltex_extra/utils/fs.lua:79: in function 'exportFile'
        ...ed/start/ltex_extra.nvim/lua/ltex_extra/commands-lsp.lua:96: in function 'fn'
        /usr/share/nvim/runtime/lua/vim/lsp/buf.lua:651: in function 'apply_action'
        /usr/share/nvim/runtime/lua/vim/lsp/buf.lua:697: in function 'on_choice'
        /usr/share/nvim/runtime/lua/vim/ui.lua:54: in function 'select'
        /usr/share/nvim/runtime/lua/vim/lsp/buf.lua:708: in function 'on_code_action_results'
        /usr/share/nvim/runtime/lua/vim/lsp/buf.lua:726: in function 'callback'
        /usr/share/nvim/runtime/lua/vim/lsp.lua:2021: in function 'handler'
        /usr/share/nvim/runtime/lua/vim/lsp.lua:1394: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

To Reproduce

  1. Configure ltex_extra to have path variable set as absolute path to directory. Something like
    /home/user/Documents/Test Path.
  2. Make sure that the last directory is missing. (Test Path in the example)
  3. Misspell some word, or make up a new word.
  4. Try to add that word to a dictionary through code action.
  5. See error above.

Expected behavior
A word should be added to a dictionary. And as it's the case when the relative path is provided and last directory is missing, it should be created.

System:

  • OS: Linux
  • Neovim version: stable
  • LTeX server intallation method: manual
  • ltex_extra version: currently, the latest commit f32a4ca

Edit:
Originally, the issue was reporting the problem with spaces in path. But actually, the problem with spaces was when I was using the version at commit 3ceb240. Then I updated to the latest version, and taught it's still the same problem, just with a different error message. It's not, the different error message refers to the bug with an absolute path, that's why I've updated the bug report, and didn't create a new issue.

Error catching ltex client

The Bug
When performing a code action command, like add to a dictionary, the word is added to the dictionary file, but the config of ltex is not updated, with the error that the ltex client could not be catched. The result is that the word is still unknown to ltex. However, when restarting nvim, the correct dictionary is loaded and the word is known.

The reason for this bug is that vim.lsp.buf_get_clients() does return an empty dict for a reason I belive I can explain later.

Log:

Error catching ltex client
[ltex_extra] [TRACE 12:49:10] ...tart/ltex_extra.nvim/lua/ltex_extra/src/commands-lsp.lua:90: addToDictionary
[ltex_extra] [DEBUG 12:49:10] ...tart/ltex_extra.nvim/lua/ltex_extra/src/commands-lsp.lua:93: Lang: '"en-US"' Words: '{ "rrest
" }'
[ltex_extra] [TRACE 12:49:10] ...acker/start/ltex_extra.nvim/lua/ltex_extra/src/utils.lua:61: Exporting  dictionary en-US { "r
rest" }
[ltex_extra] [TRACE 12:49:10] ...acker/start/ltex_extra.nvim/lua/ltex_extra/src/utils.lua:37: Checking dir .ltex/
[ltex_extra] [TRACE 12:49:10] ...acker/start/ltex_extra.nvim/lua/ltex_extra/src/utils.lua:13: Checking path  .ltex/
[ltex_extra] [TRACE 12:49:10] ...acker/start/ltex_extra.nvim/lua/ltex_extra/src/utils.lua:50: Writing  .ltex/ltex.dictionary.e
n-US.txt
[ltex_extra] [TRACE 12:49:10] ...tart/ltex_extra.nvim/lua/ltex_extra/src/commands-lsp.lua:57: updateConfig
[ltex_extra] [TRACE 12:49:10] ...tart/ltex_extra.nvim/lua/ltex_extra/src/commands-lsp.lua:13: catch_ltex
[ltex_extra] [ERROR 12:49:10] ...tart/ltex_extra.nvim/lua/ltex_extra/src/commands-lsp.lua:71: Error catching ltex client

To Reproduce
Steps to reproduce the behavior:

  1. ltex-ls installed through mason.nvim
  2. Setup for ltex:
require("lspconfig").ltex.setup {
    on_attach = function(_, _)
        -- your other on_attach functions.
        require("ltex_extra").setup {
            load_langs = { "en-US", "de-DE" },
            init_check = true,
            path = ".ltex",
            log_level = "trace",
        }
    end,
    settings = {
        ltex = {
            additionalRules = {
                languageModel = "~/.ngrams/",
                motherTounge = "de-DE",
            },
        },
    },
}
  1. Open a simple markdown file and insert a non-known word.
  2. Add a word to the dictionary through code actions.

Expected behavior
Add the word to the dictionary and update the ltex configuration

Possible Reason
Neovim often has weird behavior when interacting with the API through callbacks. That's why the API features methods like schedule that execute a function inside the main event loop. Wrapping the updateConfig function with vim.schedule will probably fix this issue.

I will shortly open a PR with a version that works for me.

System:

  • OS: macOS
  • Neovim version: 0.8.2
  • LTeX server intallation method: mason

Files are written for ignored rules/ false positives and dictionary, but they aren't ignored during linting

Describe the bug
When I activate the code action to hide a false positive, the following error comes up:

[ltex_extra] [ERROR 12:41:26] ...tart/ltex-extra.nvim/lua/ltex_extra/src/commands-lsp.lua:69:Error catching ltex client

The files are written in the path specified in the config:
image

But they are ignored inside the editor (the warning about the ignored error keeps appearing.

Expected behavior
The ignored diagnostics should not show warnings.

System:

  • OS: macOS, Monterey, 12.6
  • Neovim version: 0.8
  • LTeX server installation method: mason

Additional context
My lsp and plugging config:

	if server == "ltex" then
		opt.settings = {
			ltex = {
				enabled = { "latex", "tex", "bib", "markdown" },
				language = "en-US",
				diagnosticSeverity = "information",
				setenceCacheSize = 2000,
				checkFrequency = "edit",
				trace = { server = "verbose" },
				additionalRules = {
					enablePickyRules = true,
					motherTongue = "pt-BR",
				},
			},
		}

		opt.on_attach = function(client, bufnr)
			on_attach(client, bufnr)
			require("ltex_extra").setup({
				load_langs = { "en-US" }, -- table <string> : languages for witch dictionaries will be loaded
				init_check = true, -- boolean : whether to load dictionaries on startup
				path = home .. "/.config/nvim/grammar", -- string : path to store dictionaries. Relative path uses current working directory
				log_level = "debug", -- string : "none", "trace", "debug", "info", "warn", "error", "fatal"
			})
		end
	end

Here is a little video with the complete behavior:

Screen.Recording.2022-11-13.at.12.49.54.mov

Error catching ltex client.

I have the error below sometime:

Error executing vim.schedule lua callback: ...vim/lazy/ltex_extra.nvim/lua/ltex_extra/commands-lsp.lua:84: Error catching ltex client
stack traceback:
	[C]: in function 'updateConfig'
	...vim/lazy/ltex_extra.nvim/lua/ltex_extra/commands-lsp.lua:84: in function <...vim/lazy/ltex_extra.nvim/lua/ltex_extra/commands-lsp.lua:83>
Error executing vim.schedule lua callback: ...vim/lazy/ltex_extra.nvim/lua/ltex_extra/commands-lsp.lua:84: Error catching ltex client
stack traceback:
	[C]: in function 'updateConfig'
	...vim/lazy/ltex_extra.nvim/lua/ltex_extra/commands-lsp.lua:84: in function <...vim/lazy/ltex_extra.nvim/lua/ltex_extra/commands-lsp.lua:83>

To Reproduce
Steps to reproduce the behavior:

  1. Your settings for ltex are:
    {
        "barreiroleo/ltex_extra.nvim",
        event = "LazyFile",
        dependencies = { "neovim/nvim-lspconfig" },
    },
    -- setup
                setup = {
                -- integrate ltex_extra with lazyvim
                -- https://github.com/LazyVim/LazyVim/discussions/403
                ---@diagnostic disable-next-line: unused-local
                ltex = function(_, opts)
                    vim.api.nvim_create_autocmd("LspAttach", {
                        callback = function(args)
                            ---@diagnostic disable-next-line: no-unknown
                            local client = vim.lsp.get_client_by_id(args.data.client_id)
                            if client.name == "ltex" then
                                require("ltex_extra").setup({
                                    load_langs = { "en-US", "fr" }, -- languages for witch dictionaries will be loaded
                                    init_check = true, -- whether to load dictionaries on startup
                                    path = vim.fn.expand("~") .. "/.config/ltex", -- path to store dictionaries.
                                    log_level = "error", -- "none", "trace", "debug", "info", "warn", "error", "fatal"
                                })
                            end
                        end,
                    })
                end,
            },

System:

  • OS: MacOS
  • Neovim version: 0.9.4

Support having both global and project-local dictionaries at the same time

Is your feature request related to a problem? Please describe.
Currently, I have to decide whether I want to use a global and a project-specific dictionary file. This also applies to hiddenFalsePositives. While some words and rules apply to a single project, others apply to everything I'm working at.

Describe the solution you'd like
I would like to have an additional setup option called global_path, user_path (in LTeX terminology) or something similar. After setting that option, a new code actions would appear: "Add 'โ€ฆ' to global dictionary" and "Hide false positive globally".

Describe alternatives you've considered
I tried setting the dictionary paths using ltex.dictionary, but it seems it is only supported by the VSCode extension.

Provide a default language

Actually is an issue. Probably when I wrote this, en-US was working as default for the code action.
Thanks!

Note to self: Add default lang for updateConfigFull or insert one at setup if the table is empty.

Originally posted by @barreiroleo in #43 (comment)

Home directory can't be accessed via ~ in ltex_extra path

Describe the bug
Say I wish ltex_extra to save files to my home directory:

require("lspconfig").ltex.setup {
    on_attach = function(client, bufnr)
        require("ltex_extra").setup {
            load_langs = { "en-GB" },
            init_check = true,
            path = "~",
            log_level = "none",
        }
    end,
    settings = {
        ltex = {
            language = "en-GB",
        }
    }
}

This appears to be okay until ltex_extra tries to write to the specified path containing ~, then it fails. For instance if I try to add a word to the ltex dictionary via a code action then it reports the following error:

Fail making directory
Fail export ~/ltex.dictionary.en-GB.txt

Presumably it thinks ~ is supposed to be the name of a regular directory and finds it can't name a directory this in the current path.

Expected behavior
In the above mentioned case, ltex.dictionary.en-GB.txt should be written to the home directory, /home/username/ltex.dictionary.en-GB.txt.

System:

  • OS: Linux
  • Neovim version: 0.9 Nightly
  • LTeX server intallation method: Mason

Error catching ltex client

Hello, I am trying to get language tool to work, I am using lazy and Mason...
I keep getting:
swappy-20230309-085359
also cant't find how to get "spell suggestions" or substitute with correct suggestions for grammar like I can do in the browser.
my config is:

return {
    require("lspconfig").ltex.setup {
        capabilities = capabilities,
        -- on_attach = function(client, bufnr)
        on_attach = on_attach,
        -- your other on_attach functions.
        require("ltex_extra").setup {
            load_langs = { "es", "en-US" }, -- table <string> : languages for witch dictionaries will be loaded
            init_check = true,              -- boolean : whether to load dictionaries on startup
            path = nil,                     -- string : path to store dictionaries. Relative path uses current working directory
            log_level = "none",             -- string : "none", "trace", "debug", "info", "warn", "error", "fatal"
        },
        settings = {
            ltex = {
                language = "auto",
                additionalRules = {
                    enablePickyRules = true,
                    motherTongue = "es",
                },
            }
        }
    }
}

the return {} is because of auto load for lazy.nvim
how can I enable this for all files, txt,markdown,html etc?

Disable missing-files warning when not using those files.

Is your feature request related to a problem? Please describe.
It's a bit annoying to saw the missing-files warning when you actucally don't need that file.
For example, I only needs ltex.dictionary.en-US.txt in certain repo. The warnings of missing ltex.disabledRules.en-US.txt and ltex.hiddenFalsePositives.en-US.txt are a bit annoying. Even when I do need those files, ltex_extra.nvim's code action will create it. So it's a bit confuse to see this kind of warning.

Describe the solution you'd like
Don't show miss-files warning even if there's only one of the three files is created.

Describe alternatives you've considered
I saw you add a related TODO of Abort initial load if the files doesn't exist, maybe you're already consider it? If so I will close the issue.

Thanks for creeating this handy plugin!

disabledRules in ltex settings are ignored

Describe the bug
With the following config:

require("lspconfig").ltex.setup {
    on_attach = function(client, bufnr)
        require("ltex_extra").setup {
            load_langs = { "en-GB" },
            init_check = true,
            path = "ltex",
            log_level = "none",
        }
    end,
    settings = {
        ltex = {
            language = "en-GB",
            disabledRules = {
                ["en-GB"] = { "PROFANITY", "IE_NO_COMMA", "EG_NO_COMMA", "PASSIVE_VOICE", "BACHELOR_ABBR" }
            },
            dictionary = {
                ["en-GB"] = { "Neovim", "ltex-ls" }
            },
            additionalRules = {
                enablePickyRules = true,
                motherTongue = "en-GB",
                languageModel = "~/ngrams"
            }
        }
    }
}

None of the disabledRules specifically passed to ltex ("PROFANITY", "IE_NO_COMMA", "EG_NO_COMMA", "PASSIVE_VOICE", "BACHELOR_ABBR") are listened to if ltex_extra is also attached. Creating an ltex.disabledRules.en-GB.txt file with these rules works, but if I want to use ltex for per-project rules (so my ltex_extra path is project-relative) I have to copy this file every time.

Expected behavior
I believe ltex_extra should always follow any disabledRules passed to ltex specifically and ltex.disabledRules.*.txt files should always supplement instead of supersede this (or at least these rules shouldn't be ignored if such a file doesn't exist).

System:

  • OS: Linux (Arch)
  • Neovim version: [nightly]
  • LTeX server intallation method: [mason]

Replacement suggestions via quick fixes

Is your feature request related to a problem? Please describe.
It's cumbersome to look for the correct spelling on Google and type it in.

Describe the solution you'd like
A code action to accept a ltex suggestion, possibly mappable.

Describe alternatives you've considered
VSC is not an option.

Additional context
As you've implemented the other extra features the VSC plugin for ltex provides, the "accept quick fix suggestion" option is missing.
I've also noticed, that I don't even have suggestions - is there a way to turn this on or do I need an extra dictionary for that?

The feature is described here and here and the ltex main website also suggests that this feature exists natively (Replacement suggestions via quick fixes).

Edit: found another source.

No trailing separator for `path` option

Describe the bug
When setting the path option, trailing separators are not added by default, and they are removed if one is added manually. I get a warning saying that the path /home/vandal/.local/share/ltexltex.hiddenFalsePositives.en-US.txt does not exist. I think this behaviour is introduced by vim.fs.normalize(), added in #26. For example:

  • :lua print(vim.fn.expand("~") .. "/.local/share/ltex/") gives the trailing slash
  • :lua print(vim.fs.normalize(vim.fn.expand("~") .. "/.local/share/ltex/")) does not show a trailing slash

I think moving .. "/" outside of vim.fs.normalize() here would fix the issue. I tried locally and it seemed to work. Let me know if I should send a PR or if you prefer to do it directly.

Here is my config for ltex_extra:

  require("ltex_extra").setup{
    load_langs = { "fr", "en-US" },
    init_check = true, -- boolean : whether to load dictionaries on startup
    path = vim.fn.expand("~") .. "/.local/share/ltex/",
    log_level = "warn"
  }

To Reproduce
Steps to reproduce the behavior:

  1. Use the config shown above
  2. Load a file that uses ltex
  3. Get the warning described above

Expected behavior
The trailing separator should be kept when added manually, and probably added automatically when not present.

System:

  • OS: Linux
  • Neovim version: 0.9.0
  • LTeX server intallation method: mason

User dictionary not loaded even if `init_check = true`

Logs

[ltex_extra] [TRACE 14:21:11] /home/xxx/.config/nvim_test/.repro/plugins/ltex_extra.nvim/lua/ltex_extra/commands-lsp.lua:79: updateConfigFull
[ltex_extra] [TRACE 14:29:02] /home/xxx/.config/nvim_test/.repro/plugins/ltex_extra.nvim/lua/ltex_extra/commands-lsp.lua:92: addToDictionary
[ltex_extra] [DEBUG 14:29:21] /home/xxx/.config/nvim_test/.repro/plugins/ltex_extra.nvim/lua/ltex_extra/commands-lsp.lua:95: Lang: '"en-US"' Words: '{ "missspell" }'
[ltex_extra] [TRACE 14:29:27] /home/xxx/.config/nvim_test/.repro/plugins/ltex_extra.nvim/lua/ltex_extra/utils/fs.lua:77: Exporting  dictionary en-US { "missspell" }
[ltex_extra] [TRACE 14:29:29] /home/xxx/.config/nvim_test/.repro/plugins/ltex_extra.nvim/lua/ltex_extra/utils/fs.lua:47: Checking dir /home/xxx/.config/nvim_test/
[ltex_extra] [TRACE 14:29:31] /home/xxx/.config/nvim_test/.repro/plugins/ltex_extra.nvim/lua/ltex_extra/utils/fs.lua:65: Writing  /home/xxx/.config/nvim_test/ltex.dictionary.en-US.txt { "missspell" }
[ltex_extra] [TRACE 14:29:33] /home/xxx/.config/nvim_test/.repro/plugins/ltex_extra.nvim/lua/ltex_extra/commands-lsp.lua:60: updateConfig
[ltex_extra] [TRACE 14:29:34] /home/xxx/.config/nvim_test/.repro/plugins/ltex_extra.nvim/lua/ltex_extra/commands-lsp.lua:51: catch_ltex
[ltex_extra] [TRACE 14:29:34] /home/xxx/.config/nvim_test/.repro/plugins/ltex_extra.nvim/lua/ltex_extra/commands-lsp.lua:25: update_dictionary
[ltex_extra] [TRACE 14:29:35] /home/xxx/.config/nvim_test/.repro/plugins/ltex_extra.nvim/lua/ltex_extra/utils/fs.lua:127: Loading  dictionary en-US
[ltex_extra] [TRACE 14:29:35] /home/xxx/.config/nvim_test/.repro/plugins/ltex_extra.nvim/lua/ltex_extra/utils/fs.lua:28: Checking path  /home/xxx/.config/nvim_test/ltex.dictionary.en-US.txt
[ltex_extra] [TRACE 14:29:36] /home/xxx/.config/nvim_test/.repro/plugins/ltex_extra.nvim/lua/ltex_extra/utils/fs.lua:108: Reading  /home/xxx/.config/nvim_test/ltex.dictionary.en-US.txt
[ltex_extra] [TRACE 14:29:36] /home/xxx/.config/nvim_test/.repro/plugins/ltex_extra.nvim/lua/ltex_extra/utils/fs.lua:88: Checking if file uses carriage returns in line feeds
[ltex_extra] [DEBUG 14:29:37] /home/xxx/.config/nvim_test/.repro/plugins/ltex_extra.nvim/lua/ltex_extra/utils/fs.lua:135: { "missspell", "missspell" }
[ltex_extra] [DEBUG 14:29:38] /home/xxx/.config/nvim_test/.repro/plugins/ltex_extra.nvim/lua/ltex_extra/commands-lsp.lua:28: {
[ltex_extra]   ["en-US"] = { "missspell", "missspell" }
[ltex_extra] }

Describe the bug
Dictionary does not get loaded on startup. I can add words to dictionary by code action without any error, and once adding any word, the existing dictionary gets loaded. As you can tell from the logs, there are two "missspell"s in the end.

To Reproduce
Steps to reproduce the behavior:

  1. Your settings for ltex are: minimal init.lua
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs { "config", "data", "state", "cache" } do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system {
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  }
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    "neovim/nvim-lspconfig",
    config = function()
      vim.keymap.set("n", "<C-a>", vim.lsp.buf.code_action)

      require("lspconfig").ltex.setup {
        on_attach = function()
          require("ltex_extra").setup {
            init_check = true,
            path = "",
            log_level = "trace",
          }
        end,
      }
    end,
  },

  {
    "williamboman/mason.nvim",
    opts = {},
  },
  {
    "williamboman/mason-lspconfig",
    dependencies = {
      "williamboman/mason.nvim",
      "neovim/nvim-lspconfig",
    },
    opts = {
      ensure_installed = { "ltex" },
    },
  },
  {
    "barreiroleo/ltex_extra.nvim",
    ft = { "markdown", "tex" },
    dependencies = {
      "neovim/nvim-lspconfig",
      "nvim-lua/plenary.nvim",  -- for logging
    },
  },
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})
  1. tex file and dictionary
.
โ”œโ”€โ”€ ltex.dictionary.en-US.txt
โ””โ”€โ”€ test.tex
  1. See error: dictionary not loaded on startup

Expected behavior
dictionary should be loaded on startup

Screenshots
None

System:

  • Linux
  • Neovim version: 0.9.1 stable
  • LTeX server intallation method: mason
  • ltex_extra version: f32a4ca

Additional context
Nice plugin! Everything works perfectly except the aforementioned issue. I searched and found issue #7 but I don't think it helps. Thanks in advance!

Problems with spanish

I have exactly the same configuration (I also speak Spanish). But I can't get ltex with your plugin to use the spanish language. It works but it always detects English. Do you know what could be the reason?

Global dictionary + project-specific local dictionary?

Hi,

Thanks a lot for the fantastic plugin.

I was wondering if there's a good way to have a global custom dictionary (~/.local/share/ltex/ltex.dictionary.en-US.txt) and a local dictionary file under the root of the current project.
So when I open a file in a specific project and if there's a (for example) .ltex.dictionary.en-US.txt file, ltex would concatenate it with the global dictionary.
I tried pointing path to the global ltex directory and adding ltex.dictionary under settings, but that doesn't seem to work.

Thanks.

Support config path relative to the root directory

Is your feature request related to a problem? Please describe.
I prefer to have one dictionary for all files in a repository. With the current implementation, files in each directory need separate dictionaries.

Describe the solution you'd like
Automatically setting dictionary path relatively to root directory, when it is set.

Describe alternatives you've considered
I used to have the following in my configuration, but after recent changes it stopped working:

local lspconfig = require 'lspconfig'

lspconfig.ltex.setup {
  -- Look for existing `.ltex` directory first. If it doesn't exist,
  -- look for .git/.hg directories. If everything else fails, get absolute
  -- path to the file parent
  root_dir = function(file_path)
    return lspconfig.util.root_pattern('.ltex', '.hg', '.git')(file_path)
      or vim.fn.fnamemodify(file_path, ':p:h')
  end,
  on_attach = function(client, _)
    -- ...
    require('ltex_extra').setup {
      load_langs = { 'en-US', 'pl-PL', },
      path = client.config.root_dir .. '/.ltex',
    }
  end,
}

Now it gives me the following message:

Error executing lua: ...packer/start/ltex-extra.nvim/lua/ltex_extra/utils/fs.lua:53: attempt to ind
ex local 'stat' (a nil value)

It was a workaround anyway, so I would prefer replacing it with a proper solution.

Incorrect buffer for code actions with lspsaga

Describe the bug
As mentioned previously in #7 (comment) ltex_extra throws error catching ltex client when code actions are executed via the lspsaga menu. Is it possible to investigate this further, or add a note to the readme to say that this doesn't work with lspsaga?

ltex_extra fails to attach to server

Describe the bug
When opened, nvim displays five messages reporting "Error catching ltex client", followed by an analogous error message (see screenshots below). However, ltex_extra seems to work as expected on both Markdown and TeX files. The plugin is configured with the default:

require('lspconfig').ltex.setup {
    on_attach = on_attach,
    capabilities = capabilities,
        require('ltex_extra').setup{
            load_langs = { 'it', 'en-US' }, -- table <string> : languages for witch dictionaries will be loaded
            init_check = true, -- boolean : whether to load dictionaries on startup
            path = nil, -- string : path to store dictionaries. Relative path uses current working directory
            log_level = 'trace', -- string : 'none', 'trace', 'debug', 'info', 'warn', 'error', 'fatal'
        }
    ,
    settings = {
        ltex = {
            -- your settings.
        }
    }
}
  • OS Mac Ventura 13.0.1;
  • Nvim version 0.8.1;
  • Ltex-extra installed using Packer;
  • LTeX server installed using Mason;

For completeness, here is also the attach function that I'm using, which is taken from Kickstart.nvim (see link):

local on_attach = function(_, bufnr)

  local nmap = function(keys, func, desc)
    if desc then
      desc = 'LSP: ' .. desc
    end

    vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
  end

  nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
  nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')

  nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition')
  nmap('gi', vim.lsp.buf.implementation, '[G]oto [I]mplementation')
  nmap('gr', require('telescope.builtin').lsp_references)
  nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
  nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')

  -- See `:help K` for why this keymap
  nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
  nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')

  -- Lesser used LSP functionality
  nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
  nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
  nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
  nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
  nmap('<leader>wl', function()
    print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
  end, '[W]orkspace [L]ist Folders')

  -- Create a command `:Format` local to the LSP buffer
  vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
    if vim.lsp.buf.format then
      vim.lsp.buf.format { async = true }
    else
      vim.lsp.buf.formatting()
    end
  end, { desc = 'Format current buffer with LSP' })
end

Screenshot 2022-11-22 at 10 44 05

Screenshot 2022-11-22 at 10 46 31

Handle multiple setup calls

Certain configurations can lead to multiple setup calls that end in errors or exceptions.
If the package is already loaded, it should raise a warning or just reload de plugin. TBD

For reference #51

Can't start plugin

Describe the bug
Plugin errors due to serialization issue

To Reproduce
Steps to reproduce the behavior:

  1. Install plugin
  2. Use default config
  3. Start nvim on a tex file.

Expected behavior
The plugin to start

Screenshots
image

Desktop (please complete the following information):
nvim 0.8 master build

Additional context
With a quick look through the code, I don't see where the issue is.

Use nvim's builtin dictionary

Is your feature request related to a problem? Please describe.
If we enable nvim's built-in spell-checking using set spell, then nvim can save custom words in ~/.config/nvim/spell/en.utf-8.add.

Describe the solution you'd like
A configuration option that would utilize nvim's spell list.

Describe alternatives you've considered
N/A

User dictionary not loaded

Hey thank you for your cool plugin!

Issue

I am able to add words to a user dictionary, but I cannot load them from the dictionary when I restart neovim.
Not sure if your plugin supports loading dictionaries, or not.
As far as I know ltex-ls does not support user dictionaries.

Questions

  1. Does your plugin support the loading of user dictionaries?
  2. If yes, how can I configure it?
  3. If not, do you plan on adding it?

If you need more information or something is not clear, let me know.
Thanks again for your amazing work!

Add command to switch language

At setup, add a command to change the cheched language

Provide a command like

LTextSwitchLang <lang>

with lang autocompletion

I have this in my config

    local function setup_ltex(lang)
      local config = {
        on_attach = function(client, bufnr)
          custom_attach(client, bufnr)
          require('ltex_extra').setup {
            load_langs = { 'en-US', 'fr-FR' },
            -- init_check = true,
            path = vim.fn.stdpath 'config' .. '/spell/dictionaries',
          }
          vim.api.nvim_create_user_command("LtexSwitchLang", function(args)
            local splited_args = vim.split(args.args, " ", {trimemtpy=true})
            setup_ltex(splited_args[1])
          end, { nargs = 1 })
        end,
        settings = {
          ['ltex'] = {
            configurationTarget = {
              dictionary = 'user',
              disabledRules = 'workspaceFolderExternalFile',
              hiddenFalsePositives = 'workspaceFolderExternalFile',
            },
            language = lang,
          },
        },
      }
      require'lspconfig'['ltex'].setup(config)
    end
    setup_ltex('en-US')

It is not perfect but a good starting point as it provides the the Command only when ltex is setup
It does not remove it once ltex dies though,and produce a warning saying that the previous instance of ltex died

Available languages from ltex: https://valentjn.github.io/ltex/settings.html#ltexlanguage

Attempt to index field ltex (nil value)

Describe the bug
An error occurs when initializing buffer with following message:

Attempt to index field ltex (nil value)

It only shows if I don't pass the settings object during the initialization of the LSP.

To Reproduce
Configure lsp in following way:

lspconfig.ltex.setup {
    capabilities = capabilities,
    on_attach = function(client, bufnr)
        require("ltex_extra").setup {
            load_langs = { "pl-PL", "en-US" },
            init_check = true,
            path = "./.dict",
            log_level = "none",
        }
    end
}

and open a file in vim that would trigger ltex to be attached, e.g. .md.
The error shows up.

When I add

    settings = {
        ltex = {
            -- your settings.
        }
    }

to the ltex.setup call the error goes away.

Expected behavior
I think that the error should not happen when not passing the empty settings object.

Screenshots
If applicable, add screenshots to help explain your problem.

System:

  • OS: linux
  • Neovim version: 0.8.1
  • LTeX server intallation method: vim-plug

ltex

Update: fix invalid comments in code snippets

Dictionary diagnostic not working anymore

Describe the bug
Dictionary diagnostic not working anymore, I have no feedback on spelling errors.

To Reproduce
Steps to reproduce the behavior:

  1. Open a markdown file
  2. Write something wrong, like This is not a proper sentejce.
  3. The last word is not marked as wrong.

Expected behavior
sentejce marked as wrong.

Logs

[ERROR][2023-03-06 10:19:47] .../vim/lsp/rpc.lua:734	"rpc"	"ltex-ls"	"stderr"	"Mar 06, 2023 10:19:47 AM org.bsplines.ltexls.server.LtexLanguageServer initialize\nINFO: ltex-ls 15.2.0 - initializing...\n"
[ERROR][2023-03-06 10:19:47] .../vim/lsp/rpc.lua:734	"rpc"	"ltex-ls"	"stderr"	"Mar 06, 2023 10:19:47 AM org.bsplines.ltexls.server.LtexTextDocumentItem raiseExceptionIfCanceled\nFINE: Canceling check due to incoming check request...\n"
[ERROR][2023-03-06 10:19:47] .../vim/lsp/rpc.lua:734	"rpc"	"ltex-ls"	"stderr"	"Mar 06, 2023 10:19:47 AM org.bsplines.ltexls.server.LtexTextDocumentItem raiseExceptionIfCanceled\nFINE: Canceling check due to incoming check request...\nMar 06, 2023 10:19:47 AM org.bsplines.ltexls.server.LtexTextDocumentItem raiseExceptionIfCanceled\nFINE: Canceling check due to incoming check request...\nMar 06, 2023 10:19:47 AM org.bsplines.ltexls.server.LtexTextDocumentItem raiseExceptionIfCanceled\nFINE: Canceling check due to incoming check request...\nMar 06, 2023 10:19:47 AM org.bsplines.ltexls.server.LtexTextDocumentItem raiseExceptionIfCanceled\nFINE: Canceling check due to incoming check request...\nMar 06, 2023 10:19:47 AM org.bsplines.ltexls.server.LtexTextDocumentItem raiseExceptionIfCanceled\nFINE: Canceling check due to incoming check request...\nMar 06, 2023 10:19:47 AM org.bsplines.ltexls.server.LtexTextDocumentItem raiseExceptionIfCanceled\nFINE: Canceling check due to incoming check request...\nMar 06, 2023 10:19:47 AM org.bsplines.ltexls.server.LtexTextDocumentItem raiseExceptionIfCanceled\nFINE: Canceling check due to incoming check request...\nMar 06, 2023 10:19:47 AM org.bsplines.ltexls.server.LtexTextDocumentItem raiseExceptionIfCanceled\nFINE: Canceling check due to incoming check request...\n"
[ERROR][2023-03-06 10:19:47] .../vim/lsp/rpc.lua:734	"rpc"	"ltex-ls"	"stderr"	"Mar 06, 2023 10:19:47 AM org.bsplines.ltexls.server.DocumentChecker logTextToBeChecked\nFINE: Checking the following text in language 'en-US' via LanguageTool: \"dotfiles\\n\\narch\\ni3-gaps\\ntmux\\nnvim\\n\\n\\nThis is not a proper sentejce.\\n\\nHere is one.\\n\"\n"
[ERROR][2023-03-06 10:19:48] .../vim/lsp/rpc.lua:734	"rpc"	"ltex-ls"	"stderr"	"Mar 06, 2023 10:19:48 AM org.bsplines.ltexls.server.DocumentChecker checkAnnotatedTextFragment\nFINE: Obtained 0 rule matches\n"

System:

  • OS: Linux (Arch)
  • Neovim version: nightly
  • LTeX server intallation method: mason

Additional context
Ltex config:

require 'lspconfig'.ltex.setup {
  capabilities = your_capabilities,
  on_attach = function(client, bufnr)
    require("ltex_extra").setup {
      load_langs = { "fr-CH", "en-US", "en-GB" }, -- table <string> : languages for witch dictionaries will be loaded
      init_check = true, -- boolean : whether to load dictionaries on startup
      path = "$HOME/.local/share/nvim/.ltex", -- string : path to store dictionaries. Relative path uses current working directory
      log_level = "trace", -- string : "none", "trace", "debug", "info", "warn", "error", "fatal"
    }
  end,
  settings = {
    ltex = {
    }
  }
}

And if it helps, here are my nvim dotfiles.

Initial check and reload() don't work

Describe the bug
The initial check and reload() doesn't work properly. It can't load my dictionary.
The log has only
[ltex_extra] [TRACE 16:10:07] ~/.local/share/nvim/lazy/ltex-extra.nvim/lua/lt ex_extra/commands-lsp.lua:79: updateConfigFull
then nothing happens, no error or further step.

But it works properly if I make a code action of adding new words.

To Reproduce
Steps to reproduce the behavior:

  1. Your settings for ltex are:
lspconfig.ltex.setup {
  capabilities = capabilities,
  on_attach = function(client, bufnr)
    on_attach(client, bufnr) -- rest of your on_attach process.
    require("ltex_extra").setup {
      load_lang={"en-US",},
      init_check = true,
      path =  "~/.local/share/ltex",
      log_level="trace",
    }
  end,
}

System:

  • OS: Ubuntu
  • Neovim version: 0.9
  • LTeX server intallation method: Mason

Additional context
I used Nvchad to setup .

My ltex rules are being ignored.

Settings

ltex_extra.setup({
    load_langs = { "en-US", "pt-BR" },
    init_check = true,
    path = ".ltex",
    server_opts = {
        capabilities = capabilities,
        settings = {
            ltex = {
                filetypes = { "markdown", "quarto" },
                language = "auto",
                additionalRules = {
                    enablePickyRules = true,
                    motherTongue = "pt-BR",
                },
            },
        },
    },
})

My lsp settings: https://github.com/phrmendes/bkps/blob/popOS/nix/cfg/nvim/lua/plugins/lsp.lua

Describe the bug
After close neovim, ltex ignore previous rules in ltex.disabledRules.*.txt and ltex.hiddenFalsePositives.*.txt. Running more tests, apparently all rules are loaded after using the code action again.

Expected behavior
Load the parameters after reopening the file in neovim.

Screenshots
https://github-production-user-asset-6210df.s3.amazonaws.com/22376151/260316888-b5191c81-d096-4e13-b77c-b0a21ba8900a.mp4

System:

  • OS: Linux
  • Neovim version: v0.9.1
  • LTeX server intallation method: nix-pkgs (v16.0.0)

File system watcher

When manually modifying a ltex file, it would be nice to trigger require"ltex_extra".reload().

Clarify in docs that `load_langs` needs to be specified manually for init_check to work

The README currently claims that load_langs will automatically load "en-US":

load_langs = {}, -- en-US as default

Unfortunately, this does not appear to be the case, at least during the init_check. With the following configuration, my dictionary is only loaded after I apply the "Add to Dictionary" code action (the disabledRules and hiddenFalsePositives files don't get loaded at all, leading to a bunch of duplicate entries in the corresponding files):

lspconfig.ltex.setup({
    capabilities = caps,
    on_attach = function()
        require("ltex_extra").setup({
            init_check = true,
            path = "~/.local/share/ltex",
        })
        require("ltex_extra").init()
    end,
    settings = {
        ltex = {
            language = "en-US",
        },
    },
})

Adding load_langs = { "en-US" } to the ltex_extra setup config fixes these problems.

Since it took me quite a while to get to the bottom of this, I think it would be worthwhile to either treat this as an issue, or to clarify in the docs that the load_langs setting needs to be manually specified.

Commit Hash: 9bed99b
Neovim Version: v0.9.4
ltex-ls version: 16.0.0

ltex_extra with grammar guard

I try ltex_extra with grammar-guard.
Because ltex_extra don't find any ltex server, I'll have to add "grammar_guard" in order ltex_extra can deal with ltex server.
this is the rewrite catch_ltex function :

local function catch_ltex()
    log.trace("catch_ltex")
    local buf_clients = vim.lsp.buf_get_clients()
    local client = nil
    for _, lsp in pairs(buf_clients) do
        if lsp.name == "ltex" or lsp.name == "grammar_guard" then client = lsp end
    end
    return client
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.