Myriad-Dreamin / tinymist

Tinymist [ˈtaɪni mɪst] is an integrated language service for Typst [taɪpst].
https://myriad-dreamin.github.io/tinymist
Apache License 2.0
748 stars 30 forks source link

Root directory not found, Neovim and Lspconfig #528

Closed pauladam94 closed 2 months ago

pauladam94 commented 2 months ago

Here is my config for the LSP in neovim in init.lua.

  {
    "neovim/nvim-lspconfig",
    dependencies = {
      "kevinhwang91/nvim-ufo",
      { "j-hui/fidget.nvim", opts = {} },
      { "folke/neodev.nvim", opts = {} },
    },
    -- This was an unsuccessful try
    -- opts = {
    --  servers = {
    --    tinymist = {
    --      settings = {
    --        rootPath = "~/PaulJR/",
    --      },
    --    },
    --  },
    --},
      local capabilities = vim.lsp.protocol.make_client_capabilities()
      capabilities = vim.tbl_deep_extend("force", capabilities, require("cmp_nvim_lsp").default_capabilities())

      local lsp_capabilities = require("cmp_nvim_lsp").default_capabilities()

      -- TINYMIST
      require("lspconfig")["tinymist"].setup {
        capabilities = lsp_capabilities,
        settings = {
          tinymist = {
          -- another unsucessfull try
           --  rootPath = "~/PaulJR/",
            settings = {
              rootPath = "~/PaulJR/",
            },
          },
        },
      }
}

In the tinymist docs, for the root path it is indicated to put - for getting the parent directory. Is it the string "-" right ? Just to be sure because I also have tried that but it didn't work.

Here is the result of LspInfo :

 Language client log: /home/pauladam/.local/state/nvim/lsp.log
 Detected filetype:   typst

 0 client(s) attached to this buffer: 

 Other clients that match the filetype: typst

 Config: tinymist
    filetypes:         typst
    root directory:    Not found. -- here is the issue
    cmd:               /run/current-system/sw/bin/tinymist
    cmd is executable: true
    autostart:         true
    custom handlers:   

 Configured servers list: tsserver, clangd, coq_lsp, lua_ls, rust_analyzer, tinymist
➜  ~ tinymist --version
tinymist 
Build Timestamp:     1980-01-01T00:00:00.000000000Z
Build Git Describe:  VERGEN_IDEMPOTENT_OUTPUT
Commit SHA:          VERGEN_IDEMPOTENT_OUTPUT
Commit Date:         None
Commit Branch:       None
Cargo Target Triple: x86_64-unknown-linux-gnu
Typst Version:       0.11.1
➜  ~ tinymist -V
tinymist 0.11.9

Maybe I am doing something obviously wrong, that's why I post this issue. Thank in advance.

pauladam94 commented 2 months ago

I actually managed to make it work. Actually in neovim. Instead of changing the tynimyst parameter rootPath, it is the lspconfig parameter root_dir that should be changed.

This fix my issue :

      require("lspconfig")["tinymist"].setup {
        capabilities = lsp_capabilities,
        root_dir = function(filename, bufnr)
          return "/home/pauladam/PaulJR/" -- this is fixed, but other function can take the parent directory in neovim
        end,
    }

Once you know that, any thing can be given to root_dir parameter.

Myriad-Dreamin commented 2 months ago

Sorry I'm late, I was busy when I first checked your issue. I think of it is a bit unfortunate that there are some unintentional similar keys that are confusing people. But root_dir is a neovim specific configuration. But we could document it to avoid future pitfall.

pauladam94 commented 2 months ago

Just to be sure, it this way that should work to put settings for the tinymist ?

  {
    "neovim/nvim-lspconfig",
    dependencies = {
      "kevinhwang91/nvim-ufo",
      { "j-hui/fidget.nvim", opts = {} },
      { "folke/neodev.nvim", opts = {} },
    },
      local capabilities = vim.lsp.protocol.make_client_capabilities()
      capabilities = vim.tbl_deep_extend("force", capabilities, require("cmp_nvim_lsp").default_capabilities())

      local lsp_capabilities = require("cmp_nvim_lsp").default_capabilities()

      require("lspconfig")["tinymist"].setup {
        capabilities = lsp_capabilities,
        root_dir = function(filename, bufnr)
              return "the right root_dire depending on filename..."
          end
        settings = {
          tinymist = {
            settings = {
              formatterMode = "typstfmt",
            },
          },
        },
      }
    }
Myriad-Dreamin commented 2 months ago

I don't see obvious errors in your posted code.

FahimAnayet commented 2 months ago
root_dir = function(filename, bufnr)
           return vim.fn.getcwd()
           end,

This is much more dynamic. But this may change the workspace every time :(