Skip to content

Commit 5bbdd8d

Browse files
committed
breaking_change: remove on_attach function
1 parent e6ddf5c commit 5bbdd8d

File tree

2 files changed

+16
-57
lines changed

2 files changed

+16
-57
lines changed

README.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,9 @@ use 'aspeddro/rescript-tools.nvim'
1919

2020
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`.
2121

22-
## Setup
22+
## Usage
2323

2424
```lua
25-
local on_attach = function(client, bufnr)
26-
-- on_attach function will create buffer commands when LSP is attached
27-
require('rescript-tools').on_attach(client, bufnr)
28-
end
29-
3025
--Setup rescript LSP
3126
require'lspconfig'.rescriptls.setup{
3227
-- Using mason.nvim plugin
@@ -37,7 +32,21 @@ require'lspconfig'.rescriptls.setup{
3732
-- '/home/username/path/to/server/out/server.js',
3833
-- '--stdio'
3934
-- }
40-
on_attach = on_attach
35+
on_attach = on_attach,
36+
commands = {
37+
ResOpenCompiled = {
38+
require('rescript-tools').open_compiled,
39+
description = 'Open Compiled JS',
40+
},
41+
ResCreateInterface = {
42+
require('rescript-tools').create_interface,
43+
description = 'Create Interface file',
44+
},
45+
ResSwitchImplInt = {
46+
require('rescript-tools').switch_impl_intf,
47+
description = 'Switch Implementation/Interface',
48+
},
49+
},
4150
}
4251
```
4352

lua/rescript-tools/init.lua

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -173,54 +173,4 @@ M.switch_impl_intf = function(ask)
173173
end
174174
end
175175

176-
---This function can be used to create command when LSP is attached to buffer.
177-
---@param client table LSP client
178-
---@param bufnr number buffer number
179-
---@param opts? { enable: boolean, names: table<string, function> }
180-
---@usage [[
181-
--- -- Default options
182-
--- require('rescript-tools').on_attach(client, bufnr, {
183-
--- commands = {
184-
--- enable = true,
185-
--- names = {
186-
--- ResOpenCompiled = rescript('rescript-tools').open_compiled
187-
--- ResCreateInterface = rescript('rescript-tools').create_interface
188-
--- ResSwitchImplInt = rescript('rescript-tools').switch_impl_intf
189-
--- }
190-
--- }
191-
--- })
192-
--- -- Overriding the command name
193-
--- require('rescript-tools').on_attach(client, bufnr, {
194-
--- commands = {
195-
--- names = {
196-
--- ResOpenJS = rescript('rescript-tools').open_compiled
197-
--- ResCreateInt = rescript('rescript-tools').create_interface
198-
--- ResSwitch = rescript('rescript-tools').switch_impl_intf
199-
--- }
200-
--- }
201-
--- })
202-
---@usage ]]
203-
M.on_attach = function(client, bufnr, opts)
204-
opts = vim.tbl_deep_extend("force", {
205-
commands = {
206-
enable = true,
207-
names = {
208-
ResOpenCompiled = M.open_compiled,
209-
ResCreateInterface = M.create_interface,
210-
ResSwitchImplInt = M.switch_impl_intf,
211-
},
212-
},
213-
}, opts or {})
214-
if client.name == "rescriptls" then
215-
if opts.commands.enable then
216-
for name, fn in pairs(opts.commands.names) do
217-
vim.api.nvim_buf_create_user_command(bufnr, name, fn, {
218-
nargs = 0,
219-
desc = "ReScript: " .. name,
220-
})
221-
end
222-
end
223-
end
224-
end
225-
226176
return M

0 commit comments

Comments
 (0)