diff options
Diffstat (limited to 'configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251')
14 files changed, 2577 insertions, 0 deletions
diff --git a/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-autoloads.el b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-autoloads.el new file mode 100644 index 000000000000..2ec1da5e3d40 --- /dev/null +++ b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-autoloads.el @@ -0,0 +1,32 @@ +;;; lsp-ui-autoloads.el --- automatically extracted autoloads +;; +;;; Code: +(add-to-list 'load-path (directory-file-name (or (file-name-directory #$) (car load-path)))) + +;;;### (autoloads nil "lsp-ui" "lsp-ui.el" (23428 20493 246694 908000)) +;;; Generated autoloads from lsp-ui.el + +(autoload 'lsp-ui-mode "lsp-ui" "\ +Toggle language server UI mode on or off. +‘lsp-ui-mode’ is a minor mode that contains a series of useful UI +integrations for ‘lsp-mode’. With a prefix argument ARG, enable +language server UI mode if ARG is positive, and disable it +otherwise. If called from Lisp, enable the mode if ARG is +omitted or nil, and toggle it if ARG is ‘toggle’. + +\(fn &optional ARG)" t nil) + +;;;*** + +;;;### (autoloads nil nil ("lsp-ui-doc.el" "lsp-ui-flycheck.el" "lsp-ui-imenu.el" +;;;;;; "lsp-ui-peek.el" "lsp-ui-pkg.el" "lsp-ui-sideline.el") (23428 +;;;;;; 20493 250920 356000)) + +;;;*** + +;; Local Variables: +;; version-control: never +;; no-byte-compile: t +;; no-update-autoloads: t +;; End: +;;; lsp-ui-autoloads.el ends here diff --git a/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-doc.el b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-doc.el new file mode 100644 index 000000000000..e31d10663171 --- /dev/null +++ b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-doc.el @@ -0,0 +1,651 @@ +;;; lsp-ui-doc.el --- Lsp-Ui-Doc -*- lexical-binding: t -*- + +;; Copyright (C) 2017 Sebastien Chapuis + +;; Author: Sebastien Chapuis <sebastien@chapu.is> +;; URL: https://github.com/emacs-lsp/lsp-ui +;; Keywords: lsp, ui + +;;; 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: +;; +;; Show documentation of the symbol at point in a child frame + +;;; Code: + +(require 'lsp-mode) +(require 'dash) +(require 'dash-functional) +(require 'markdown-mode) + +(defgroup lsp-ui-doc nil + "Display informations of the current line." + :group 'tools + :group 'convenience + :group 'lsp-ui + :link '(custom-manual "(lsp-ui-doc) Top") + :link '(info-link "(lsp-ui-doc) Customizing")) + +(defcustom lsp-ui-doc-enable t + "Whether or not to enable lsp-ui-doc." + :type 'boolean + :group 'lsp-ui) + +(defcustom lsp-ui-doc-header nil + "Whether or not to enable the header which display the symbol string." + :type 'boolean + :group 'lsp-ui-doc) + +(defcustom lsp-ui-doc-include-signature nil + "Whether or not to include the object signature/type in the frame." + :type 'boolean + :group 'lsp-ui-doc) + +(defcustom lsp-ui-doc-position 'top + "Where to display the doc." + :type '(choice (const :tag "Top" top) + (const :tag "Bottom" bottom) + (const :tag "At point" at-point)) + :group 'lsp-ui-doc) + +(defcustom lsp-ui-doc-border "white" + "Border color of the frame." + :type 'color + :group 'lsp-ui-doc) + +(defcustom lsp-ui-doc-max-width 150 + "Maximum number of columns of the frame." + :type 'integer + :group 'lsp-ui-doc) + +(defcustom lsp-ui-doc-max-height 30 + "Maximum number of lines in the frame." + :type 'integer + :group 'lsp-ui-doc) + +(defcustom lsp-ui-doc-use-childframe t + "Whether to display documentation in a child-frame or the current frame. +Child frames requires GNU/Emacs version >= 26 and graphical frames." + :type 'boolean + :group 'lsp-ui-doc) + +(defface lsp-ui-doc-background + '((((background light)) :background "#b3b3b3") + (t :background "#272A36")) + "Background color of the documentation. +Only the `background' is used in this face." + :group 'lsp-ui-doc) + +(defface lsp-ui-doc-header + '((t :foreground "black" + :background "deep sky blue")) + "Face used on the header." + :group 'lsp-ui-doc) + +(defface lsp-ui-doc-url + '((t :inherit link)) + "Face used on links." + :group 'lsp-ui-doc) + +(defvar lsp-ui-doc-frame-parameters + '((left . -1) + (no-accept-focus . t) + (no-focus-on-map . t) + (min-width . 0) + (width . 0) + (min-height . 0) + (height . 0) + (internal-border-width . 1) + (vertical-scroll-bars . nil) + (horizontal-scroll-bars . nil) + (right-fringe . 0) + (menu-bar-lines . 0) + (tool-bar-lines . 0) + (line-spacing . 0) + (unsplittable . t) + (undecorated . t) + (top . -1) + (visibility . nil) + (mouse-wheel-frame . nil) + (no-other-frame . t) + (cursor-type . nil) + (inhibit-double-buffering . t) + (drag-internal-border . t) + (no-special-glyphs . t) + (desktop-dont-save . t)) + "Frame parameters used to create the frame.") + +(defvar lsp-ui-doc-render-function nil + "Function called to format the documentation. +The function takes a string as parameter and should return a string. +If this variable is nil (the default), the documentation will be rendered +as markdown.") + +(defvar lsp-ui-doc-custom-markup-modes + '((rust-mode "no_run" "rust,no_run" "rust,ignore" "rust,should_panic")) + "Mode to uses with markdown code blocks. +They are added to `markdown-code-lang-modes'") + +(defvar lsp-ui-doc-frame-hook nil + "Hooks run on child-frame creation. +The functions receive 2 parameters: the frame and its window.") + +(defvar-local lsp-ui-doc--bounds nil) +(defvar-local lsp-ui-doc--string-eldoc nil) + +(declare-function lsp-ui-sideline--get-renderer 'lsp-ui-sideline) + +;; Avoid warning with emacs < 26 +(declare-function display-buffer-in-child-frame "window.el") + +(defvar-local lsp-ui-doc--parent-vars nil + "Variables from the parents frame that we want to access in the child. +Because some variables are buffer local.") + +(defvar-local lsp-ui-doc--inline-ov nil + "Overlay used to display the documentation in the buffer.") + +(defmacro lsp-ui-doc--with-buffer (&rest body) + "Execute BODY in the lsp-ui-doc buffer." + `(let ((parent-vars (list :buffer (current-buffer) + :window (get-buffer-window) + :workspace-root (when lsp--cur-workspace + (lsp--workspace-root lsp--cur-workspace))))) + (with-current-buffer (get-buffer-create (lsp-ui-doc--make-buffer-name)) + (setq lsp-ui-doc--parent-vars parent-vars) + (prog1 (let ((buffer-read-only nil)) + ,@body) + (setq buffer-read-only t))))) + +(defmacro lsp-ui-doc--get-parent (var) + "Return VAR in `lsp-ui-doc--parent-vars'." + `(plist-get lsp-ui-doc--parent-vars ,var)) + +(defmacro lsp-ui-doc--set-frame (frame) + "Set the frame parameter ‘lsp-ui-doc-frame’ to FRAME." + `(set-frame-parameter nil 'lsp-ui-doc-frame ,frame)) + +(defmacro lsp-ui-doc--get-frame () + "Return the child frame." + `(frame-parameter nil 'lsp-ui-doc-frame)) + +(defun lsp-ui-doc--make-buffer-name () + "Construct the buffer name, it should be unique for each frame." + (concat " *lsp-ui-doc-" + (or (frame-parameter nil 'window-id) + (frame-parameter nil 'name)) + "*")) + +(defun lsp-ui-doc--set-eldoc (marked-string) + (when marked-string + (let ((string (lsp-ui-doc--extract-marked-string marked-string))) + (setq lsp-ui-doc--string-eldoc string)))) + +(defun lsp-ui-doc--eldoc (&rest _) + (when (and (lsp--capability "documentHighlightProvider") + lsp-highlight-symbol-at-point) + (lsp-symbol-highlight)) + lsp-ui-doc--string-eldoc) + +;; ‘markdown-fontify-code-block-default-mode’ isn’t yet available in +;; Markdown 2.3. +(defvar markdown-fontify-code-block-default-mode) + +(defun lsp-ui-doc--setup-markdown (mode) + "Setup the ‘markdown-mode’ in the frame. +MODE is the mode used in the parent frame." + (make-local-variable 'markdown-code-lang-modes) + (dolist (mark (alist-get mode lsp-ui-doc-custom-markup-modes)) + (add-to-list 'markdown-code-lang-modes (cons mark mode))) + (setq-local markdown-fontify-code-blocks-natively t) + (setq-local markdown-fontify-code-block-default-mode mode) + (setq-local markdown-hide-markup t)) + +(defun lsp-ui-doc--extract-marked-string (marked-string) + "Render the MARKED-STRING." + (string-trim-right + (let* ((string (if (stringp marked-string) + marked-string + (gethash "value" marked-string))) + (with-lang (hash-table-p marked-string)) + (language (and with-lang (gethash "language" marked-string))) + (render-fn (if with-lang (lsp-ui-sideline--get-renderer language) + (and (functionp lsp-ui-doc-render-function) + lsp-ui-doc-render-function))) + (mode major-mode)) + (if render-fn + (funcall render-fn string) + (with-temp-buffer + (insert string) + (delay-mode-hooks + (let ((inhibit-message t)) + (funcall (cond ((and with-lang (string= "text" language)) 'text-mode) + ((fboundp 'gfm-view-mode) 'gfm-view-mode) + (t 'markdown-mode)))) + (when (derived-mode-p 'markdown-mode) + (lsp-ui-doc--setup-markdown mode)) + (ignore-errors + (font-lock-ensure))) + (buffer-string)))))) + +(defun lsp-ui-doc--filter-marked-string (list-marked-string) + (let ((groups (--separate (and (hash-table-p it) + (lsp-ui-sideline--get-renderer (gethash "language" it))) + list-marked-string))) + (lsp-ui-doc--set-eldoc (caar groups)) + (if lsp-ui-doc-include-signature + list-marked-string + (cadr groups)))) + +(defun lsp-ui-doc--extract (contents) + "Extract the documentation from CONTENTS. +CONTENTS can be differents type of values: +MarkedString | MarkedString[] | MarkupContent (as defined in the LSP). +We don't extract the string that `lps-line' is already displaying." + (when contents + (cond + ((stringp contents) contents) + ((listp contents) ;; MarkedString[] + (mapconcat 'lsp-ui-doc--extract-marked-string + (lsp-ui-doc--filter-marked-string contents) + "\n\n" + ;; (propertize "\n\n" 'face '(:height 0.4)) + )) + ((gethash "kind" contents) (gethash "value" contents)) ;; MarkupContent + ((gethash "language" contents) ;; MarkedString + (lsp-ui-doc--extract-marked-string contents))))) + +(defun lsp-ui-doc--make-request () + "Request the documentation to the LS." + (when (and (bound-and-true-p lsp--cur-workspace) + (not (bound-and-true-p lsp-ui-peek-mode))) + (if (symbol-at-point) + (let ((bounds (bounds-of-thing-at-point 'symbol))) + (unless (equal lsp-ui-doc--bounds bounds) + (lsp--send-request-async (lsp--make-request "textDocument/hover" + (lsp--text-document-position-params)) + (lambda (hover) + (lsp-ui-doc--callback hover bounds (current-buffer)) + )))) + (setq lsp-ui-doc--string-eldoc nil) + (lsp-ui-doc--hide-frame)))) + +(defun lsp-ui-doc--callback (hover bounds buffer) + "Process the received documentation. +HOVER is the doc returned by the LS. +BOUNDS are points of the symbol that have been requested. +BUFFER is the buffer where the request has been made." + (if (and hover + (lsp--point-is-within-bounds-p (car bounds) (cdr bounds)) + (equal buffer (current-buffer))) + (let ((doc (lsp-ui-doc--extract (gethash "contents" hover)))) + (setq lsp-ui-doc--bounds bounds) + (lsp-ui-doc--display (thing-at-point 'symbol t) doc)) + (setq lsp-ui-doc--string-eldoc nil) + (lsp-ui-doc--hide-frame))) + +(defun lsp-ui-doc--hide-frame () + "Hide the frame." + (setq lsp-ui-doc--bounds nil) + (when (overlayp lsp-ui-doc--inline-ov) + (delete-overlay lsp-ui-doc--inline-ov)) + (when (lsp-ui-doc--get-frame) + (lsp-ui-doc--with-buffer + (erase-buffer)) + (make-frame-invisible (lsp-ui-doc--get-frame)))) + +(defun lsp-ui-doc--buffer-width () + "Calcul the max width of the buffer." + (lsp-ui-doc--with-buffer + (save-excursion + (let ((max 0)) + (goto-char (point-min)) + (while (not (eobp)) + (let* ((len (- (line-end-position) (line-beginning-position)))) + (when (> len max) + (setq max len))) + (forward-line 1)) + max)))) + +(defun lsp-ui-doc--line-height (&optional line) + "Return the pos-y of the LINE on screen, in pixel." + (nth 2 (or (window-line-height line) + (and (redisplay t) + (window-line-height line))))) + +(defun lsp-ui-doc--sideline-pos-y () + (-> (when (bound-and-true-p lsp-ui-sideline--occupied-lines) + (-min lsp-ui-sideline--occupied-lines)) + (line-number-at-pos) + (lsp-ui-doc--line-height))) + +(defun lsp-ui-doc--resize-buffer () + "If the buffer's width is larger than the current frame, resize it." + (let* ((frame-width (frame-width)) + (fill-column (min lsp-ui-doc-max-width (- frame-width 5)))) + (when (> (lsp-ui-doc--buffer-width) (min lsp-ui-doc-max-width frame-width)) + (lsp-ui-doc--with-buffer + (fill-region (point-min) (point-max)))))) + +(defun lsp-ui-doc--next-to-side-window-p nil + "Return non-nil if the window on the left is a side window." + (let* ((win (window-at 0 0)) + (left (window-left (selected-window)))) + (and (not (eq win (selected-window))) + (or (not left) (eq win left)) + (eq (window-parameter win 'window-side) 'left)))) + +(defun lsp-ui-doc--mv-at-point (frame height start-x start-y) + "Move the FRAME at point. +HEIGHT is the child frame height. +START-X is the position x of the current window. +START-Y is the position y of the current window." + (-let* (((x . y) (--> (bounds-of-thing-at-point 'symbol) + (nth 2 (posn-at-point (car it))))) + (mode-line-y (lsp-ui-doc--line-height 'mode-line)) + (char-height (frame-char-height)) + (y (or (and (> y (/ mode-line-y 2)) + (<= (- mode-line-y y) (+ char-height height)) + (> (- y height) 0) + (- y height)) + (+ y char-height)))) + (set-frame-position frame (+ x start-x) (+ y start-y)))) + +(defun lsp-ui-doc--move-frame (frame) + "Place our FRAME on screen." + (lsp-ui-doc--resize-buffer) + (-let* (((left top _right _bottom) (window-edges nil nil nil t)) + (window (frame-root-window frame)) + ((width . height) (window-text-pixel-size window nil nil 10000 10000 t)) + (width (+ width (* (frame-char-width frame) 1))) ;; margins + (char-h (frame-char-height)) + (height (min (- (* lsp-ui-doc-max-height char-h) (/ char-h 2)) height)) + (frame-resize-pixelwise t)) + (set-frame-size frame width height t) + (if (eq lsp-ui-doc-position 'at-point) + (lsp-ui-doc--mv-at-point frame height left top) + (set-frame-position frame + (if (and (>= left (+ width 10 (frame-char-width))) + (not (lsp-ui-doc--next-to-side-window-p))) + 10 + (- (frame-pixel-width) width 10 (frame-char-width))) + (pcase lsp-ui-doc-position + ('top (+ top 10)) + ('bottom (- (lsp-ui-doc--line-height 'mode-line) + height + 10))))))) + +(defun lsp-ui-doc--visit-file (filename) + "Visit FILENAME in the parent frame." + (-some->> (find-file-noselect filename) + (set-window-buffer (lsp-ui-doc--get-parent :window)))) + +(defun lsp-ui-doc--put-click (bounds fn) + "Add text properties on text to make it clickable. +The text delimiters are BOUNDS. +FN is the function to call on click." + (let ((map (make-sparse-keymap))) + (define-key map [down-mouse-1] fn) + (put-text-property (car bounds) (cdr bounds) 'keymap map) + (put-text-property (car bounds) (cdr bounds) 'mouse-face + (list :inherit 'lsp-ui-doc-url + :box (list :line-width -1 + :color (face-foreground 'lsp-ui-doc-url)))) + (add-face-text-property (car bounds) (cdr bounds) 'lsp-ui-doc-url))) + +(defun lsp-ui-doc--make-clickable-link () + "Find paths and urls in the buffer and make them clickable." + (goto-char (point-min)) + (save-excursion + (while (not (eobp)) + ;;; TODO: + ;;; Search path in the whole buffer. + ;;; For now, it searches only on beginning of lines. + (-when-let* ((filename (thing-at-point 'filename)) + (path (if (file-readable-p filename) filename + (let ((full (concat (lsp-ui-doc--get-parent :workspace-root) + filename))) + (and (file-readable-p full) + full))))) + (lsp-ui-doc--put-click (or (bounds-of-thing-at-point 'filename) + (bounds-of-thing-at-point 'url)) + (lambda () (interactive) + (lsp-ui-doc--visit-file path)))) + (forward-line 1)) + (goto-char (point-min)) + (condition-case nil + (while (search-forward-regexp "http[s]?://") + (lsp-ui-doc--put-click (or (thing-at-point-bounds-of-url-at-point) + (bounds-of-thing-at-point 'filename)) + 'browse-url-at-mouse)) + (search-failed nil)))) + +(defun lsp-ui-doc--render-buffer (string symbol) + "Set the buffer with STRING." + (lsp-ui-doc--with-buffer + (erase-buffer) + (let ((inline-p (lsp-ui-doc--inline-p))) + (insert (concat (unless inline-p (propertize "\n" 'face '(:height 0.2))) + (-> (replace-regexp-in-string "`\\([\n]+\\)" "" string) + (string-trim-right)) + (unless inline-p (propertize "\n\n" 'face '(:height 0.3)))))) + (lsp-ui-doc--make-clickable-link) + (setq-local face-remapping-alist `((header-line lsp-ui-doc-header))) + (setq-local window-min-height 1) + (setq header-line-format (when lsp-ui-doc-header (concat " " symbol)) + mode-line-format nil + cursor-type nil))) + +(defun lsp-ui-doc--inline-height () + (lsp-ui-doc--with-buffer + (length (split-string (buffer-string) "\n")))) + +(defun lsp-ui-doc--remove-invisibles (string) + "Remove invisible characters in STRING." + (let* ((start (text-property-not-all 0 (length string) 'invisible nil string))) + (while start + (setq string (concat (substring string 0 start) + (-some->> (next-single-property-change start 'invisible string) + (substring string)))) + (setq start (text-property-not-all 0 (length string) 'invisible nil string))) + string)) + +(defvar-local lsp-ui-doc--inline-width nil) + +(defun lsp-ui-doc--inline-window-width nil + (- (min (window-text-width) + (window-body-width)) + (if (bound-and-true-p display-line-numbers-mode) + (+ 2 (line-number-display-width)) + 0) + 1)) + +(defun lsp-ui-doc--inline-zip (s1 s2) + (let* ((width (lsp-ui-doc--inline-window-width)) + (max-s1 (- width lsp-ui-doc--inline-width 2))) + (truncate-string-to-width + (concat (truncate-string-to-width s1 max-s1 nil ?\s) s2) + width nil ?\s))) + +(defun lsp-ui-doc--inline-padding (string len) + (let ((string (concat " " string (make-string (- len (string-width string)) ?\s) " "))) + (add-face-text-property 0 (length string) (list :background (face-background 'lsp-ui-doc-background nil t)) t string) + string)) + +(defun lsp-ui-doc--inline-faking-frame (doc-strings) + (let* ((len-max (-max-by '> (-map 'string-width doc-strings)))) + (setq lsp-ui-doc--inline-width len-max) + (--map (lsp-ui-doc--inline-padding it len-max) doc-strings))) + +(defun lsp-ui-doc--inline-untab (string) + (replace-regexp-in-string "\t" (make-string tab-width ?\s) string nil t)) + +(defun lsp-ui-doc--inline-merge (strings) + (let* ((buffer-strings (-> (lsp-ui-doc--inline-untab strings) + (lsp-ui-doc--remove-invisibles) + (split-string "\n"))) + (doc-strings (-> (lsp-ui-doc--with-buffer (buffer-string)) + (lsp-ui-doc--inline-untab) + (lsp-ui-doc--remove-invisibles) + (split-string "\n"))) + (merged (--> (lsp-ui-doc--inline-faking-frame doc-strings) + (-zip-with 'lsp-ui-doc--inline-zip buffer-strings it) + (string-join it "\n") + (concat it "\n")))) + (add-face-text-property 0 (length merged) 'default t merged) + merged)) + +(defun lsp-ui-doc--inline-pos-at (start lines) + "Calcul the position at START + forward n LINES." + (save-excursion (goto-char start) + (forward-line lines) + (point))) + +(defun lsp-ui-doc--inline-pos (height) + "Return a cons of positions where to place the doc. +HEIGHT is the documentation number of lines." + (let* ((w-start (window-start)) + (w-end (lsp-ui-doc--inline-pos-at w-start (window-body-height))) + (ov-end (lsp-ui-doc--inline-pos-at w-start height))) + (cond + ;; Display on top ? + ((< (lsp-ui-doc--inline-pos-at ov-end 1) (point)) + (cons w-start ov-end)) + ;; Display at the bottom ? + ((>= (lsp-ui-doc--inline-pos-at w-end (- height)) + (lsp-ui-doc--inline-pos-at (point) 2)) + (cons (lsp-ui-doc--inline-pos-at w-end (- height)) + w-end)) + ;; The doc is too long to display it fixed to the bottom ? + ;; Then display 2 lines after `point' + ;; The end of the documentation won't be visible in the window + (t (cons (lsp-ui-doc--inline-pos-at (point) 2) + (lsp-ui-doc--inline-pos-at (point) (+ height 2))))))) + +(defun lsp-ui-doc--inline () + "Display the doc in the buffer." + (-let* ((height (lsp-ui-doc--inline-height)) + ((start . end) (lsp-ui-doc--inline-pos height)) + (buffer-string (buffer-substring start end)) + (ov (if (overlayp lsp-ui-doc--inline-ov) lsp-ui-doc--inline-ov + (setq lsp-ui-doc--inline-ov (make-overlay start end))))) + (move-overlay ov start end) + (overlay-put ov 'display (lsp-ui-doc--inline-merge buffer-string)) + (overlay-put ov 'lsp-ui-doc-inline t) + (overlay-put ov 'window (selected-window)))) + +(defun lsp-ui-doc--inline-p () + "Return non-nil when the documentation should be display without a child frame." + (or (not lsp-ui-doc-use-childframe) + (not (display-graphic-p)) + (not (fboundp 'display-buffer-in-child-frame)))) + +(defun lsp-ui-doc--display (symbol string) + "Display the documentation." + (if (or (null string) (string-empty-p string)) + (lsp-ui-doc--hide-frame) + (lsp-ui-doc--render-buffer string symbol) + (if (lsp-ui-doc--inline-p) + (lsp-ui-doc--inline) + (unless (frame-live-p (lsp-ui-doc--get-frame)) + (lsp-ui-doc--set-frame (lsp-ui-doc--make-frame))) + (lsp-ui-doc--move-frame (lsp-ui-doc--get-frame)) + (unless (frame-visible-p (lsp-ui-doc--get-frame)) + (make-frame-visible (lsp-ui-doc--get-frame)))))) + +(defun lsp-ui-doc--make-frame () + "Create the child frame and return it." + (lsp-ui-doc--delete-frame) + (let* ((after-make-frame-functions nil) + (before-make-frame-hook nil) + (name-buffer (lsp-ui-doc--make-buffer-name)) + (buffer (get-buffer name-buffer)) + (params (append lsp-ui-doc-frame-parameters + `((default-minibuffer-frame . ,(selected-frame)) + (minibuffer . ,(minibuffer-window)) + (left-fringe . ,(frame-char-width)) + (background-color . ,(face-background 'lsp-ui-doc-background nil t))))) + (window (display-buffer-in-child-frame + buffer + `((child-frame-parameters . ,params)))) + (frame (window-frame window))) + (set-frame-parameter nil 'lsp-ui-doc-buffer buffer) + (set-window-dedicated-p window t) + (redirect-frame-focus frame (frame-parent frame)) + (set-face-background 'internal-border lsp-ui-doc-border frame) + (run-hook-with-args 'lsp-ui-doc-frame-hook frame window) + frame)) + +(defun lsp-ui-doc--delete-frame () + "Delete the child frame if it exists." + (-when-let (frame (lsp-ui-doc--get-frame)) + (delete-frame frame) + (lsp-ui-doc--set-frame nil))) + +(defadvice select-window (after lsp-ui-doc--select-window activate) + "Delete the child frame if window changes." + (unless (equal (ad-get-arg 0) (selected-window)) + (lsp-ui-doc--hide-frame))) + +(advice-add 'load-theme :before (lambda (&rest _) (lsp-ui-doc--delete-frame))) +(add-hook 'window-configuration-change-hook #'lsp-ui-doc--hide-frame) + +(defun lsp-ui-doc-enable-eldoc () + (setq-local eldoc-documentation-function 'lsp-ui-doc--eldoc)) + +(defun lsp-ui-doc--on-delete (frame) + "Function called when a FRAME is deleted." + (-some--> (frame-parameter frame 'lsp-ui-doc-buffer) + (get-buffer it) + (and (buffer-live-p it) it) + (kill-buffer it))) + +(define-minor-mode lsp-ui-doc-mode + "Minor mode for showing hover information in child frame." + :init-value nil + :group lsp-ui-doc + (cond + (lsp-ui-doc-mode + (progn + (with-eval-after-load 'frameset + ;; The documentation frame can’t be properly restored. Especially + ;; ‘desktop-save’ will misbehave and save a bogus string "Unprintable + ;; entity" in the desktop file. Therefore we have to prevent + ;; ‘frameset-save’ from saving the parameter. + (unless (assq 'lsp-ui-doc-frame frameset-filter-alist) + ;; Copy the variable first. See the documentation of + ;; ‘frameset-filter-alist’ for explanation. + (cl-callf copy-tree frameset-filter-alist) + (push '(lsp-ui-doc-frame . :never) frameset-filter-alist))) + (add-hook 'lsp-after-open-hook 'lsp-ui-doc-enable-eldoc nil t) + (add-hook 'post-command-hook 'lsp-ui-doc--make-request nil t) + (add-hook 'delete-frame-functions 'lsp-ui-doc--on-delete nil t))) + (t + (remove-hook 'delete-frame-functions 'lsp-ui-doc--on-delete t) + (remove-hook 'post-command-hook 'lsp-ui-doc--make-request t) + (remove-hook 'lsp-after-open-hook 'lsp-ui-doc-enable-eldoc t) + (setq-local eldoc-documentation-function 'lsp--on-hover)))) + +(defun lsp-ui-doc-enable (enable) + "Enable/disable ‘lsp-ui-doc-mode’. +It is supposed to be called from `lsp-ui--toggle'" + (lsp-ui-doc-mode (if enable 1 -1))) + +(provide 'lsp-ui-doc) +;;; lsp-ui-doc.el ends here diff --git a/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-doc.elc b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-doc.elc new file mode 100644 index 000000000000..c4bd81782506 --- /dev/null +++ b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-doc.elc Binary files differdiff --git a/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-flycheck.el b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-flycheck.el new file mode 100644 index 000000000000..d6397d074026 --- /dev/null +++ b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-flycheck.el @@ -0,0 +1,235 @@ +;;; lsp-ui-flycheck.el --- Flycheck support for lsp-mode -*- lexical-binding: t; -*- + +;; Copyright (C) 2017 fmdkdd +;; URL: https://github.com/emacs-lsp/lsp-ui +;; Keywords: lsp, ui + +;; 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 of the License, 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. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Flycheck integration for lsp-mode. To enable, put this in your config: +;; (require 'lsp-ui-flycheck) +;; (with-eval-after-load 'lsp-mode +;; (add-hook 'lsp-after-open-hook (lambda () (lsp-ui-flycheck-enable 1)))) + +;;; Code: + +(require 'lsp-notifications) +(require 'lsp-mode) +(require 'flycheck) +(require 'pcase) +(require 'dash) + +(defgroup lsp-ui-flycheck nil + "The LSP extension to display syntax checking." + :group 'tools + :group 'convenience + :group 'lsp-ui + :link '(custom-manual "(lsp-ui-flycheck) Top") + :link '(info-link "(lsp-ui-flycheck) Customizing")) + +(defcustom lsp-ui-flycheck-enable t + "Whether or not to enable ‘lsp-ui-flycheck’." + :type 'boolean + :group 'lsp-ui) + +(defcustom lsp-ui-flycheck-live-reporting t + "If non-nil, diagnostics in buffer will be reported as soon as possible. +Typically, on every keystroke. +If nil, diagnostics will be reported according to `flycheck-check-syntax-automatically'." + :type 'boolean + :group 'lsp-ui-flycheck) + +(defcustom lsp-ui-flycheck-list-position 'bottom + "Position where `lsp-ui-flycheck-list' will show diagnostics for the whole workspace." + :type '(choice (const :tag "Bottom" bottom) + (const :tag "Right" right)) + :group 'lsp-ui-flycheck) + +(defvar-local lsp-ui-flycheck-list--buffer nil) + +(defun lsp-ui-flycheck-list--post-command () + (when (eobp) + (forward-line -1))) + +(defun lsp-ui-flycheck-list--update (window workspace) + (let ((buffer-read-only nil) + (lsp--cur-workspace workspace)) + (erase-buffer) + (remove-overlays) + (maphash (lambda (file diagnostic) + (when diagnostic + (overlay-put + (make-overlay (point) (point)) + 'after-string + (concat (propertize "\n" 'face '(:height 0.2)) + (propertize (lsp-ui--workspace-path file) + 'face 'dired-directory) + (propertize "\n" 'face '(:height 0.2))))) + (dolist (diag diagnostic) + (let* ((message (or (lsp-diagnostic-message diag) "???")) + (severity (or (lsp-diagnostic-severity diag) 1)) + (line (or (lsp-diagnostic-line diag) 1)) + (face (cond ((= severity 1) 'error) + ((= severity 2) 'warning) + (t 'success))) + (text (concat (propertize (number-to-string line) 'face face) + ": " + (car (split-string message "\n"))))) + (add-text-properties 0 (length text) `(diag ,diag file ,file window ,window) text) + (insert (concat text "\n"))))) + lsp--diagnostics)) + (if (= (point) 1) + (overlay-put (make-overlay 1 1) + 'after-string "No diagnostic available\n") + (goto-char 1)) + (lsp-ui-flycheck-list-mode)) + +(defun lsp-ui-flycheck-list () + "List all the diagnostics in the whole workspace." + (interactive) + (let ((buffer (get-buffer-create "*lsp-diagnostics*")) + (workspace lsp--cur-workspace) + (window (selected-window))) + (with-current-buffer buffer + (lsp-ui-flycheck-list--update window workspace)) + (add-hook 'lsp-after-diagnostics-hook 'lsp-ui-flycheck-list--refresh nil t) + (setq lsp-ui-flycheck-list--buffer buffer) + (let ((win (display-buffer-in-side-window + buffer `((side . ,lsp-ui-flycheck-list-position) (slot . 5) (window-width . 0.20))))) + (set-window-dedicated-p win t) + (select-window win) + (fit-window-to-buffer nil nil 10)))) + +(defun lsp-ui-flycheck-list--refresh () + (let ((workspace lsp--cur-workspace) + (current-window (selected-window))) + (when (and (buffer-live-p lsp-ui-flycheck-list--buffer) + (get-buffer-window lsp-ui-flycheck-list--buffer) + workspace) + (with-selected-window (get-buffer-window lsp-ui-flycheck-list--buffer) + (lsp-ui-flycheck-list--update current-window workspace) + (fit-window-to-buffer nil nil 10))))) + +(defun lsp-ui-flycheck-list--open () + (-when-let* ((diag (get-text-property (point) 'diag)) + (file (get-text-property (point) 'file)) + (window (get-text-property (point) 'window)) + (line (lsp-diagnostic-line diag)) + (column (lsp-diagnostic-column diag)) + (marker (with-current-buffer + (or (get-file-buffer file) + (find-file-noselect file)) + (save-restriction + (widen) + (save-excursion + (goto-char 1) + (forward-line line) + (forward-char column) + (point-marker)))))) + (set-window-buffer window (marker-buffer marker) t) + (with-selected-window window + (goto-char marker) + (recenter) + (pulse-momentary-highlight-one-line (marker-position marker) 'next-error)) + window)) + +(defun lsp-ui-flycheck-list--view () + (interactive) + (lsp-ui-flycheck-list--open)) + +(defun lsp-ui-flycheck-list--visit () + (interactive) + (select-window (lsp-ui-flycheck-list--open))) + +(defun lsp-ui-flycheck-list--quit () + (interactive) + (kill-buffer)) + +(defvar lsp-ui-flycheck-list-mode-map nil + "Keymap for ‘lsp-ui-flycheck-list-mode’.") +(unless lsp-ui-flycheck-list-mode-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "q") 'lsp-ui-flycheck-list--quit) + (define-key map (kbd "<return>") 'lsp-ui-flycheck-list--view) + (define-key map (kbd "<M-return>") 'lsp-ui-flycheck-list--visit) + (setq lsp-ui-flycheck-list-mode-map map))) + +(define-derived-mode lsp-ui-flycheck-list-mode special-mode "lsp-ui-flycheck-list" + "Mode showing flycheck diagnostics for the whole workspace." + (setq truncate-lines t) + (setq mode-line-format nil) + (add-hook 'post-command-hook 'lsp-ui-flycheck-list--post-command nil t)) + +(defun lsp-ui-flycheck--start (checker callback) + "Start an LSP syntax check with CHECKER. + +CALLBACK is the status callback passed by Flycheck." + ;; Turn all errors from lsp--diagnostics for the current buffer into + ;; flycheck-error objects and pass them immediately to the callback + (let ((errors)) + (dolist (diag (or (gethash buffer-file-name lsp--diagnostics) + (gethash (file-truename buffer-file-name) lsp--diagnostics))) + (push (flycheck-error-new + :buffer (current-buffer) + :checker checker + :filename buffer-file-name + :line (1+ (lsp-diagnostic-line diag)) + :column (1+ (lsp-diagnostic-column diag)) + :message (lsp-diagnostic-message diag) + :level (pcase (lsp-diagnostic-severity diag) + (1 'error) + (2 'warning) + (_ 'info)) + :id (lsp-diagnostic-code diag)) + errors)) + (funcall callback 'finished errors))) + +(flycheck-define-generic-checker 'lsp-ui + "A syntax checker using the Language Server Protocol (RLS) +provided by lsp-mode. + +See https://github.com/emacs-lsp/lsp-mode." + :start #'lsp-ui-flycheck--start + :modes '(python-mode) ; Need a default mode + :predicate (lambda () lsp-mode) + :error-explainer (lambda (e) (flycheck-error-message e))) + +(defun lsp-ui-flycheck-add-mode (mode) + "Add MODE as a valid major mode for the lsp checker." + (unless (flycheck-checker-supports-major-mode-p 'lsp-ui mode) + (flycheck-add-mode 'lsp-ui mode))) + +(defun lsp-ui-flycheck--report nil + (and flycheck-mode + lsp-ui-flycheck-live-reporting + (flycheck-buffer))) + +;; FIXME: Provide a way to disable lsp-ui-flycheck +(defun lsp-ui-flycheck-enable (_) + "Enable flycheck integration for the current buffer." + (when lsp-ui-flycheck-live-reporting + (setq-local flycheck-check-syntax-automatically nil)) + (setq-local flycheck-checker 'lsp-ui) + (lsp-ui-flycheck-add-mode major-mode) + (add-to-list 'flycheck-checkers 'lsp-ui) + (add-hook 'lsp-after-diagnostics-hook 'lsp-ui-flycheck--report nil t)) + +;; lsp-ui.el loads lsp-ui-flycheck.el, so we can’t ‘require’ lsp-ui. +;; FIXME: Remove this cyclic dependency. +(declare-function lsp-ui--workspace-path "lsp-ui" (path)) + +(provide 'lsp-ui-flycheck) +;;; lsp-ui-flycheck.el ends here diff --git a/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-flycheck.elc b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-flycheck.elc new file mode 100644 index 000000000000..e34b41764817 --- /dev/null +++ b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-flycheck.elc Binary files differdiff --git a/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-imenu.el b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-imenu.el new file mode 100644 index 000000000000..d7005e878e2b --- /dev/null +++ b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-imenu.el @@ -0,0 +1,241 @@ +;;; lsp-ui-imenu.el --- Lsp-Ui-Imenu -*- lexical-binding: t -*- + +;; Copyright (C) 2018 Sebastien Chapuis + +;; Author: Sebastien Chapuis <sebastien@chapu.is> +;; URL: https://github.com/emacs-lsp/lsp-ui +;; Keywords: lsp, ui + +;;; 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: +;; +;; Show imenu entries +;; Call the function `lsp-ui-imenu' +;; +;; (define-key lsp-ui-mode-map (kbd "C-c l") 'lsp-ui-imenu) +;; + +;;; Code: + +(require 'lsp-mode) +(require 'lsp-imenu) +(require 'dash) + +(defgroup lsp-ui-imenu nil + "Display imenu entries." + :group 'tools + :group 'convenience + :group 'lsp-ui + :link '(custom-manual "(lsp-ui-imenu) Top") + :link '(info-link "(lsp-ui-imenu) Customizing")) + +(defcustom lsp-ui-imenu-enable t + "Whether or not to enable ‘lsp-ui-imenu’." + :type 'boolean + :group 'lsp-ui) + +(defcustom lsp-ui-imenu-kind-position 'top + "Where to show the entries kind." + :type '(choice (const :tag "Top" top) + (const :tag "Left" left)) + :group 'lsp-ui-imenu) + +(defcustom lsp-ui-imenu-colors '("deep sky blue" "green3") + "Color list to cycle through for entry groups." + :type '(repeat color) + :group 'lsp-ui-menu) + +(declare-function imenu--make-index-alist 'imenu) +(declare-function imenu--subalist-p 'imenu) +(defvar imenu--index-alist) + +(defun lsp-ui-imenu--pad (s len color &optional no-bar) + (let ((n (- len (length s)))) + (propertize (concat (make-string n ?\s) s (unless no-bar " ┃ ")) + 'face `(:foreground ,color)))) + +(defun lsp-ui-imenu--get-color (index) + (nth (mod index (length lsp-ui-imenu-colors)) lsp-ui-imenu-colors)) + +(defun lsp-ui-imenu--make-line (title index padding entry color-index) + (let* ((color (lsp-ui-imenu--get-color color-index)) + (prefix (if (and (= index 0) (eq lsp-ui-imenu-kind-position 'left)) title " ")) + (text (concat (lsp-ui-imenu--pad prefix padding color) + (propertize (car entry) 'face 'default) + "\n")) + (len (length text))) + (add-text-properties 0 len `(index ,index title ,title marker ,(cdr entry) padding ,padding) text) + text)) + +(defvar-local lsp-ui-imenu-ov nil) + +(defun lsp-ui-imenu--make-ov nil + (or (and (overlayp lsp-ui-imenu-ov) lsp-ui-imenu-ov) + (setq lsp-ui-imenu-ov (make-overlay 1 1)))) + +(defun lsp-ui-imenu--post-command nil + (when (eobp) + (forward-line -1)) + (-when-let (padding (get-char-property (point) 'padding)) + (goto-char (+ 3 (line-beginning-position) padding))) + (when (eq lsp-ui-imenu-kind-position 'left) + (save-excursion + (when (overlayp lsp-ui-imenu-ov) + (overlay-put lsp-ui-imenu-ov 'display nil)) + (redisplay) + (goto-char (window-start)) + (if (not (= (get-text-property (point) 'index) 0)) + (let* ((ov (lsp-ui-imenu--make-ov)) + (padding (get-text-property (point) 'padding)) + (title (get-text-property (point) 'title)) + (text (buffer-substring (+ (line-beginning-position) padding) (line-end-position)))) + (move-overlay ov (line-beginning-position) (line-end-position)) + (overlay-put ov 'display `(string ,(concat (let ((n (- padding (length title)))) + (propertize (concat (make-string n ?\s) title))) + text)))) + (when (overlayp lsp-ui-imenu-ov) + (delete-overlay lsp-ui-imenu-ov)))))) + +(defvar lsp-ui-imenu--origin nil) + +(defun lsp-ui-imenu--put-separator nil + (let ((ov (make-overlay (point) (point)))) + (overlay-put ov 'after-string (propertize "\n" 'face '(:height 0.6))))) + +(defun lsp-ui-imenu--put-kind (title padding color-index) + (when (eq lsp-ui-imenu-kind-position 'top) + (let ((ov (make-overlay (point) (point))) + (color (lsp-ui-imenu--get-color color-index))) + (overlay-put + ov 'after-string + (concat (lsp-ui-imenu--pad " " padding color t) + "\n" + title + (propertize "\n" 'face '(:height 1))))))) + +(defun lsp-ui-imenu nil + (interactive) + (setq lsp-ui-imenu--origin (current-buffer)) + (imenu--make-index-alist) + (let ((list imenu--index-alist)) + (with-current-buffer (get-buffer-create "*lsp-ui-imenu*") + (let* ((padding (or (and (eq lsp-ui-imenu-kind-position 'top) 1) + (--> (-filter 'imenu--subalist-p list) + (--map (length (car it)) it) + (-max (or it '(1)))))) + (grouped-by-subs (-partition-by 'imenu--subalist-p list)) + (color-index 0) + buffer-read-only) + (remove-overlays) + (erase-buffer) + (lsp-ui-imenu--put-separator) + (dolist (group grouped-by-subs) + (if (imenu--subalist-p (car group)) + (dolist (kind group) + (-let* (((title . entries) kind)) + (lsp-ui-imenu--put-kind title padding color-index) + (--each-indexed entries + (insert (lsp-ui-imenu--make-line title it-index padding it color-index))) + (lsp-ui-imenu--put-separator) + (setq color-index (1+ color-index)))) + (--each-indexed group + (insert (lsp-ui-imenu--make-line " " it-index padding it color-index))) + (lsp-ui-imenu--put-separator) + (setq color-index (1+ color-index)))) + (lsp-ui-imenu-mode) + (setq mode-line-format '(:eval (lsp-ui-imenu--win-separator))) + (goto-char 1) + (add-hook 'post-command-hook 'lsp-ui-imenu--post-command nil t) + )) + (let ((win (display-buffer-in-side-window (get-buffer "*lsp-ui-imenu*") '((side . right)))) + (fit-window-to-buffer-horizontally t)) + (set-window-margins win 1) + (select-window win) + (set-window-start win 1) + (set-window-dedicated-p win t) + (let ((fit-window-to-buffer-horizontally 'only)) + (fit-window-to-buffer win)) + (window-resize win 3 t)))) + +(defun lsp-ui-imenu--win-separator () + (when (and (window-combined-p) + (window-next-sibling) + (= (window-bottom-divider-width) 0)) + (propertize (make-string (window-total-width) ?\─) 'face 'window-divider))) + +(defun lsp-ui-imenu--kill nil + (interactive) + (kill-buffer-and-window)) + +(defun lsp-ui-imenu--jump (direction) + (let ((current (get-text-property (point) 'title))) + (forward-line direction) + (while (and current + (not (= (line-number-at-pos) 1)) + (equal current (get-text-property (point) 'title))) + (forward-line direction)))) + +(defun lsp-ui-imenu--next-kind nil + (interactive) + (lsp-ui-imenu--jump 1)) + +(defun lsp-ui-imenu--prev-kind nil + (interactive) + (lsp-ui-imenu--jump -1) + (while (not (= (get-text-property (point) 'index) 0)) + (forward-line -1))) + +(defun lsp-ui-imenu--visit nil + (interactive) + (let ((marker (get-text-property (point) 'marker))) + (select-window (get-buffer-window lsp-ui-imenu--origin)) + (goto-char marker) + (pulse-momentary-highlight-one-line (point) 'next-error))) + +(defun lsp-ui-imenu--view nil + (interactive) + (let ((marker (get-text-property (point) 'marker))) + (with-selected-window (get-buffer-window lsp-ui-imenu--origin) + (goto-char marker) + (recenter) + (pulse-momentary-highlight-one-line (point) 'next-error)))) + +(defvar lsp-ui-imenu-mode-map nil + "Keymap for ‘lsp-ui-peek-mode’.") +(unless lsp-ui-imenu-mode-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "q") 'lsp-ui-imenu--kill) + (define-key map (kbd "<right>") 'lsp-ui-imenu--next-kind) + (define-key map (kbd "<left>") 'lsp-ui-imenu--prev-kind) + (define-key map (kbd "<return>") 'lsp-ui-imenu--view) + (define-key map (kbd "<M-return>") 'lsp-ui-imenu--visit) + (setq lsp-ui-imenu-mode-map map))) + +(define-derived-mode lsp-ui-imenu-mode special-mode "lsp-ui-imenu" + "Mode showing imenu entries.") + +(defun lsp-ui-imenu-enable (enable) + (if enable + (lsp-enable-imenu) + (when (eq imenu-create-index-function 'lsp--imenu-create-index) + (setq imenu-create-index-function + 'imenu-default-create-index-function)))) + +(provide 'lsp-ui-imenu) +;;; lsp-ui-imenu.el ends here diff --git a/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-imenu.elc b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-imenu.elc new file mode 100644 index 000000000000..d351a80ddf0d --- /dev/null +++ b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-imenu.elc Binary files differdiff --git a/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-peek.el b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-peek.el new file mode 100644 index 000000000000..f9823b8d0f73 --- /dev/null +++ b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-peek.el @@ -0,0 +1,731 @@ +;;; lsp-ui-peek.el --- Lsp-Ui-Peek -*- lexical-binding: t -*- + +;; Copyright (C) 2017 Sebastien Chapuis + +;; Author: Sebastien Chapuis <sebastien@chapu.is> +;; URL: https://github.com/emacs-lsp/lsp-ui +;; Keywords: lsp, ui +;; Version: 0.0.1 + +;;; 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: +;; +;; Load this file and execute `lsp-ui-peek-find-references' +;; on a symbol to find its references +;; or `lsp-ui-peek-find-definitions'. +;; Type 'q' to close the window. +;; + +;;; Code: + +(require 'lsp-mode) +(require 'xref) +(require 'dash) + +(defgroup lsp-ui-peek nil + "Improve version of xref with peek feature." + :group 'tools + :group 'convenience + :group 'lsp-ui + :link '(custom-manual "(lsp-ui-peek) Top") + :link '(info-link "(lsp-ui-peek) Customizing")) + +(defcustom lsp-ui-peek-enable t + "Whether or not to enable ‘lsp-ui-peek’." + :type 'boolean + :group 'lsp-ui) + +(defcustom lsp-ui-peek-peek-height 20 + "Height of the peek code." + :type 'integer + :group 'lsp-ui-peek) + +(defcustom lsp-ui-peek-list-width 50 + "Width of the right panel." + :type 'integer + :group 'lsp-ui-peek) + +(defcustom lsp-ui-peek-fontify 'on-demand + "Whether to fontify chunks of code (use semantics colors). +WARNING: 'always can heavily slow the processing when `lsp-ui-peek-expand-function' +expands more than 1 file. It is recommended to keeps the default value of +`lsp-ui-peek-expand-function' when this variable is 'always." + :type '(choice (const :tag "Never" never) + (const :tag "On demand" on-demand) + (const :tag "Always" always)) + :group 'lsp-ui-peek) + +(defcustom lsp-ui-peek-always-show nil + "Show the peek view even if there is only 1 cross reference. +By default, the peek view isn't shown if there is 1 xref." + :type 'boolean + :group 'lsp-ui-peek) + +(defface lsp-ui-peek-peek + '((((background light)) :background "light gray") + (t :background "#031A25")) + "Face used for the peek." + :group 'lsp-ui-peek) + +(defface lsp-ui-peek-list + '((((background light)) :background "light gray") + (t :background "#181818")) + "Face used to list references." + :group 'lsp-ui-peek) + +(defface lsp-ui-peek-filename + '((((background light)) :foreground "red") + (t :foreground "dark orange")) + "Face used for the filename's reference in the list." + :group 'lsp-ui-peek) + +(defface lsp-ui-peek-line-number + '((t :foreground "grey25")) + "Line number face." + :group 'lsp-ui-peek) + +(defface lsp-ui-peek-highlight + '((((background light)) :background "dim gray" + :foreground "white" + :distant-foreground "black") + (t :background "white" + :foreground "black" + :distant-foreground "white" + :box (:line-width -1 :color "white"))) + "Face used to highlight the reference/definition. +Do not use box, underline or overline prop. If you want to use +box, use a negative value for its width. Those properties deform +the whole overlay." + :group 'lsp-ui-peek) + +(defface lsp-ui-peek-header + '((((background light)) :background "grey30" :foreground "white") + (t :background "white" :foreground "black")) + "Face used for the headers." + :group 'lsp-ui-peek) + +(defface lsp-ui-peek-footer + '((t :inherit lsp-ui-peek-header)) + "Face used for the footers. Only the background of this face is used." + :group 'lsp-ui-peek) + +(defface lsp-ui-peek-selection + '((((background light)) :background "grey30" :foreground "white") + (t :background "white" :foreground "black")) + "Face used for the current selection. +Do not use box, underline or overline prop. If you want to use +box, use a negative value for its width. Those properties +deform the whole overlay." + :group 'lsp-ui-peek) + +(defvar lsp-ui-peek-expand-function 'lsp-ui-peek--expand-buffer + "A function used to determinate which file(s) to expand in the list of xrefs. +The function takes one parameter: a list of cons where the car is the +filename and the cdr is the number of references in that file. +It should returns a list of filenames to expand. +WARNING: If you change this variable and expand more than 1 file, it is +recommended to set `lsp-ui-peek-fontify' to 'never or 'on-demand, otherwise it +will cause performances issues.") + +(defvar-local lsp-ui-peek--overlay nil) +(defvar-local lsp-ui-peek--list nil) +(defvar-local lsp-ui-peek--last-xref nil) +(defvar-local lsp-ui-peek--selection 0) +(defvar-local lsp-ui-peek--offset 0) +(defvar-local lsp-ui-peek--size-list 0) +(defvar-local lsp-ui-peek--win-start nil) +(defvar-local lsp-ui-peek--kind nil) +(defvar-local lsp-ui-peek--deactivate-keymap-fn nil) + +(defvar lsp-ui-peek--jumps (make-hash-table) + "Hashtable which stores all jumps on a per window basis.") + +(defvar evil--jumps-window-jumps) ; defined in evil-jumps.el + +(defmacro lsp-ui-peek--with-evil-jumps (&rest body) + "Make `evil-jumps.el' commands work on `lsp-ui-peek--jumps'." + (declare (indent 1)) + `(let ((evil--jumps-window-jumps lsp-ui-peek--jumps)) + ,@body)) + +(with-eval-after-load 'evil-jumps + ;; We need to jump through some hoops to prevent the byte-compiler from + ;; compiling this code. We can’t compile the code without requiring + ;; ‘evil-macros’. + (eval '(progn + (evil-define-motion lsp-ui-peek-jump-backward (count) + (lsp-ui-peek--with-evil-jumps + (evil--jump-backward count) + (run-hooks 'xref-after-return-hook))) + (evil-define-motion lsp-ui-peek-jump-forward (count) + (lsp-ui-peek--with-evil-jumps + (evil--jump-forward count) + (run-hooks 'xref-after-return-hook)))) + t)) + +(defmacro lsp-ui-peek--prop (prop &optional string) + `(get-text-property 0 ,prop (or ,string (lsp-ui-peek--get-text-selection) ""))) + +(defmacro lsp-ui-peek--add-prop (prop &optional string) + `(let ((obj (or ,string (lsp-ui-peek--get-text-selection)))) + (add-text-properties 0 (length obj) ,prop obj) + obj)) + +(defun lsp-ui-peek--truncate (len s) + (if (> (string-width s) len) + (format "%s.." (substring s 0 (- len 2))) + s)) + +(defun lsp-ui-peek--get-text-selection (&optional n) + (nth (or n lsp-ui-peek--selection) + (--remove (get-text-property 0 'lsp-ui-peek-hidden it) lsp-ui-peek--list))) + +(defun lsp-ui-peek--get-selection () + (get-text-property 0 'lsp-ui-peek (or (lsp-ui-peek--get-text-selection) ""))) + +(defun lsp-ui-peek--visual-index () + (- lsp-ui-peek--selection lsp-ui-peek--offset)) + +(defun lsp-ui-peek--make-line (index src) + (-let* (((s1 . s2) src) + (len-s1 (length s1)) + (len-s2 (length s2)) + (on-selection (= (1+ (lsp-ui-peek--visual-index)) index)) + (face-left (if (= index 0) 'lsp-ui-peek-header 'lsp-ui-peek-peek)) + (face-right (cond (on-selection 'lsp-ui-peek-selection) + ((= index 0) 'lsp-ui-peek-header) + (t 'lsp-ui-peek-list)))) + (when on-selection + (setq s2 (copy-sequence s2)) + (add-face-text-property 0 len-s2 face-right nil s2)) + (unless (get-text-property 0 'lsp-ui-peek-faced s2) + (add-face-text-property 0 len-s2 face-right t s2) + (add-text-properties 0 len-s2 '(lsp-ui-peek-faced t) s2) + (add-face-text-property 0 len-s2 'default t s2)) + (add-face-text-property 0 len-s1 face-left t s1) + (add-face-text-property 0 len-s1 'default t s1) + (concat + s1 + (propertize "_" 'face face-left 'display `(space :align-to (- right-fringe ,(1+ lsp-ui-peek-list-width)))) + " " + s2 + (propertize "_" 'face face-right 'display `(space :align-to (- right-fringe 1))) + (propertize "\n" 'face face-right)))) + +(defun lsp-ui-peek--adjust (width strings) + (-let* (((s1 . s2) strings)) + (cons (lsp-ui-peek--truncate (- width (1+ lsp-ui-peek-list-width)) s1) + (lsp-ui-peek--truncate (- lsp-ui-peek-list-width 2) s2)))) + +(defun lsp-ui-peek--make-footer () + ;; Character-only terminals don't support characters of different height + (when (display-graphic-p) + (list + (concat + (propertize " " + 'face `(:background ,(face-background 'lsp-ui-peek-footer nil t) :height 1) + 'display `(space :align-to (- right-fringe ,(1+ lsp-ui-peek-list-width)))) + (propertize " " 'face '(:height 1) + 'display `(space :align-to (- right-fringe ,lsp-ui-peek-list-width))) + (propertize " " + 'face `(:background ,(face-background 'lsp-ui-peek-footer nil t) :height 1) + 'display `(space :align-to (- right-fringe 0))) + (propertize "\n" 'face '(:height 1)) + (propertize "\n" 'face '(:height 0.5)))))) + +(defun lsp-ui-peek--peek-new (src1 src2) + (-let* ((win-width (window-text-width)) + (string (-some--> (-zip-fill "" src1 src2) + (--map (lsp-ui-peek--adjust win-width it) it) + (-map-indexed 'lsp-ui-peek--make-line it) + (-concat it (lsp-ui-peek--make-footer)))) + (next-line (line-beginning-position 2)) + (ov (or (when (overlayp lsp-ui-peek--overlay) lsp-ui-peek--overlay) + (make-overlay next-line next-line)))) + (setq lsp-ui-peek--overlay ov) + (overlay-put ov 'after-string (mapconcat 'identity string "")) + (overlay-put ov 'display-line-numbers-disable t) + (overlay-put ov 'window (get-buffer-window)))) + +(defun lsp-ui-peek--expand-buffer (files) + (if (--any? (equal (car it) buffer-file-name) files) + (list buffer-file-name) + (list (caar files)))) + +(defun lsp-ui-peek--expand (xrefs) + (let* ((to-expand (->> (--map (cons (plist-get it :file) (plist-get it :count)) xrefs) + (funcall lsp-ui-peek-expand-function))) + first) + (while (nth lsp-ui-peek--selection lsp-ui-peek--list) + (when (and (lsp-ui-peek--prop 'xrefs) + (member (lsp-ui-peek--prop 'file) to-expand)) + (unless first + (setq first (1+ lsp-ui-peek--selection))) + (lsp-ui-peek--toggle-file t)) + (setq lsp-ui-peek--selection (1+ lsp-ui-peek--selection))) + (setq lsp-ui-peek--selection (or first 0)) + (lsp-ui-peek--recenter))) + +(defun lsp-ui-peek--show (xrefs) + "Create a window to list references/defintions. +XREFS is a list of references/definitions." + (setq lsp-ui-peek--win-start (window-start) + lsp-ui-peek--selection 0 + lsp-ui-peek--offset 0 + lsp-ui-peek--size-list 0 + lsp-ui-peek--list nil) + (when (eq (logand lsp-ui-peek-peek-height 1) 1) + (setq lsp-ui-peek-peek-height (1+ lsp-ui-peek-peek-height))) + (when (< (- (line-number-at-pos (window-end)) (line-number-at-pos)) + (+ lsp-ui-peek-peek-height 3)) + (recenter 15)) + (setq xrefs (--sort (string< (plist-get it :file) (plist-get other :file)) xrefs)) + (--each xrefs + (-let* (((&plist :file filename :xrefs xrefs :count count) it) + (len-str (number-to-string count))) + (setq lsp-ui-peek--size-list (+ lsp-ui-peek--size-list count)) + (push (concat (propertize (lsp-ui--workspace-path filename) + 'face 'lsp-ui-peek-filename + 'file filename + 'xrefs xrefs) + (propertize " " 'display `(space :align-to (- right-fringe ,(1+ (length len-str))))) + (propertize len-str 'face 'lsp-ui-peek-filename)) + lsp-ui-peek--list))) + (setq lsp-ui-peek--list (nreverse lsp-ui-peek--list)) + (lsp-ui-peek--expand xrefs) + (lsp-ui-peek--peek)) + +(defun lsp-ui-peek--recenter () + (let ((half-height (/ lsp-ui-peek-peek-height 2))) + (when (> lsp-ui-peek--selection half-height) + (setq lsp-ui-peek--offset (- lsp-ui-peek--selection (1- half-height)))))) + +(defun lsp-ui-peek--fill (min-len list) + (let ((len (length list))) + (if (< len min-len) + (append list (-repeat (- min-len len) "")) + list))) + +(defun lsp-ui-peek--render (major string) + (with-temp-buffer + (insert string) + (delay-mode-hooks + (let ((inhibit-message t)) + (funcall major)) + (ignore-errors + (font-lock-ensure))) + (buffer-string))) + +(defun lsp-ui-peek--peek () + "Show reference's chunk of code." + (-let* ((xref (lsp-ui-peek--get-selection)) + ((&plist :file file :chunk chunk) (or xref lsp-ui-peek--last-xref)) + (header (concat " " (lsp-ui--workspace-path file) "\n")) + (header2 (format " %s %s" lsp-ui-peek--size-list (symbol-name lsp-ui-peek--kind))) + (ref-view (--> chunk + (if (eq lsp-ui-peek-fontify 'on-demand) + (lsp-ui-peek--render major-mode it) + chunk) + (subst-char-in-string ?\t ?\s it) + (concat header it) + (split-string it "\n"))) + (list-refs (->> lsp-ui-peek--list + (--remove (lsp-ui-peek--prop 'lsp-ui-peek-hidden it)) + (-drop lsp-ui-peek--offset) + (-take (1- lsp-ui-peek-peek-height)) + (lsp-ui-peek--fill (1- lsp-ui-peek-peek-height)) + (-concat (list header2))))) + (setq lsp-ui-peek--last-xref (or xref lsp-ui-peek--last-xref)) + (lsp-ui-peek--peek-new ref-view list-refs))) + +(defun lsp-ui-peek--toggle-text-prop (s) + (let ((state (lsp-ui-peek--prop 'lsp-ui-peek-hidden s))) + (lsp-ui-peek--add-prop `(lsp-ui-peek-hidden ,(not state)) s))) + +(defun lsp-ui-peek--toggle-hidden (file) + (setq lsp-ui-peek--list + (--map-when (string= (plist-get (lsp-ui-peek--prop 'lsp-ui-peek it) :file) file) + (prog1 it (lsp-ui-peek--toggle-text-prop it)) + lsp-ui-peek--list))) + +(defun lsp-ui-peek--remove-hidden (file) + (setq lsp-ui-peek--list + (--map-when (string= (plist-get (lsp-ui-peek--prop 'lsp-ui-peek it) :file) file) + (prog1 it (lsp-ui-peek--add-prop '(lsp-ui-peek-hidden nil) it)) + lsp-ui-peek--list))) + +(defun lsp-ui-peek--make-ref-line (xref) + (-let* (((&plist :summary summary :line line :file file) xref) + (string (format "%-3s %s" + (propertize (number-to-string (1+ line)) + 'face 'lsp-ui-peek-line-number) + (string-trim summary)))) + (lsp-ui-peek--add-prop `(lsp-ui-peek ,xref file ,file) string))) + +(defun lsp-ui-peek--insert-xrefs (xrefs filename index) + (setq lsp-ui-peek--list (--> (lsp-ui-peek--get-xrefs-in-file (cons filename xrefs)) + (-map 'lsp-ui-peek--make-ref-line it) + (-insert-at (1+ index) it lsp-ui-peek--list) + (-flatten it))) + (lsp-ui-peek--add-prop '(xrefs nil))) + +(defun lsp-ui-peek--toggle-file (&optional no-update) + (interactive) + (-if-let* ((xrefs (lsp-ui-peek--prop 'xrefs)) + (filename (lsp-ui-peek--prop 'file)) + (index (--find-index (equal (lsp-ui-peek--prop 'file it) filename) + lsp-ui-peek--list))) + (lsp-ui-peek--insert-xrefs xrefs filename index) + (let ((file (lsp-ui-peek--prop 'file))) + (lsp-ui-peek--toggle-hidden file) + (while (not (equal file (lsp-ui-peek--prop 'file))) + (lsp-ui-peek--select-prev t)))) + (unless no-update + (lsp-ui-peek--peek))) + +(defun lsp-ui-peek--select (index) + (setq lsp-ui-peek--selection (+ lsp-ui-peek--selection index))) + +(defun lsp-ui-peek--select-next (&optional no-update) + (interactive) + (when (lsp-ui-peek--get-text-selection (1+ lsp-ui-peek--selection)) + (lsp-ui-peek--select 1) + (while (> (lsp-ui-peek--visual-index) (- lsp-ui-peek-peek-height 2)) + (setq lsp-ui-peek--offset (1+ lsp-ui-peek--offset))) + (unless no-update + (lsp-ui-peek--peek)))) + +(defun lsp-ui-peek--select-prev (&optional no-update) + (interactive) + (when (> lsp-ui-peek--selection 0) + (lsp-ui-peek--select -1) + (while (< (lsp-ui-peek--visual-index) 0) + (setq lsp-ui-peek--offset (1- lsp-ui-peek--offset)))) + (unless no-update + (lsp-ui-peek--peek))) + +(defun lsp-ui-peek--skip-refs (fn) + (let ((last-file (lsp-ui-peek--prop 'file)) + last-selection) + (when (lsp-ui-peek--get-selection) + (while (and (equal (lsp-ui-peek--prop 'file) last-file) + (not (equal last-selection lsp-ui-peek--selection))) + (setq last-selection lsp-ui-peek--selection) + (funcall fn t))))) + +(defun lsp-ui-peek--select-prev-file () + (interactive) + (if (not (lsp-ui-peek--get-selection)) + (lsp-ui-peek--select-prev) + (lsp-ui-peek--skip-refs 'lsp-ui-peek--select-prev) + (when (lsp-ui-peek--get-selection) + (lsp-ui-peek--skip-refs 'lsp-ui-peek--select-prev) + (unless (= lsp-ui-peek--selection 0) + (lsp-ui-peek--select-next t)))) + (if (lsp-ui-peek--prop 'xrefs) + (lsp-ui-peek--toggle-file) + (lsp-ui-peek--remove-hidden (lsp-ui-peek--prop 'file))) + (lsp-ui-peek--select-next t) + (lsp-ui-peek--recenter) + (lsp-ui-peek--peek)) + +(defun lsp-ui-peek--select-next-file () + (interactive) + (lsp-ui-peek--skip-refs 'lsp-ui-peek--select-next) + (if (lsp-ui-peek--prop 'xrefs) + (lsp-ui-peek--toggle-file) + (lsp-ui-peek--remove-hidden (lsp-ui-peek--prop 'file))) + (lsp-ui-peek--select-next t) + (lsp-ui-peek--recenter) + (lsp-ui-peek--peek)) + +(defun lsp-ui-peek--peek-hide () + "Hide the chunk of code and restore previous state." + (when (overlayp lsp-ui-peek--overlay) + (delete-overlay lsp-ui-peek--overlay)) + (setq lsp-ui-peek--overlay nil + lsp-ui-peek--last-xref nil) + (set-window-start (get-buffer-window) lsp-ui-peek--win-start)) + +(defun lsp-ui-peek--deactivate-keymap () + "Deactivate keymap." + (-when-let (fn lsp-ui-peek--deactivate-keymap-fn) + (setq lsp-ui-peek--deactivate-keymap-fn nil) + (funcall fn))) + +(defun lsp-ui-peek--goto-xref (&optional x other-window) + "Go to a reference/definition." + (interactive) + (-if-let (xref (or x (lsp-ui-peek--get-selection))) + (-let (((&plist :file file :line line :column column) xref) + (buffer (current-buffer))) + (if (not (file-readable-p file)) + (user-error "File not readable: %s" file) + (setq lsp-ui-peek--win-start nil) + (lsp-ui-peek--abort) + (let ((marker (with-current-buffer + (or (get-file-buffer file) + (find-file-noselect file)) + (save-restriction + (widen) + (save-excursion + ;; When we jump to a file with line/column unspecified, + ;; we do not want to move the point if the buffer exists. + ;; We interpret line=column=0 differently here. + (when (> (+ line column) 0) + (goto-char 1) + (forward-line line) + (forward-char column)) + (point-marker))))) + (current-workspace lsp--cur-workspace)) + (if other-window + (pop-to-buffer (marker-buffer marker) t) + (switch-to-buffer (marker-buffer marker))) + (with-current-buffer buffer + (lsp-ui-peek-mode -1)) + (unless lsp--cur-workspace + (setq lsp--cur-workspace current-workspace)) + (unless lsp-mode + (lsp-mode 1) + (lsp-on-open)) + (goto-char marker) + (run-hooks 'xref-after-jump-hook)))) + (lsp-ui-peek--toggle-file))) + +(defun lsp-ui-peek--goto-xref-other-window () + (interactive) + (lsp-ui-peek--goto-xref nil t)) + +(defvar lsp-ui-peek-mode-map nil + "Keymap for ‘lsp-ui-peek-mode’.") +(unless lsp-ui-peek-mode-map + (let ((map (make-sparse-keymap))) + (suppress-keymap map t) + (define-key map "\e\e\e" 'lsp-ui-peek--abort) + (define-key map "\C-g" 'lsp-ui-peek--abort) + (define-key map (kbd "M-n") 'lsp-ui-peek--select-next-file) + (define-key map (kbd "<right>") 'lsp-ui-peek--select-next-file) + (define-key map (kbd "M-p") 'lsp-ui-peek--select-prev-file) + (define-key map (kbd "<left>") 'lsp-ui-peek--select-prev-file) + (define-key map (kbd "C-n") 'lsp-ui-peek--select-next) + (define-key map (kbd "n") 'lsp-ui-peek--select-next) + (define-key map (kbd "<down>") 'lsp-ui-peek--select-next) + (define-key map (kbd "C-p") 'lsp-ui-peek--select-prev) + (define-key map (kbd "p") 'lsp-ui-peek--select-prev) + (define-key map (kbd "<up>") 'lsp-ui-peek--select-prev) + (define-key map (kbd "TAB") 'lsp-ui-peek--toggle-file) + (define-key map (kbd "q") 'lsp-ui-peek--abort) + (define-key map (kbd "RET") 'lsp-ui-peek--goto-xref) + (define-key map (kbd "M-RET") 'lsp-ui-peek--goto-xref-other-window) + (setq lsp-ui-peek-mode-map map))) + +(defun lsp-ui-peek--disable () + "Do not call this function, call `lsp-ui-peek--abort' instead." + (when (bound-and-true-p lsp-ui-peek-mode) + (lsp-ui-peek-mode -1) + (lsp-ui-peek--peek-hide))) + +(defun lsp-ui-peek--abort () + (interactive) + ;; The timer fixes https://github.com/emacs-lsp/lsp-ui/issues/33 + (run-with-idle-timer 0 nil 'lsp-ui-peek--disable)) + +(define-minor-mode lsp-ui-peek-mode + "Mode for lsp-ui-peek." + :init-value nil + (if lsp-ui-peek-mode + (setq lsp-ui-peek--deactivate-keymap-fn (set-transient-map lsp-ui-peek-mode-map t 'lsp-ui-peek--abort)) + (lsp-ui-peek--deactivate-keymap) + (lsp-ui-peek--peek-hide))) + +(defun lsp-ui-peek--find-xrefs (input kind &optional request param) + "Find INPUT references. +KIND is ‘references’, ‘definitions’ or a custom kind." + (setq lsp-ui-peek--kind kind) + (let ((xrefs (lsp-ui-peek--get-references kind request param))) + (unless xrefs + (user-error "No %s found for: %s" (symbol-name kind) input)) + (xref-push-marker-stack) + (when (featurep 'evil-jumps) + (lsp-ui-peek--with-evil-jumps (evil-set-jump))) + (if (and (not lsp-ui-peek-always-show) + (not (cdr xrefs)) + (= (length (plist-get (car xrefs) :xrefs)) 1)) + (-let* ((xref (car (plist-get (car xrefs) :xrefs))) + ((&hash "uri" file "range" range) xref) + ((&hash "line" line "character" col) (gethash "start" range)) + (file (lsp--uri-to-path file))) + (lsp-ui-peek--goto-xref `(:file ,file :line ,line :column ,col))) + (lsp-ui-peek-mode) + (lsp-ui-peek--show xrefs)))) + +(defun lsp-ui-peek-find-references () + "Find references to the IDENTIFIER at point." + (interactive) + (lsp-ui-peek--find-xrefs (symbol-at-point) + 'references + "textDocument/references" + (lsp--make-reference-params))) + +(defun lsp-ui-peek-find-definitions () + "Find definitions to the IDENTIFIER at point." + (interactive) + (lsp-ui-peek--find-xrefs (symbol-at-point) + 'definitions + "textDocument/definition")) + +(defun lsp-ui-peek-find-implementation () + "Find implementation locations of the symbol at point." + (interactive) + (lsp-ui-peek--find-xrefs (symbol-at-point) + 'implementation + "textDocument/implementation")) + +(defun lsp-ui-peek-find-workspace-symbol (pattern) + "Find symbols in the worskpace. +The symbols are found matching PATTERN." + (interactive (list (read-string "workspace/symbol: " + nil 'xref--read-pattern-history))) + (lsp-ui-peek--find-xrefs pattern + 'symbols + "workspace/symbol" + (list :query pattern))) + +(defun lsp-ui-peek-find-custom (kind request &optional param) + "Find custom references. +KIND is a symbol to name the references (definition, reference, ..). +REQUEST is the method string to send the the language server. +PARAM is the method parameter. If nil, it default to TextDocumentPositionParams." + (lsp-ui-peek--find-xrefs (symbol-at-point) kind request param)) + +(defun lsp-ui-peek--extract-chunk-from-buffer (pos start end) + "Return the chunk of code pointed to by POS (a Position object) in the current buffer. +START and END are delimiters." + (let* ((point (lsp--position-to-point pos)) + (inhibit-field-text-motion t) + (line-start (1+ (- 1 (/ lsp-ui-peek-peek-height 2)))) + (line-end (/ lsp-ui-peek-peek-height 2))) + (save-excursion + (goto-char point) + (let* ((before (buffer-substring (line-beginning-position line-start) (line-beginning-position))) + (line (buffer-substring (line-beginning-position) (line-end-position))) + (after (buffer-substring (line-end-position) (line-end-position line-end))) + (len (length line))) + (add-face-text-property (max (min start len) 0) + (max (min end len) 0) + 'lsp-ui-peek-highlight t line) + `(,line . ,(concat before line after)))))) + +(defun lsp-ui-peek--xref-make-item (filename location) + "Return an item from a LOCATION in FILENAME. +LOCATION can be either a LSP Location or SymbolInformation." + ;; TODO: Read more informations from SymbolInformation. + ;; For now, only the location is used. + (-let* ((location (or (gethash "location" location) location)) + (range (gethash "range" location)) + ((&hash "start" pos-start "end" pos-end) range) + (start (gethash "character" pos-start)) + (end (gethash "character" pos-end)) + ((line . chunk) (lsp-ui-peek--extract-chunk-from-buffer pos-start start end))) + (list :summary (or line filename) + :chunk (or chunk filename) + :file filename + :line (gethash "line" pos-start) + :column start + :len (- end start)))) + +(defun lsp-ui-peek--fontify-buffer (filename) + (when (eq lsp-ui-peek-fontify 'always) + (unless buffer-file-name + (make-local-variable 'delay-mode-hooks) + (let ((buffer-file-name filename) + (enable-local-variables nil) + (inhibit-message t) + (delay-mode-hooks t)) + (set-auto-mode))) + (font-lock-ensure))) + +(defun lsp-ui-peek--get-xrefs-in-file (file) + "Return all references that contain a file. +FILE is a cons where its car is the filename and the cdr is a list of Locations +within the file. We open and/or create the file/buffer only once for all +references. The function returns a list of `ls-xref-item'." + (let* ((filename (car file)) + (visiting (find-buffer-visiting filename)) + (fn (lambda (loc) (lsp-ui-peek--xref-make-item filename loc)))) + (cond + (visiting + (with-temp-buffer + (insert-buffer-substring-no-properties visiting) + (lsp-ui-peek--fontify-buffer filename) + (mapcar fn (cdr file)))) + ((file-readable-p filename) + (with-temp-buffer + (insert-file-contents-literally filename) + (lsp-ui-peek--fontify-buffer filename) + (mapcar fn (cdr file)))) + (t (user-error "Cannot read %s" filename))))) + +(defun lsp-ui-peek--get-xrefs-list (file) + "Return a list of xrefs in FILE." + (-let* (((filename . xrefs) file)) + `(:file ,filename :xrefs ,xrefs :count ,(length xrefs)))) + +(defun lsp-ui-peek--locations-to-xref-items (locations) + "Return a list of list of item from LOCATIONS. +LOCATIONS is an array of Location objects: + +interface Location { + uri: DocumentUri; + range: Range; +}" + (-some--> (lambda (loc) (lsp--uri-to-path (gethash "uri" (or (gethash "location" loc) loc)))) + (seq-group-by it locations) + (mapcar #'lsp-ui-peek--get-xrefs-list it))) + +(defun lsp-ui-peek--to-sequence (maybe-sequence) + "If maybe-sequence is not a sequence, wraps it into a single-element sequence." + (if (sequencep maybe-sequence) maybe-sequence (list maybe-sequence))) + +(defun lsp-ui-peek--get-references (_kind request &optional param) + "Get all references/definitions for the symbol under point. +Returns item(s)." + (-some->> (lsp--send-request (lsp--make-request + request + (or param (lsp--text-document-position-params)))) + ;; Language servers may return a single LOCATION instead of a sequence of them. + (lsp-ui-peek--to-sequence) + (lsp-ui-peek--locations-to-xref-items) + (-filter 'identity))) + +(defvar lsp-ui-mode-map) + +(defun lsp-ui-peek-enable (_enable) + (interactive) + (unless (bound-and-true-p lsp-ui-mode-map) + (user-error "Please load lsp-ui before trying to enable lsp-ui-peek"))) + +;; lsp-ui.el loads lsp-ui-peek.el, so we can’t ‘require’ lsp-ui. +;; FIXME: Remove this cyclic dependency. +(declare-function lsp-ui--workspace-path "lsp-ui" (path)) + +(declare-function evil-set-jump "evil-jumps.el" (&optional pos)) + +(provide 'lsp-ui-peek) +;;; lsp-ui-peek.el ends here diff --git a/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-peek.elc b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-peek.elc new file mode 100644 index 000000000000..4a28d35c69fb --- /dev/null +++ b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-peek.elc Binary files differdiff --git a/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-pkg.el b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-pkg.el new file mode 100644 index 000000000000..dd2e8c8dd02d --- /dev/null +++ b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-pkg.el @@ -0,0 +1,17 @@ +(define-package "lsp-ui" "20180619.251" "UI modules for lsp-mode" + '((emacs "25.1") + (dash "2.13") + (dash-functional "1.2.0") + (flycheck "31") + (lsp-mode "4.0") + (markdown-mode "2.3")) + :keywords + '("lsp") + :authors + '(("Tobias Pisani" . "topisani@hamsterpoison.com")) + :maintainer + '("Tobias Pisani" . "topisani@hamsterpoison.com") + :url "https://github.com/emacs-lsp/lsp-ui") +;; Local Variables: +;; no-byte-compile: t +;; End: diff --git a/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-sideline.el b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-sideline.el new file mode 100644 index 000000000000..49d766a6f506 --- /dev/null +++ b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-sideline.el @@ -0,0 +1,505 @@ +;;; lsp-ui-sideline.el --- Lsp-Ui-Sideline -*- lexical-binding: t -*- + +;; Copyright (C) 2017 Sebastien Chapuis + +;; Author: Sebastien Chapuis <sebastien@chapu.is> +;; URL: https://github.com/emacs-lsp/lsp-ui +;; Keywords: lsp, ui + +;;; 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: +;; +;; Utility to show informations of the current line + +;;; Code: + +(require 'lsp-mode) +(require 'flycheck) +(require 'dash) + +(defgroup lsp-ui-sideline nil + "Display informations of the current line." + :group 'tools + :group 'convenience + :group 'lsp-ui + :link '(custom-manual "(lsp-ui-sideline) Top") + :link '(info-link "(lsp-ui-sideline) Customizing")) + +(defcustom lsp-ui-sideline-enable t + "Whether or not to enable ‘lsp-ui-sideline’." + :type 'boolean + :group 'lsp-ui) + +(defcustom lsp-ui-sideline-ignore-duplicate nil + "Control to ignore duplicates when there is a same symbol with the same contents." + :type 'boolean + :group 'lsp-ui-sideline) + +(defcustom lsp-ui-sideline-show-symbol t + "When t, show the symbol name on the right of the information." + :type 'boolean + :group 'lsp-ui-sideline) + +(defcustom lsp-ui-sideline-show-hover t + "Whether to show hover messages in sideline." + :type 'boolean + :group 'lsp-ui-sideline) + +(defcustom lsp-ui-sideline-show-flycheck t + "Whether to show flycheck messages in sideline." + :type 'boolean + :group 'lsp-ui-sideline) + +(defcustom lsp-ui-sideline-show-code-actions t + "Whether to show code actions in sideline." + :type 'boolean + :group 'lsp-ui-sideline) + +(defcustom lsp-ui-sideline-update-mode 'line + "Define the mode for updating sideline information. + +When set to `line' the information will be updated when user +changes current line otherwise the information will be updated +when user changes current point." + :type '(choice (const line) + (const point)) + :group 'lsp-ui-sideline) + +(defcustom lsp-ui-sideline-delay 0.2 + "Number of seconds to wait before showing sideline." + :type 'number + :group 'lsp-ui-sideline) + +(defvar lsp-ui-sideline-code-actions-prefix "" + "Prefix to insert before the code action title. +This can be used to insert, for example, an unicode character: 💡") + +(defvar-local lsp-ui-sideline--ovs nil + "Overlays used by `lsp-ui-sideline'.") + +(defvar-local lsp-ui-sideline--occupied-lines nil + "List of lines occupied by an overlay of `lsp-ui-sideline'.") + +(defvar-local lsp-ui-sideline--tag nil + "Tag marking where the last operation was based. +It is used to know when the cursor has changed of line or point.") + +(defvar-local lsp-ui-sideline--last-width nil + "Value of window's width on the last operation. +It is used to know when the window has changed of width.") + +(defvar-local lsp-ui-sideline--timer nil) + +(defface lsp-ui-sideline-symbol + '((t :foreground "grey" + :box (:line-width -1 :color "grey") + :height 0.99)) + "Face used to highlight symbols." + :group 'lsp-ui-sideline) + +(defface lsp-ui-sideline-current-symbol + '((t :foreground "white" + :weight ultra-bold + :box (:line-width -1 :color "white") + :height 0.99)) + "Face used to highlight the symbol on point." + :group 'lsp-ui-sideline) + +(defface lsp-ui-sideline-code-action + '((t :foreground "yellow")) + "Face used to highlight code action text." + :group 'lsp-ui-sideline) + +(defface lsp-ui-sideline-symbol-info + '((t :slant italic :height 0.99)) + "Face used to highlight the symbols informations (LSP hover)." + :group 'lsp-ui-sideline) + +(defface lsp-ui-sideline-global + '((t)) + "Face which apply to all overlays. +This face have a low priority over the others." + :group 'lsp-ui-sideline) + +(defun lsp-ui-sideline--calc-space (win-width str-len index) + "Calcul whether there is enough space on line. +If there is enough space, it returns the point of the last +character on the line. + +WIN-WIDTH is the window width. +STR-LEN is the string size. +INDEX is the line number (relative to the current line)." + (let ((eol (line-end-position index))) + (unless (member eol lsp-ui-sideline--occupied-lines) + (save-excursion + (goto-char eol) + (when (>= (- win-width (current-column)) str-len) + eol))))) + +(defun lsp-ui-sideline--find-line (str-len &optional up) + "Find a line where the string can be inserted. +It loops on the nexts lines to find enough space. +Returns the point of the last character on the line. + +WIN-WIDTH is the window width. +STR-LEN is the string size. +if UP is non-nil, it loops on the previous lines.." + (let ((win-width (lsp-ui-sideline--window-width)) + (index 1) pos) + (while (and (null pos) (<= (abs index) 30)) + (setq index (if up (1- index) (1+ index))) + (setq pos (lsp-ui-sideline--calc-space win-width str-len index))) + (when pos (push pos lsp-ui-sideline--occupied-lines)) + (if (or (equal pos (point-min)) + (and up (null pos))) + (lsp-ui-sideline--find-line str-len) + pos))) + +(defun lsp-ui-sideline--delete-ov () + "Delete overlays." + (seq-do 'delete-overlay lsp-ui-sideline--ovs) + (setq lsp-ui-sideline--ovs nil)) + +(defun lsp-ui-sideline--get-renderer (language) + "Return a function to fontify a string in LANGUAGE." + (thread-last lsp--cur-workspace + lsp--workspace-client + lsp--client-string-renderers + (assoc-string language) + cdr)) + +(defun lsp-ui-sideline--get-language () + "Return the language of the buffer." + (thread-first lsp--cur-workspace + lsp--workspace-client + lsp--client-language-id + (funcall (current-buffer)))) + +(defun lsp-ui-sideline--extract-info (contents) + "Extract the line to print from CONTENTS. +CONTENTS can be differents type of values: +MarkedString | MarkedString[] | MarkupContent (as defined in the LSP). +We prioritize string with a language (which is probably a type or a +function signature)." + (when contents + (cond + ((stringp contents) contents) + ((listp contents) ;; MarkedString[] + (--first (and (hash-table-p it) + (lsp-ui-sideline--get-renderer (gethash "language" it))) + contents)) + ((gethash "kind" contents) (gethash "value" contents)) ;; MarkupContent + ((gethash "language" contents) ;; MarkedString + (and (lsp-ui-sideline--get-renderer (gethash "language" contents)) + (gethash "value" contents)))))) + +(defun lsp-ui-sideline--format-info (marked-string) + "Format MARKED-STRING. +If the string has a language, we fontify it with the function provided +by `lsp-mode'. +MARKED-STRING is the string returned by `lsp-ui-sideline--extract-info'." + (when marked-string + (when (hash-table-p marked-string) + (let* ((language (gethash "language" marked-string)) + (value (gethash "value" marked-string)) + (renderer (lsp-ui-sideline--get-renderer language))) + (setq marked-string (if (and (functionp renderer) value) + (funcall renderer value) + value)))) + (add-face-text-property 0 (length marked-string) 'lsp-ui-sideline-symbol-info nil marked-string) + (add-face-text-property 0 (length marked-string) 'default t marked-string) + (replace-regexp-in-string "[\n\t ]+" " " marked-string))) + +(defun lsp-ui-sideline--align (&rest lengths) + (+ (apply '+ lengths) + (if (display-graphic-p) 1 2))) + +(defun lsp-ui-sideline--make-display-string (info symbol current) + "Make final string to display on buffer. +INFO is the information to display. +SYMBOL is the symbol associated to the info. +CURRENT is non-nil when the point is on the symbol." + (let* ((face (if current 'lsp-ui-sideline-current-symbol 'lsp-ui-sideline-symbol)) + (str (if lsp-ui-sideline-show-symbol + (concat info " " (propertize (concat " " symbol " ") 'face face)) + info)) + (len (length str)) + (margin (lsp-ui-sideline--margin-width))) + (add-face-text-property 0 len 'lsp-ui-sideline-global nil str) + (concat + (propertize " " 'display `(space :align-to (- right-fringe ,(lsp-ui-sideline--align len margin)))) + str))) + +(defun lsp-ui-sideline--check-duplicate (symbol info) + (not (when lsp-ui-sideline-ignore-duplicate + (--any (and (string= (overlay-get it 'symbol) symbol) + (string= (overlay-get it 'info) info)) + lsp-ui-sideline--ovs)))) + +(defun lsp-ui-sideline--margin-width () + (+ (if fringes-outside-margins right-margin-width 0) + (or (and (boundp 'fringe-mode) + (consp fringe-mode) + (or (equal (car fringe-mode) 0) + (equal (cdr fringe-mode) 0)) + 1) + 0) + (if (bound-and-true-p display-line-numbers-mode) + (+ 2 (line-number-display-width)) + 0))) + +(defun lsp-ui-sideline--window-width () + (- (min (window-text-width) (window-body-width)) + (lsp-ui-sideline--margin-width))) + +(defun lsp-ui-sideline--push-info (symbol tag bounds info) + (when (and (= tag (lsp-ui-sideline--calculate-tag)) + (not (lsp-ui-sideline--stop-p))) + (let* ((info (concat (thread-first (gethash "contents" info) + lsp-ui-sideline--extract-info + lsp-ui-sideline--format-info))) + (current (and (>= (point) (car bounds)) (<= (point) (cdr bounds))))) + (when (and (> (length info) 0) + (lsp-ui-sideline--check-duplicate symbol info)) + (let* ((final-string (lsp-ui-sideline--make-display-string info symbol current)) + (pos-ov (lsp-ui-sideline--find-line (length final-string))) + (ov (when pos-ov (make-overlay pos-ov pos-ov)))) + (when pos-ov + (overlay-put ov 'info info) + (overlay-put ov 'symbol symbol) + (overlay-put ov 'bounds bounds) + (overlay-put ov 'current current) + (overlay-put ov 'after-string final-string) + (overlay-put ov 'window (get-buffer-window)) + (push ov lsp-ui-sideline--ovs))))))) + +(defun lsp-ui-sideline--toggle-current (ov current) + "Toggle the OV face according to CURRENT." + (let* ((info (overlay-get ov 'info)) + (symbol (overlay-get ov 'symbol)) + (string (lsp-ui-sideline--make-display-string info symbol current))) + (overlay-put ov 'current current) + (overlay-put ov 'after-string string))) + +(defun lsp-ui-sideline--highlight-current (point) + "Update the symbol's face according to POINT." + (dolist (ov lsp-ui-sideline--ovs) + (let* ((bounds (overlay-get ov 'bounds)) + (start (car bounds)) + (end (cdr bounds))) + (if (and bounds (>= point start) (<= point end)) + (unless (overlay-get ov 'current) + (lsp-ui-sideline--toggle-current ov t)) + (when (overlay-get ov 'current) + (lsp-ui-sideline--toggle-current ov nil)))))) + +(defun lsp-ui-sideline--flycheck () + "Show flycheck message(s)." + (let ((bol (line-beginning-position)) + (eol (line-end-position))) + (dolist (e (flycheck-overlay-errors-in bol (1+ eol))) + (let* ((message (--> (flycheck-error-format-message-and-id e) + (car (split-string it "\n")) + (replace-regexp-in-string "[\n\t ]+" " " it))) + (len (length message)) + (level (flycheck-error-level e)) + (face (if (eq level 'info) 'success level)) + (margin (lsp-ui-sideline--margin-width)) + (message (progn (add-face-text-property 0 len 'lsp-ui-sideline-global nil message) + (add-face-text-property 0 len face nil message) + message)) + (string (concat (propertize " " 'display `(space :align-to (- right-fringe ,(lsp-ui-sideline--align len margin)))) + message)) + (pos-ov (lsp-ui-sideline--find-line len t)) + (ov (and pos-ov (make-overlay pos-ov pos-ov)))) + (when pos-ov + (overlay-put ov 'after-string string) + (push ov lsp-ui-sideline--ovs)))))) + +(defvar-local lsp-ui-sideline--code-actions nil) + +(defun lsp-ui-sideline-apply-code-actions nil + "Choose and apply code action(s) on the current line." + (interactive) + (unless lsp-ui-sideline--code-actions + (user-error "No code actions on the current line")) + (let* ((actions lsp-ui-sideline--code-actions) + (title (completing-read "Apply: " (--map (gethash "title" it) actions) + nil t)) + (action (--first (equal (gethash "title" it) title) actions))) + (unless action + (error "Fail to apply action")) + (lsp-execute-code-action action))) + +(defun lsp-ui-sideline--code-actions (actions) + "Show code ACTIONS." + (setq lsp-ui-sideline--code-actions actions) + (dolist (action actions) + (-let* ((title (->> (gethash "title" action) + (replace-regexp-in-string "[\n\t ]+" " ") + (concat lsp-ui-sideline-code-actions-prefix))) + (margin (lsp-ui-sideline--margin-width)) + (keymap (let ((map (make-sparse-keymap))) + (define-key map [down-mouse-1] (lambda () (interactive) + (save-excursion + (lsp-execute-code-action action)))) + map)) + (len (length title)) + (title (progn (add-face-text-property 0 len 'lsp-ui-sideline-global nil title) + (add-face-text-property 0 len 'lsp-ui-sideline-code-action nil title) + (add-text-properties 0 len `(keymap ,keymap mouse-face highlight) title) + title)) + (string (concat (propertize " " 'display `(space :align-to (- right-fringe ,(lsp-ui-sideline--align len margin)))) + title)) + (pos-ov (lsp-ui-sideline--find-line (1+ (length title)) t)) + (ov (and pos-ov (make-overlay pos-ov pos-ov)))) + (when pos-ov + (overlay-put ov 'after-string string) + (push ov lsp-ui-sideline--ovs))))) + +(defun lsp-ui-sideline--calculate-tag() + "Calculate the tag used to determinie whether to update sideline information." + (if (equal lsp-ui-sideline-update-mode 'line) + (line-number-at-pos) + (point))) + +(defun lsp-ui-sideline--run () + "Show informations (flycheck + lsp). +It loops on the symbols of the current line and request information +to the language server." + (lsp-ui-sideline--delete-ov) + (when (and lsp--cur-workspace + buffer-file-name) + (let ((eol (line-end-position)) + (bol (line-beginning-position)) + (tag (lsp-ui-sideline--calculate-tag)) + (line-widen (save-restriction (widen) (line-number-at-pos))) + (doc-id (lsp--text-document-identifier))) + (save-excursion + (setq lsp-ui-sideline--occupied-lines nil + lsp-ui-sideline--tag tag + lsp-ui-sideline--last-width (window-text-width)) + (when lsp-ui-sideline-show-flycheck + (lsp-ui-sideline--flycheck)) + (when (and lsp-ui-sideline-show-code-actions (lsp--capability "codeActionProvider")) + (lsp--send-request-async (lsp--make-request + "textDocument/codeAction" + (if (equal lsp-ui-sideline-update-mode 'line) + (list :textDocument doc-id + :range (lsp--region-to-range bol eol) + :context (list :diagnostics (lsp--cur-line-diagnotics))) + (lsp--text-document-code-action-params))) + #'lsp-ui-sideline--code-actions)) + ;; Go through all symbols and request hover information. Note that the symbols are + ;; traversed backwards as `forward-symbol' with a positive argument will jump just past the + ;; current symbol. By going from the end of the line towards the front, point will be placed + ;; at the beginning of each symbol. As the requests are first collected in a list before + ;; being processed they are still sent in order from left to right. + (when (and lsp-ui-sideline-show-hover (lsp--capability "hoverProvider")) + (let ((symbols)) + (goto-char eol) + (while (and (> (point) bol) + (progn (forward-symbol -1) + (>= (point) bol))) + (let* ((symbol (thing-at-point 'symbol t)) + (bounds (bounds-of-thing-at-point 'symbol)) + (parsing-state (syntax-ppss)) + (in-string (nth 3 parsing-state)) + (outside-comment (eq (nth 4 parsing-state) nil))) + ;; Skip strings and comments + (when (and symbol (not in-string) outside-comment) + (push (list symbol tag bounds (lsp--position (1- line-widen) (- (point) bol))) symbols)))) + (dolist (entry symbols) + (-let [(symbol tag bounds position) entry] + (lsp--send-request-async + (lsp--make-request + "textDocument/hover" + (list :textDocument doc-id :position position)) + (lambda (info) (if info (lsp-ui-sideline--push-info symbol tag bounds info)))))))))))) + +(defun lsp-ui-sideline--stop-p () + "Return non-nil if the sideline should not be display." + (or (region-active-p) + (bound-and-true-p company-pseudo-tooltip-overlay) + (bound-and-true-p lsp-ui-peek--overlay))) + +(defun lsp-ui-sideline--hide-before-company (command) + "Disable the sideline before company's overlay appears. +COMMAND is `company-pseudo-tooltip-frontend' parameter." + (when (memq command '(post-command update)) + (lsp-ui-sideline--delete-ov) + (setq lsp-ui-sideline--tag nil))) + +(defun lsp-ui-sideline () + "Show informations of the current line." + (if (lsp-ui-sideline--stop-p) + (progn (setq lsp-ui-sideline--tag nil) + (lsp-ui-sideline--delete-ov)) + (if (and (equal (lsp-ui-sideline--calculate-tag) lsp-ui-sideline--tag) + (equal (window-text-width) lsp-ui-sideline--last-width)) + (lsp-ui-sideline--highlight-current (point)) + (lsp-ui-sideline--delete-ov) + (when lsp-ui-sideline--timer + (cancel-timer lsp-ui-sideline--timer)) + (let ((buf (current-buffer))) + (setq lsp-ui-sideline--timer + (run-with-idle-timer lsp-ui-sideline-delay + nil + (lambda () + ;; run lsp-ui only if current-buffer is the same. + (when (equal buf (current-buffer)) + (lsp-ui-sideline--run))))))))) + +(defun lsp-ui-sideline-toggle-symbols-info () + "Toggle display of symbols informations. +This does not toggle display of flycheck diagnostics or code actions." + (interactive) + (when (bound-and-true-p lsp-ui-sideline-mode) + (setq lsp-ui-sideline-show-hover + (not lsp-ui-sideline-show-hover)) + (lsp-ui-sideline--run))) + +(defun lsp-ui-sideline--diagnostics-changed () + "Handler for flycheck notifications." + (setq lsp-ui-sideline--tag nil) + (lsp-ui-sideline)) + +(define-minor-mode lsp-ui-sideline-mode + "Minor mode for showing information of current line." + :init-value nil + :group lsp-ui-sideline + (cond + (lsp-ui-sideline-mode + (add-hook 'post-command-hook 'lsp-ui-sideline nil t) + (advice-add 'company-pseudo-tooltip-frontend :before 'lsp-ui-sideline--hide-before-company) + (add-hook 'lsp-after-diagnostics-hook 'lsp-ui-sideline--diagnostics-changed nil t) + (setq-local flycheck-display-errors-function nil)) + (t + (setq lsp-ui-sideline--tag nil) + (advice-remove 'company-pseudo-tooltip-frontend 'lsp-ui-sideline--hide-before-company) + (lsp-ui-sideline--delete-ov) + (remove-hook 'lsp-after-diagnostics-hook 'lsp-ui-sideline--diagnostics-changed) + (remove-hook 'post-command-hook 'lsp-ui-sideline t)))) + +(defun lsp-ui-sideline-enable (enable) + "Enable/disable `lsp-ui-sideline-mode'." + (lsp-ui-sideline-mode (if enable 1 -1))) + +(provide 'lsp-ui-sideline) +;;; lsp-ui-sideline.el ends here diff --git a/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-sideline.elc b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-sideline.elc new file mode 100644 index 000000000000..5591772830df --- /dev/null +++ b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui-sideline.elc Binary files differdiff --git a/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui.el b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui.el new file mode 100644 index 000000000000..d56dd34d5773 --- /dev/null +++ b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui.el @@ -0,0 +1,165 @@ +;;; lsp-ui.el --- UI modules for lsp-mode -*- lexical-binding: t; -*- + +;; Copyright (C) 2017 Tobias Pisani + +;; Author: Tobias Pisani <topisani@hamsterpoison.com> +;; Keywords: lsp +;; URL: https://github.com/emacs-lsp/lsp-ui +;; Package-Requires: ((emacs "25.1") (dash "2.13") (dash-functional "1.2.0") (flycheck "31") (lsp-mode "4.0") (markdown-mode "2.3")) +;; Version: 0.0.1 + +;; Permission is hereby granted, free of charge, to any person obtaining a copy +;; of this software and associated documentation files (the "Software"), to deal +;; in the Software without restriction, including without limitation the rights +;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +;; copies of the Software, and to permit persons to whom the Software is +;; furnished to do so, subject to the following conditions: + +;; The above copyright notice and this permission notice shall be included in +;; all copies or substantial portions of the Software. + +;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +;; SOFTWARE. + +;;; Commentary: + +;; lsp-ui contains a series of useful UI integrations for lsp-mode, like +;; flycheck support and code lenses. + +;;; Code: + +(defgroup lsp-ui nil + "‘lsp-ui’ contains a series of useful UI integrations for ‘lsp-mode’." + :group 'tools + :group 'convenience + :link '(custom-manual "(lsp-ui) Top") + :link '(info-link "(lsp-ui) Customizing")) + +(require 'lsp-ui-sideline) +(require 'lsp-ui-peek) +(require 'lsp-ui-flycheck) +(require 'lsp-ui-imenu) +(require 'lsp-ui-doc) + +(defun lsp-ui-peek--render (major string) + (with-temp-buffer + (insert string) + (delay-mode-hooks + (let ((inhibit-message t)) + (funcall major)) + (ignore-errors + (font-lock-ensure))) + (buffer-string)) + ) + + +(defun lsp-ui--workspace-path (path) + "Return the PATH relative to the workspace. +If the PATH is not in the workspace, it returns the original PATH." + (let* ((path (file-truename path)) + (root (lsp--workspace-root lsp--cur-workspace)) + (in-workspace (string-prefix-p root path))) + (if in-workspace + (substring path (length root)) + path))) + +(defun lsp-ui--toggle (enable) + (dolist (feature '(lsp-ui-flycheck lsp-ui-peek lsp-ui-sideline lsp-ui-doc lsp-ui-imenu)) + (let* ((sym (intern-soft (concat (symbol-name feature) "-enable"))) + (value (symbol-value sym)) + (fn (symbol-function sym))) + (when (and (or value (not enable)) + (functionp fn)) + (funcall fn enable))))) + +(defvar lsp-ui-mode-map (make-sparse-keymap)) + +;;;###autoload +(define-minor-mode lsp-ui-mode + "Toggle language server UI mode on or off. +‘lsp-ui-mode’ is a minor mode that contains a series of useful UI +integrations for ‘lsp-mode’. With a prefix argument ARG, enable +language server UI mode if ARG is positive, and disable it +otherwise. If called from Lisp, enable the mode if ARG is +omitted or nil, and toggle it if ARG is ‘toggle’." + :init-value nil + :group lsp-ui + :keymap lsp-ui-mode-map + (lsp-ui--toggle lsp-ui-mode)) + +;; The request is delegated to xref-backend-apropos defined in lsp-mode. +;; xref-find-apropos does similar job but is less appealing because it splits and +;; regex quotes the pattern. The language server likely knows more about how +;; to do fuzzy matching. +(defun lsp-ui-find-workspace-symbol (pattern) + "List project-wide symbols matching the query string PATTERN." + (interactive (list (read-string + "workspace/symbol: " + nil 'xref--read-pattern-history))) + (xref--find-xrefs pattern 'apropos pattern nil)) + +(defun lsp-ui--location< (x y) + "Compares two triples X and Y. +Both should have the form (FILENAME LINE COLUMN)." + (if (not (string= (car x) (car y))) + (string< (car x) (car y)) + (if (not (= (cadr x) (cadr y))) + (< (cadr x) (cadr y)) + (< (caddr x) (caddr y))))) + +(defun lsp-ui--reference-triples (filter-fn) + "Return references as a list of (FILENAME LINE COLUMN) triples." + (let ((refs (lsp--send-request (lsp--make-request + "textDocument/references" + (lsp--make-reference-params))))) + (sort + (mapcar + (lambda (ref) + (-let* (((&hash "uri" uri "range" range) ref) + ((&hash "line" line "character" col) (gethash "start" range))) + (list (lsp--uri-to-path uri) line col))) + (if filter-fn (--filter (funcall filter-fn it) refs) refs)) + #'lsp-ui--location<))) + +;; TODO Make it efficient +(defun lsp-ui-find-next-reference (&optional filter-fn) + "Find next reference of the symbol at point." + (interactive) + (let* ((cur (list buffer-file-name (lsp--cur-line) (lsp--cur-column))) + (refs (lsp-ui--reference-triples filter-fn)) + (idx -1) + (res (-first (lambda (ref) (cl-incf idx) (lsp-ui--location< cur ref)) refs))) + (if res + (progn + (find-file (car res)) + (goto-char 1) + (forward-line (cadr res)) + (forward-char (caddr res)) + (cons idx (length refs))) + (cons 0 0)))) + +;; TODO Make it efficient +(defun lsp-ui-find-prev-reference (&optional filter-fn) + "Find previous reference of the symbol at point." + (interactive) + (let* ((cur (list buffer-file-name (lsp--cur-line) (lsp--cur-column))) + (refs (lsp-ui--reference-triples filter-fn)) + (idx -1) + (res (-last (lambda (ref) (and (lsp-ui--location< ref cur) (cl-incf idx))) refs))) + (if res + (progn + (find-file (car res)) + (goto-char 1) + (forward-line (cadr res)) + (forward-char (caddr res)) + (cons idx (length refs))) + (cons 0 0)))) + + +(provide 'lsp-ui) +;;; lsp-ui.el ends here diff --git a/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui.elc b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui.elc new file mode 100644 index 000000000000..531f9ff19c8b --- /dev/null +++ b/configs/shared/emacs/.emacs.d/elpa/lsp-ui-20180619.251/lsp-ui.elc Binary files differ |