Skip to content

Commit

Permalink
Merge pull request emacs-lsp#323 from sebastiencs/fix-narrowed
Browse files Browse the repository at this point in the history
Fix lsp-mode on narrowed buffer
  • Loading branch information
vibhavp authored Mar 26, 2018
2 parents 9576201 + 4bed19a commit 7244ec9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 6 additions & 4 deletions lsp-common.el
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@
(defun lsp--position-to-point (params)
"Convert Position object in PARAMS to a point."
(save-excursion
(goto-char (point-min))
(forward-line (gethash "line" params))
(forward-char (gethash "character" params))
(point)))
(save-restriction
(widen)
(goto-char (point-min))
(forward-line (gethash "line" params))
(forward-char (gethash "character" params))
(point))))

;;; TODO: Use the current LSP client name instead of lsp-mode for the type.
(defun lsp-warn (message &rest args)
Expand Down
12 changes: 6 additions & 6 deletions lsp-methods.el
Original file line number Diff line number Diff line change
Expand Up @@ -868,15 +868,16 @@ interface Position {

(define-inline lsp--cur-position ()
"Make a Position object for the current point."
(inline-quote (lsp--position (lsp--cur-line) (lsp--cur-column))))
(inline-quote
(save-restriction
(widen)
(lsp--position (lsp--cur-line) (lsp--cur-column)))))

(defun lsp--point-to-position (point)
"Convert POINT to Position."
(save-excursion
(goto-char point)
(save-restriction
(widen) ;; May be in a narrowed region
(lsp--cur-position))))
(lsp--cur-position)))

(define-inline lsp--position-p (p)
(inline-quote
Expand Down Expand Up @@ -1219,8 +1220,7 @@ Added to `after-change-functions'."
If IDENTIFIER and POSITION are non-nil, they will be used as the document identifier
and the position respectively."
(inline-quote (list :textDocument (or ,identifier (lsp--text-document-identifier))
:position (or ,position
(lsp--position (lsp--cur-line) (lsp--cur-column))))))
:position (or ,position (lsp--cur-position)))))

(define-inline lsp--text-document-code-action-params ()
"Make CodeActionParams for the current region in the current document."
Expand Down

0 comments on commit 7244ec9

Please sign in to comment.