Skip to content

Improve lsp--buffer-string-visible performance, avoide headvy generate-new-buffer #4794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* Changelog
** Unreleased 9.0.1
* Improve lsp--buffer-string-visible performance, avoide headvy generate-new-buffer
* Add format on save support
* Fix beancount journal file init option
* Add support for [[https://github.com/glehmann/earthlyls][earthlyls]]
Expand Down
32 changes: 15 additions & 17 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -5554,23 +5554,21 @@ MODE is the mode used in the parent frame."
(goto-char end))))))

(defun lsp--buffer-string-visible ()
"Return visible buffer string.
Stolen from `org-copy-visible'."
(let ((temp (generate-new-buffer " *temp*"))
(beg (point-min))
(end (point-max)))
(while (/= beg end)
(when (get-char-property beg 'invisible)
(setq beg (next-single-char-property-change beg 'invisible nil end)))
(let* ((next (next-single-char-property-change beg 'invisible nil end))
(substring (buffer-substring beg next)))
(with-current-buffer temp (insert substring))
;; (setq result (concat result substring))
(setq beg next)))
(setq deactivate-mark t)
(prog1 (with-current-buffer temp
(s-chop-suffix "\n" (buffer-string)))
(kill-buffer temp))))
"Return a string of the buffer's visible text."
(let ((beg (point-min))
(end (point-max))
(parts '()))
(while (< beg end)
(when (get-char-property beg 'invisible)
(setq beg (next-single-char-property-change beg 'invisible nil end)))
(let ((next (next-single-char-property-change beg 'invisible nil end)))
(push (buffer-substring-no-properties beg next) parts)
(setq beg next)))
(setq parts (nreverse parts))
(let ((result (apply #'concat parts)))
(if (string-suffix-p "\n" result)
(substring result 0 -1)
result))))

(defvar lsp-buffer-major-mode nil
"Holds the major mode when fontification function is running.
Expand Down