vim-rescript icon indicating copy to clipboard operation
vim-rescript copied to clipboard

Create interface files

Open dkirchhof opened this issue 2 years ago • 1 comments

As this plugin is for neovim AND vim, I don't know, how to manage it. So maybe just for everyones interest, I created a function (for neovim) to automatically create resi files:

function createInterfaceFile()
    local path = vim.api.nvim_buf_get_name(0)

    if vim.fn.filereadable(path .. "i") == 1 then
        print("Interface file already exists")
    else
        -- print("Create interface file")

        vim.lsp.buf_request(
          0, 
          "textDocument/createInterface", 
          { uri = "file://" .. path }, 
          function ()
            print("Interface file created")
          end
        )
    end
end

vim.cmd("command RescriptCreateInterfaceFile lua createInterfaceFile()")

dkirchhof avatar Feb 18 '23 12:02 dkirchhof

I created an emacs lisp function that's the equivalent of this. I'll issue a PR up to rescript-mode although my elisp-fu is not great so it may need some work to handle edge cases.

(defun lsp-rescript--create-interface-from-buffer (buffer)
  (interactive "bFile containing implementation: ")
  (with-current-buffer buffer
    (let ((uri (concat "file://localhost" (buffer-file-name) )))
      (if (lsp-request "textDocument/createInterface"
                       (list
                        :uri uri)
                       )
          (find-file (concat (buffer-file-name) "i" ))
        ())
      )))

Josef-Thorne-A avatar Aug 01 '25 21:08 Josef-Thorne-A