valentjn / ltex-ls

LTeX Language Server: LSP language server for LanguageTool :mag::heavy_check_mark: with support for LaTeX :mortar_board:, Markdown :pencil:, and others
https://valentjn.github.io/ltex
Mozilla Public License 2.0
764 stars 33 forks source link

Add support for Typst #249

Open HiramTheHero opened 1 year ago

HiramTheHero commented 1 year ago

Is your feature request related to a problem? Please describe. Typst is another typesetting system that is pleasant to use.

Describe the solution you'd like It would be great if Ltex-ls added support for typst files.

To my understanding the file endings are .typ.

DashieTM commented 1 year ago

Some more info, the file endings are varied, I personally use .typst as .typ can be confused with other file types. @HiramTheHero For now you can add the filetype to your lspconfig:

          filetypes = {
            "bib",
            "gitcommit",
            "markdown",
            "org",
            "plaintex",
            "rst",
            "rnoweb",
            "tex",
            "pandoc",
            "typst",
          },

Also make sure to add filetype detection for whatever file-ending you are using.

The only thing in terms of support is ignoring the typst functions as the spell checking is obviously not going to be different from other languages.

Dioprz commented 1 year ago

@DashieTM

The only thing in terms of support is ignoring the typst functions

Do you know of any way to achieve this? Can languagetool or ltex-ls be configured to do it?

DashieTM commented 1 year ago

Yes you can add typst, but I am personally not familiar with it. Here is the current selection that is supported, my assumption is that you can just extend this. https://github.com/valentjn/ltex-ls/tree/develop/src/main/kotlin/org/bsplines/ltexls/parsing

Idobenhamo commented 11 months ago

Any updates on that?

foxyseta commented 7 months ago

Well, there is a good treesitter parser for typst, but it is in treesitter: https://github.com/uben0/tree-sitter-typst. I think it is a pity that ltex-ls interally implements in Kotlin ad-hoc parsers for each supported language. It means all of these parsers for different languages need to be actively maintained.

foxyseta commented 7 months ago

Some more info, the file endings are varied, I personally use .typst as .typ can be confused with other file types. @HiramTheHero For now you can add the filetype to your lspconfig:

          filetypes = {
            "bib",
            "gitcommit",
            "markdown",
            "org",
            "plaintex",
            "rst",
            "rnoweb",
            "tex",
            "pandoc",
            "typst",
          },

Also make sure to add filetype detection for whatever file-ending you are using.

The only thing in terms of support is ignoring the typst functions as the spell checking is obviously not going to be different from other languages.

Did not work for me, the LSP buffer does not show as attached to the buffer, so there is no log to check in the first place. I am installing ltex-ls from Mason and am on neovim using nvim-lspconfig.

HiramTheHero commented 7 months ago

Some more info, the file endings are varied, I personally use .typst as .typ can be confused with other file types. @HiramTheHero For now you can add the filetype to your lspconfig:

          filetypes = {
            "bib",
            "gitcommit",
            "markdown",
            "org",
            "plaintex",
            "rst",
            "rnoweb",
            "tex",
            "pandoc",
            "typst",
          },

Also make sure to add filetype detection for whatever file-ending you are using. The only thing in terms of support is ignoring the typst functions as the spell checking is obviously not going to be different from other languages.

Did not work for me, the LSP buffer does not show as attached to the buffer, so there is no log to check in the first place. I am installing ltex-ls from Mason and am on neovim using nvim-lspconfig.

I've had the same issues before. I've never been able to get ltex-ls to work properly with typst files through the normal init.lua config options. I've always had to go into ~/.local/share/nvim/site/pack/packer/start/nvim-lspconfig/lua/lspconfig/server_configurations/ltex.lua (that's the path on MacOS if you use Packer) and add typst to the local filetypes = { part of the file. So, for example, mine looks like the following:

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

Hopefully that can get it working for your Neovim config.

foxyseta commented 7 months ago

Thanks! This worked for me, too. Hopefully project maintainers can also help on this.

tapyu commented 4 months ago

For those who are using Helix, you can use the following config in languages.toml

[[language]]
name = "typst"
language-servers = ["grammar"]

[language-server.grammar-lsp]
command = "ltex-ls"
HiramTheHero commented 3 months ago

For those on neovim, see https://github.com/neovim/nvim-lspconfig/issues/3186#issuecomment-2153597383 for a cleaner way to set things up. I've attached the comment below. This works perfect with my neovim config.

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" },
    }
  }
})
wucke13 commented 3 months ago

For those who are using Helix, you can use the following config in languages.toml

[[language]]
name = "typst"
language-servers = ["grammar"]

[language-server.grammar-lsp]
command = "ltex-ls"

I belive there is a small error, the language server name in [[languages]] must matche the on in [lanauge-server], i. e. the following worked for me:

[[language]]
name = "typst"
language-servers = ["typst-lsp", "grammar-lsp"]

[language-server.grammar-lsp]
command = "ltex-ls"