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
735 stars 30 forks source link

langauge server configuration entries should be children of the top-most entry `tinymist` #533

Open Ziqi-Yang opened 2 months ago

Ziqi-Yang commented 2 months ago

Note: I'm not talking about initialization options, but settings.

I have read the tinymist language server configuration doc. It has configuration entries like outputPath directly on the top-most level, i.e.

outputPath
exportPdf
...

However, many other language servers like rust-analyzer, python language server, gopls uses rust-analyzer, pylsp, gopls as the top-most entry of their setting respectively. That's to say:

tinymist
├── outputPath
├── exportPdf
...

Currently, I have to configure Emacs like this to successfully customize Tinymis (though I know I can also specify the initialization option to configure it):

  (setq-default eglot-workspace-configuration
                '(:exportPdf "onSave"))

Instead of this:

(setq-default eglot-workspace-configuration
              '((:pylsp . (:plugins (:ruff (:enabled t))))
                (:tinymist (:exportPdf "onSave"))))

You can see the difference. If I want to customize tinymist, then I need to discard all configurations for other language servers, since eglot-workspace-configuration is directly passed into tinymist as a whole (the following log corresponds to the first one configuration style):

[2024-08-15T06:14:48Z INFO  tinymist::init] preferred theme: None {"exportPdf": String("onSave")}
[2024-08-15T06:14:48Z INFO  tinymist::server] new settings applied

I believe having tinymist as the top-most level configuration entry is meaningful - maybe it enables multiple language servers working?

Myriad-Dreamin commented 2 months ago

Can emacs put entries under tinymist or configure tinymist separately without changing lsp server? Since, for example, neovim retrieve settings per lsp server.

https://github.com/Myriad-Dreamin/tinymist/blob/68911d91cbaea2e9fb91f33df3d803b5b433ee41/editors/neovim/plugins/tinymist.lua#L28-L29

Btw, you can try tinymist.exportPdf, as lsp server requests both xxx and tinymist.xxx at same time.

https://github.com/Myriad-Dreamin/tinymist/blob/68911d91cbaea2e9fb91f33df3d803b5b433ee41/crates/tinymist/src/init.rs#L288-L290

Ziqi-Yang commented 2 months ago

Can emacs put entries under tinymist or configure tinymist separately without changing lsp server?

Emacs have many lsp client implementations, such as eglot, lsp-mode, lsp-bridge and lspce, among which eglot becomes as the official one since Emacs 29.
For eglot, it is not possible to pass configuration separately and specifically to a certain langauge server. It will always pass the value of eglot-workspace-configuration as a whole into the the language server it launched. I think it does this style is because many other language server does make their name as the top-level entry just like namespace.


Btw, you can try tinymist.exportPdf, as lsp server requests both xxx and tinymist.xxx at same time.

This can work (corresponding to exportPdf), but tinymist's configuration pollutes eglot-workspace-configuration

  (setq-default eglot-workspace-configuration
                '(:pylsp (:plugins (:ruff (:enabled t)))
                         :exportPdf "onSave"))

And this is its log:

[stderr]  [2024-08-15T12:29:09Z INFO  tinymist::init] preferred theme: None {"exportPdf": String("onSave"), "pylsp": Object {"plugins": Object {"ruff": Object {"enabled": Bool(true)}}}}
[stderr]  [2024-08-15T12:29:09Z INFO  tinymist::server] new settings applied

But this cannot: (corresponding to tinymist.exportPdf)

  (setq-default eglot-workspace-configuration
                '(
                  :pylsp (:plugins (:ruff (:enabled t)))
                  :tinymist (:exportPdf "onSave")))

And this is its log:

[stderr]  [2024-08-15T12:31:26Z INFO  tinymist::init] preferred theme: None {"pylsp": Object {"plugins": Object {"ruff": Object {"enabled": Bool(true)}}}, "tinymist": Object {"exportPdf": String("onSave")}}
[stderr]  [2024-08-15T12:31:26Z INFO  tinymist::server] new settings applied
Myriad-Dreamin commented 2 months ago

I'm confused because I don't know whether when we add a tinymist section, the neovim users must configure like this:

  -- add tinymist to lspconfig
  {
    ---@class PluginLspOpts
    opts = {
      ---@type lspconfig.options
      servers = {
        tinymist = {
          settings = {
            tinymist = { exportPdf = "onTyped" } 
          }
        },
      },
    },
  },

On the path, tinymist occurs twice.

Ziqi-Yang commented 2 months ago

gopls also have gopls occurs twice (see https://github.com/golang/tools/blob/master/gopls/doc/vim.md#configuration):

local lspconfig = require("lspconfig")
lspconfig.gopls.setup({
  settings = {
    gopls = {
      analyses = {
        unusedparams = true,
      },
      staticcheck = true,
      gofumpt = true,
    },
  },
})

Though I don't think it's mandatory. And there may also be some or many language servers don't use its name as the top-level entry beyond my preliminary investigation.

If you don't like to add an top-level entry/namespace, it's absolutely OK. The reason I propose it is because that setting it in Emacs eglot-workspace-configuration seems awkward. However, I can also change the initial launch argument to make it work too. BTW, I'd like to add a instruction file for using tinymist in Emacs.

Myriad-Dreamin commented 2 months ago

I think of it reasonable to detect whether there is a tinymist section returned from client and merged with rest sections, which should have higher priority. It means the following configuration is totally valid:

settings = {
  tinymist = { exportPdf = "onTyped" } -- priority: high
  'tinymist.exportPdf' = "onTyped" -- priority: middle
  exportPdf = "onTyped" -- priority: low
}

It requires server changes. Three styles look a bit unclear but we can collect all voices for break change. The only thing must be ensured is not to disturb users from other editors.

Myriad-Dreamin commented 2 months ago

The reason I propose it is because that setting it in Emacs eglot-workspace-configuration seems awkward.

Btw, I think it is probably a design defect of eglot-workspace-configuration. Someone (editor or you) may do wrong, but I see the configuration for pylsp is shown in the log which is not needed by tinymist.

Myriad-Dreamin commented 2 months ago

To add README for emacs, you can update this file.

https://github.com/Myriad-Dreamin/tinymist/blob/63ade4f893c05d4134617fdcaa512d74ad4b9f08/scripts/link-docs.mjs#L42-L51

And run:

yarn build:typlite
node .\scripts\link-docs.mjs

If you don't have node runtime, you can just update the script and add a typ file. I'll run the script them.