Skip to content

Commit

Permalink
Fix issue #1020
Browse files Browse the repository at this point in the history
  • Loading branch information
manateelazycat committed Aug 17, 2024
1 parent 9265149 commit fe7a072
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/handler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ def handle_response(self, request_id, response):
from core.handler.jdtls.jdtls_list_overridable_methods import JdtlsListOverridableMethods # noqa: F401
from core.handler.jdtls.jdtls_add_overridable_methods import JdtlsAddOverridableMethods # noqa: F401
from core.handler.inlay_hint import InlayHint # noqa: F401
from core.handler.semantic_tokens import SemanticTokens # noqa: F401
from core.handler.semantic_tokens import SemanticTokens # noqa: F401
from core.handler.rust_expand_macro import RustExpandMacro # noqa: F401
from core.handler.workspace_diagnostics import WorkspaceDiagnostics # noqa: F401
15 changes: 15 additions & 0 deletions core/handler/rust_expand_macro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from core.handler import Handler
from core.utils import *
from typing import Union

class RustExpandMacro(Handler):
name = "rust_expand_macro"
method = "rust-analyzer/expandMacro"
cancel_on_change = True

def process_request(self, position) -> dict:
self.pos = position
return dict(position=position)

def process_response(self, response: Union[dict, list]) -> None:
eval_in_emacs("lsp-bridge-rust-expand-macro--update", response["name"], response["expansion"])
104 changes: 104 additions & 0 deletions lsp-bridge-rust.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
;;; lsp-bridge-rust.el --- Rust protocol for lsp-bridge -*- lexical-binding: t; -*-

;; Filename: lsp-bridge-rust.el
;; Description: Rust protocol for lsp-bridge
;; Author: Andy Stewart <lazycat.manatee@gmail.com>
;; Maintainer: Andy Stewart <lazycat.manatee@gmail.com>
;; Copyright (C) 2024, Andy Stewart, all rights reserved.
;; Created: 2024-08-17 23:47:41
;; Version: 0.1
;; Last-Updated: 2024-08-17 23:47:41
;; By: Andy Stewart
;; URL: https://www.github.org/manateelazycat/lsp-bridge-rust
;; Keywords:
;; Compatibility: GNU Emacs 31.0.50
;;
;; Features that might be required by this library:
;;
;;
;;

;;; This file is NOT part of GNU Emacs

;;; License
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.

;;; Commentary:
;;
;; Rust protocol for lsp-bridge
;;

;;; Installation:
;;
;; Put lsp-bridge-rust.el to your load-path.
;; The load-path is usually ~/elisp/.
;; It's set in your ~/.emacs like this:
;; (add-to-list 'load-path (expand-file-name "~/elisp"))
;;
;; And the following to your ~/.emacs startup file.
;;
;; (require 'lsp-bridge-rust)
;;
;; No need more.

;;; Customize:
;;
;;
;;
;; All of the above can customize by:
;; M-x customize-group RET lsp-bridge-rust RET
;;

;;; Change log:
;;
;; 2024/08/17
;; * First released.
;;

;;; Acknowledgements:
;;
;;
;;

;;; TODO
;;
;;
;;

;;; Require


;;; Code:

(defun lsp-bridge-rust-expand-macro--update (name expansion)
;; The name is macro name, not project name, you maybe want to replace it
(let ((buf (get-buffer-create (format "*rust macro expansion %s*" name))))
(with-current-buffer buf
(let ((inhibit-read-only t))
(erase-buffer)
(insert expansion)
;; if you use `rust-mode', you should replace fuction
(rust-ts-mode)))
(switch-to-buffer-other-window buf)))

(defun lsp-bridge-rust-expand-macro ()
(interactive)
(lsp-bridge-call-file-api "rust_expand_macro" (lsp-bridge--position)))

(provide 'lsp-bridge-rust)

;;; lsp-bridge-rust.el ends here
1 change: 1 addition & 0 deletions lsp-bridge.el
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
(require 'lsp-bridge-inlay-hint)
(require 'lsp-bridge-dart)
(require 'lsp-bridge-semantic-tokens)
(require 'lsp-bridge-rust)

(defgroup lsp-bridge nil
"LSP-Bridge group."
Expand Down

0 comments on commit fe7a072

Please sign in to comment.