neovim / nvim-lspconfig

Quickstart configs for Nvim LSP
Apache License 2.0
9.98k stars 2.04k forks source link

Ltex not able to recognize other file formats through user config options #3186

Closed HiramTheHero closed 1 month ago

HiramTheHero commented 1 month ago

Description

Hello all,

Thank you for working on this software. It is excellent.

ltex is supposed to be able to scan other filetypes through its ltex.enabled configuration option. I haven't been able to get this work without modifying the default config file. I've been trying to extend ltex to activate on a file with a .typ ending (which indicates a typst file).

Note that, in my situation, the typst file format is added through the typst.vim package. This is the code for it using lazy.nvim

{ 'kaarmu/typst.vim',   ft = { 'typst' }, lazy = false },

My init.lua has the following config options for ltex:

local lspconfig = require("lspconfig")

lspconfig.ltex.setup({
  settings = {
    ltex = {
      enabled = { "latex", "typst", "typ", "bib", "markdown", "plaintex", "tex" },
      language = { "en-US", "es" },
      setenceCacheSize = 2000,
      additionalRules = {
        enablePickyRules = true,
        motherTongue = "en-US",
        languageModel = '/Users/user/.local/apps/language_tool_ngram'
      },
      checkFrequency = "edit"
    }
  }
})

Whenever I go to a file with a .typ extension (for a typst file), the ltex LSP doesn't get started. The only way I've found to fix this is to add typst to the filetypes section within the default config located at ~/.local/share/nvim/lazy/nvim-lspconfig/lua/lspconfig/server_configurations/ltex.lua

To clarify, I change this:

local filetypes = {
  'bib',
  'gitcommit',
  'markdown',
  'org',
  'plaintex',
  'rst',
  'rnoweb',
  'tex',
  'pandoc',
  'quarto',
  'rmd',
  'context',
  'html',
  'xhtml',
  'mail',
  'text',
}

To this:

local filetypes = {
  'typst', -- typst is added here.
  'bib',
  'gitcommit',
  'markdown',
  'org',
  'plaintex',
  'rst',
  'rnoweb',
  'tex',
  'pandoc',
  'quarto',
  'rmd',
  'context',
  'html',
  'xhtml',
  'mail',
  'text',
}

It would be nice to enable different files through just the user options. Every time I update nvim-lspconfig I have to re-add the 'typst' entry in the base config file.

I apologize if my explanation is confusing. I'm happy to clarify if needed.

chrisgrieser commented 1 month ago

It's a bit unintuitive at first, but the problem is that settings.ltex.enabled only tell ltex which filetypes to check, but not nvim. What happens here is not really a bug, you just need to tell nvim-lspconfig when to startup ltex by adding typst to the list of filetypes.

The server_configurations/ltex.lua file you manually edited basically does that, but you can do that already more simply in the setup call like this:

local lspconfig = require("lspconfig")
lspconfig.ltex.setup({
  filetypes = { "latex", "typst", "typ", "bib", "markdown", "plaintex", "tex" }, --  <-- add this
  settings = {
    ltex = {
      enabled = { "latex", "typst", "typ", "bib", "markdown", "plaintex", "tex" },
    }
  }
})
HiramTheHero commented 1 month ago

Ah! I see. This works perfectly with my config as well. Thank you so much!