Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Ziqi-Yang opened this issue Aug 15, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@Ziqi-Yang
Copy link
Contributor

Ziqi-Yang commented Aug 15, 2024

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
Copy link
Owner

Myriad-Dreamin commented Aug 15, 2024

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

--- See [Tinymist Server Configuration](https://github.com/Myriad-Dreamin/tinymist/blob/main/Configuration.md) for references.
settings = {}

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

let sections = CONFIG_ITEMS
.iter()
.flat_map(|item| [format!("tinymist.{item}"), item.to_string()]);

@Ziqi-Yang
Copy link
Contributor Author

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
Copy link
Owner

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
Copy link
Contributor Author

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
Copy link
Owner

Myriad-Dreamin commented Aug 15, 2024

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
Copy link
Owner

Myriad-Dreamin commented Aug 15, 2024

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 Myriad-Dreamin added the enhancement New feature or request label Aug 15, 2024
@Myriad-Dreamin
Copy link
Owner

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

const main = async () => {
await Promise.all([
convert('docs/tinymist/introduction.typ', 'README.md', { before: "# Tinymist\n\n" }),
convert('docs/tinymist/frontend/neovim.typ', 'editors/neovim/README.md', { before: "# Tinymist Neovim Support for Typst\n\n" }),
convert('docs/tinymist/frontend/helix.typ', 'editors/helix/README.md', { before: "# Tinymist Helix Support for Typst\n\n" }),
convert('docs/tinymist/frontend/sublime-text.typ', 'editors/sublime-text/README.md', { before: "# Tinymist Sublime Support for Typst\n\n" }),
convert('docs/tinymist/frontend/vscode.typ', 'editors/vscode/README.md', { before: "# Tinymist Typst VS Code Extension\n\n" }),
convert('docs/tinymist/frontend/zed.typ', 'editors/zed/README.md', { before: "# Tinymist Zed Support for Typst\n\n" }),
])
};

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants