From 5bbdd8ddeafbbf2938d84ec21d1c493fccf77c83 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sat, 4 Mar 2023 00:31:26 -0300 Subject: [PATCH] breaking_change: remove on_attach function --- README.md | 23 +++++++++++------ lua/rescript-tools/init.lua | 50 ------------------------------------- 2 files changed, 16 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 6ad57cf..f8f83bd 100644 --- a/README.md +++ b/README.md @@ -19,14 +19,9 @@ use 'aspeddro/rescript-tools.nvim' The [rescript-vscode](https://github.com/rescript-lang/rescript-vscode) plugin contains a language server than can be power other editors. I recommend using [mason.nvim](https://github.com/williamboman/mason.nvim) to install the language server. It will download the `vsix` file from the latest stable release and add it to the Neovim `PATH` as `rescript-lsp`. -## Setup +## Usage ```lua -local on_attach = function(client, bufnr) - -- on_attach function will create buffer commands when LSP is attached - require('rescript-tools').on_attach(client, bufnr) -end - --Setup rescript LSP require'lspconfig'.rescriptls.setup{ -- Using mason.nvim plugin @@ -37,7 +32,21 @@ require'lspconfig'.rescriptls.setup{ -- '/home/username/path/to/server/out/server.js', -- '--stdio' -- } - on_attach = on_attach + on_attach = on_attach, + commands = { + ResOpenCompiled = { + require('rescript-tools').open_compiled, + description = 'Open Compiled JS', + }, + ResCreateInterface = { + require('rescript-tools').create_interface, + description = 'Create Interface file', + }, + ResSwitchImplInt = { + require('rescript-tools').switch_impl_intf, + description = 'Switch Implementation/Interface', + }, + }, } ``` diff --git a/lua/rescript-tools/init.lua b/lua/rescript-tools/init.lua index cc3177a..d2d56ff 100644 --- a/lua/rescript-tools/init.lua +++ b/lua/rescript-tools/init.lua @@ -173,54 +173,4 @@ M.switch_impl_intf = function(ask) end end ----This function can be used to create command when LSP is attached to buffer. ----@param client table LSP client ----@param bufnr number buffer number ----@param opts? { enable: boolean, names: table } ----@usage [[ ---- -- Default options ---- require('rescript-tools').on_attach(client, bufnr, { ---- commands = { ---- enable = true, ---- names = { ---- ResOpenCompiled = rescript('rescript-tools').open_compiled ---- ResCreateInterface = rescript('rescript-tools').create_interface ---- ResSwitchImplInt = rescript('rescript-tools').switch_impl_intf ---- } ---- } ---- }) ---- -- Overriding the command name ---- require('rescript-tools').on_attach(client, bufnr, { ---- commands = { ---- names = { ---- ResOpenJS = rescript('rescript-tools').open_compiled ---- ResCreateInt = rescript('rescript-tools').create_interface ---- ResSwitch = rescript('rescript-tools').switch_impl_intf ---- } ---- } ---- }) ----@usage ]] -M.on_attach = function(client, bufnr, opts) - opts = vim.tbl_deep_extend("force", { - commands = { - enable = true, - names = { - ResOpenCompiled = M.open_compiled, - ResCreateInterface = M.create_interface, - ResSwitchImplInt = M.switch_impl_intf, - }, - }, - }, opts or {}) - if client.name == "rescriptls" then - if opts.commands.enable then - for name, fn in pairs(opts.commands.names) do - vim.api.nvim_buf_create_user_command(bufnr, name, fn, { - nargs = 0, - desc = "ReScript: " .. name, - }) - end - end - end -end - return M