Skip to content

Commit b8dc079

Browse files
authored
feat: Add action-handlers for code-lens provided ruby-lsp-rails (#4522)
1 parent 854ff72 commit b8dc079

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

clients/lsp-ruby-lsp.el

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,35 @@
4343
(if lsp-ruby-lsp-use-bundler '("bundle" "exec"))
4444
'("ruby-lsp")))
4545

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+
4667
(lsp-register-client
4768
(make-lsp-client
4869
:new-connection (lsp-stdio-connection #'lsp-ruby-lsp--build-command)
4970
:activation-fn (lsp-activate-on "ruby")
5071
: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))
5175
:server-id 'ruby-lsp-ls))
5276

5377
(lsp-consistency-check lsp-ruby-lsp)

0 commit comments

Comments
 (0)