Skip to content

Commit

Permalink
Fix issue #739, support closing label protocol of Dart.
Browse files Browse the repository at this point in the history
  • Loading branch information
manateelazycat committed Oct 15, 2023
1 parent cd38348 commit 574f977
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 1 deletion.
3 changes: 3 additions & 0 deletions core/fileaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ def try_push_diagnostics(self, ticker):
if ticker == self.diagnostics_ticker:
eval_in_emacs("lsp-bridge-diagnostic--render", self.filepath, get_lsp_file_host(), self.get_diagnostics())

def record_dart_closing_lables(self, labels):
eval_in_emacs("lsp-bridge-dart-closing-labels--render", self.filepath, get_lsp_file_host(), labels)

def push_code_actions(self, actions, server_name, action_kind):
log_time("Record actions from '{}' for file {}".format(server_name, os.path.basename(self.filepath)))
self.code_actions[server_name] = actions
Expand Down
5 changes: 5 additions & 0 deletions core/lspserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,11 @@ def handle_recv_message(self, message: dict):
if self.enable_diagnostics and is_in_path_dict(self.files, filepath):
get_from_path_dict(self.files, filepath).record_diagnostics(message["params"]["diagnostics"], self.server_info["name"])

if "method" in message and message["method"] == "dart/textDocument/publishClosingLabels":
filepath = uri_to_path(message["params"]["uri"])
if is_in_path_dict(self.files, filepath):
get_from_path_dict(self.files, filepath).record_dart_closing_lables(message["params"]["labels"])

# Notice user if got error message from lsp server.
if "method" in message and message["method"] == "window/logMessage":
try:
Expand Down
5 changes: 4 additions & 1 deletion langserver/dart-analysis-server.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"--client-id",
"emacs.lsp-bridge"
],
"settings": {}
"settings": {},
"initializationOptions": {
"closingLabels": true
}
}
123 changes: 123 additions & 0 deletions lsp-bridge-dart.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
;;; lsp-bridge-dart.el --- Dart protocol -*- lexical-binding: t; -*-

;; Filename: lsp-bridge-dart.el
;; Description: Dart protocol
;; Author: Andy Stewart <[email protected]>
;; Maintainer: Andy Stewart <[email protected]>
;; Copyright (C) 2023, Andy Stewart, all rights reserved.
;; Created: 2023-10-03 21:35:08
;; Version: 0.1
;; Last-Updated: 2023-10-03 21:35:08
;; By: Andy Stewart
;; URL: https://www.github.org/manateelazycat/lsp-bridge-dart
;; Keywords:
;; Compatibility: GNU Emacs 30.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:
;;
;; Dart protocol
;;

;;; Installation:
;;
;; Put lsp-bridge-dart.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-dart)
;;
;; No need more.

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

;;; Change log:
;;
;; 2023/10/03
;; * First released.
;;

;;; Acknowledgements:
;;
;;
;;

;;; TODO
;;
;;
;;

;;; Require


;;; Code:

(defface lsp-bridge-dart-closing-label-face
`((t :foreground "#aaaaaa"))
"Face for dart closing tab."
:group 'lsp-bridge-dart)

(defvar-local lsp-bridge-dart-closing-label-overlays '())

(defun lsp-bridge-dart-hide-closing-label-overlays ()
(when lsp-bridge-dart-closing-label-overlays
(dolist (dart-overlay lsp-bridge-dart-closing-label-overlays)
(delete-overlay dart-overlay)))

(setq-local lsp-bridge-dart-closing-label-overlays nil))

(defun lsp-bridge-dart-closing-labels--render (filepath filehost closing-labels)
(lsp-bridge--with-file-buffer
filepath filehost
;; Hide previous overlays first.
(lsp-bridge-dart-hide-closing-label-overlays)

;; Render new overlays.
(save-excursion
(save-restriction
(dolist (closing-label closing-labels)
(let* ((label (plist-get closing-label :label))
(range (plist-get closing-label :range))
(end (plist-get range :end)))
(goto-char (acm-backend-lsp-position-to-point end))
(let* ((overlay (make-overlay (point) (1+ (point)) nil t)))
(overlay-put overlay 'before-string (propertize label 'face 'lsp-bridge-dart-closing-label-face))
(overlay-put overlay 'evaporate t) ; NOTE, `evaporate' is import
(push overlay lsp-bridge-dart-closing-label-overlays)
)))))))

(provide 'lsp-bridge-dart)

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

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

0 comments on commit 574f977

Please sign in to comment.