|
43 | 43 | (if lsp-ruby-lsp-use-bundler '("bundle" "exec"))
|
44 | 44 | '("ruby-lsp")))
|
45 | 45 |
|
| 46 | +(defun lsp-ruby-lsp--open-file (arg_hash) |
| 47 | + "Open a file. This function is for code-lens provided by ruby-lsp-rails." |
| 48 | + (let* ((arguments (gethash "arguments" arg_hash)) |
| 49 | + (uri (aref (aref arguments 0) 0)) |
| 50 | + (path-with-line-number (split-string (lsp--uri-to-path uri) "#L")) |
| 51 | + (path (car path-with-line-number)) |
| 52 | + (line-number (cadr path-with-line-number))) |
| 53 | + (find-file path) |
| 54 | + (when line-number (forward-line (1- (string-to-number line-number)))))) |
| 55 | + |
| 56 | +(defun lsp-ruby-lsp--run-test (arg_hash) |
| 57 | + "Run a test file. This function is for code-lens provided by ruby-lsp-rails." |
| 58 | + (let* ((arguments (gethash "arguments" arg_hash)) |
| 59 | + (command (aref arguments 2)) |
| 60 | + (default-directory (lsp-workspace-root)) |
| 61 | + (buffer-name "*run test results*") |
| 62 | + (buffer (progn |
| 63 | + (when (get-buffer buffer-name) (kill-buffer buffer-name)) |
| 64 | + (generate-new-buffer buffer-name)))) |
| 65 | + (async-shell-command command buffer))) |
| 66 | + |
46 | 67 | (lsp-register-client
|
47 | 68 | (make-lsp-client
|
48 | 69 | :new-connection (lsp-stdio-connection #'lsp-ruby-lsp--build-command)
|
49 | 70 | :activation-fn (lsp-activate-on "ruby")
|
50 | 71 | :priority -2
|
| 72 | + :action-handlers (ht ("rubyLsp.openFile" #'lsp-ruby-lsp--open-file) |
| 73 | + ("rubyLsp.runTest" #'lsp-ruby-lsp--run-test) |
| 74 | + ("rubyLsp.runTestInTerminal" #'lsp-ruby-lsp--run-test)) |
51 | 75 | :server-id 'ruby-lsp-ls))
|
52 | 76 |
|
53 | 77 | (lsp-consistency-check lsp-ruby-lsp)
|
|
0 commit comments