Skip to content

Commit

Permalink
Fix tide failure in magit buffers.
Browse files Browse the repository at this point in the history
When a user uses magit to extract old commits of files, magit creates buffers
for these commits. These buffers are not backed by actual files. Tide is turned
on in these buffers. Prior to this commit tide would report errors whenever it
tried to contact `tsserver` to work on one of these buffers.
  • Loading branch information
lddubeau committed May 17, 2020
1 parent 8a7c1fc commit 82810b7
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions tide.el
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,18 @@ this variable to non-nil value for Javascript buffers using `setq-local' macro."
"Returns the path to either the currently open file or the
current buffer's parent. This is needed to support indirect
buffers, as they don't set `buffer-file-name' correctly."
(buffer-file-name (or (and (bound-and-true-p edit-indirect--overlay)
(overlay-buffer edit-indirect--overlay))
(and (bound-and-true-p org-src--overlay)
(overlay-buffer org-src--overlay))
;; Needed for org-mode 8.x compatibility
(and (bound-and-true-p org-edit-src-overlay)
(overlay-buffer org-edit-src-overlay))
(buffer-base-buffer))))
;; If magit-buffer-file-name is not nil, then we are in buffer that magit
;; created, and is not backed by a real file. Returning the value of
;; `magit-buffer-file-name' is the best we can do in this case.
(or (bound-and-true-p magit-buffer-file-name)
(buffer-file-name (or (and (bound-and-true-p edit-indirect--overlay)
(overlay-buffer edit-indirect--overlay))
(and (bound-and-true-p org-src--overlay)
(overlay-buffer org-src--overlay))
;; Needed for org-mode 8.x compatibility
(and (bound-and-true-p org-edit-src-overlay)
(overlay-buffer org-edit-src-overlay))
(buffer-base-buffer)))))

;;; Compatibility

Expand Down Expand Up @@ -2093,7 +2097,15 @@ current buffer."
;; cause problems in files with lots of small blocks of TypeScript. In that
;; case we should either add an ignore list or don't do anything at all when
;; there are more than a certain amount of snippets.
(unless (stringp buffer-file-name)
(when (or (not buffer-file-name)
;; When a user uses magit to extract old commits of files, magit
;; creates buffers for those commits. These buffers are not backed
;; by actual files. However, magit "cheats" and sets
;; `buffer-file-name' when it turns on the modes on the file. So
;; when this code runs in such a buffer, `buffer-file-name' is set,
;; even though the buffer is not backed by a file on disk. So we
;; need this extra check to handle such cases.
(bound-and-true-p magit-buffer-file-name))
(setq tide-require-manual-setup t))

(set (make-local-variable 'eldoc-documentation-function)
Expand Down

0 comments on commit 82810b7

Please sign in to comment.