|
77 | 77 | :priority 0
|
78 | 78 | :server-id 'ocaml-lsp-server))
|
79 | 79 |
|
| 80 | +(defcustom lsp-cut-signature 'space |
| 81 | + "If non-nil, signatures returned on hover will not be split on newline." |
| 82 | + :group 'lsp-ocaml |
| 83 | + :type '(choice (symbol :tag "Default behaviour" 'cut) |
| 84 | + (symbol :tag "Display all the lines with spaces" 'space))) |
| 85 | + |
| 86 | +(cl-defmethod lsp-clients-extract-signature-on-hover (contents (_server-id (eql ocamllsp)) &optional storable) |
| 87 | + "Extract a representative line from OCaml's CONTENTS, to show in the echo area. |
| 88 | +This function splits the content between the signature |
| 89 | +and the documentation to display the signature |
| 90 | +and truncate it if it's too wide. |
| 91 | +The STORABLE argument is used if you want to use this |
| 92 | +function to get the type and, for example, kill and yank it. |
| 93 | +
|
| 94 | +An example of function using STORABLE is: |
| 95 | +
|
| 96 | + (defun mdrp/lsp-get-type-and-kill () |
| 97 | + (interactive) |
| 98 | + (let ((contents (-some->> (lsp--text-document-position-params) |
| 99 | + (lsp--make-request \"textDocument/hover\") |
| 100 | + (lsp--send-request) |
| 101 | + (lsp:hover-contents)))) |
| 102 | + (let ((contents (and contents |
| 103 | + (lsp--render-on-hover-content |
| 104 | + contents |
| 105 | + t)))) |
| 106 | + (let ((contents |
| 107 | + (pcase (lsp-workspaces) |
| 108 | + (`(,workspace) |
| 109 | + (lsp-clients-extract-signature-on-hover |
| 110 | + contents |
| 111 | + (lsp--workspace-server-id workspace) |
| 112 | + t)) |
| 113 | + (lsp-clients-extract-signature-on-hover |
| 114 | + contents |
| 115 | + nil) |
| 116 | + ))) |
| 117 | + (message \"Copied %s to kill-ring\" contents) |
| 118 | + (kill-new contents)))))" |
| 119 | + (let ((type (s-trim (lsp--render-element (lsp-make-marked-string |
| 120 | + :language "ocaml" |
| 121 | + :value (car (s-split "---" (lsp--render-element contents)))))))) |
| 122 | + (if (equal nil storable) |
| 123 | + (if (eq lsp-cut-signature 'cut) |
| 124 | + (car (s-lines type)) |
| 125 | + ;; else lsp-cut-signature is 'space |
| 126 | + (let ((ntype (s-replace "\n" " " type))) |
| 127 | + (if (>= (length ntype) (frame-width)) |
| 128 | + (concat (substring ntype 0 (- (frame-width) 4)) "...") |
| 129 | + ntype))) |
| 130 | + type))) |
80 | 131 |
|
81 | 132 | (lsp-consistency-check lsp-ocaml)
|
82 | 133 |
|
|
0 commit comments