Skip to content

Commit 6f26bd4

Browse files
committed
Fix tide failure in magit buffers.
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. This commit makes it so that tide detects that it is running in a magit buffer and aborts.
1 parent 8a7c1fc commit 6f26bd4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tide.el

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,6 +2088,15 @@ current buffer."
20882088
tide--minimal-emacs emacs-version)
20892089
:error))
20902090

2091+
;; When a user uses magit to extract old commits of files, magit creates
2092+
;; buffers for those commits. These buffers are not backed by actual
2093+
;; files. However, magit "cheats" and sets `buffer-file-name' when it turns on
2094+
;; the modes on the file. So when this code runs in such a buffer,
2095+
;; `buffer-file-name' is set, even though the buffer is not backed by a file
2096+
;; on disk. So we need this check to handle such cases.
2097+
(when (bound-and-true-p magit-buffer-file-name)
2098+
(error "Cannot run tide in a buffer created by magit"))
2099+
20912100
;; Indirect buffers embedded in other major modes such as those in org-mode or
20922101
;; template languages have to be manually synchronized to tsserver. This might
20932102
;; cause problems in files with lots of small blocks of TypeScript. In that
@@ -2096,6 +2105,7 @@ current buffer."
20962105
(unless (stringp buffer-file-name)
20972106
(setq tide-require-manual-setup t))
20982107

2108+
20992109
(set (make-local-variable 'eldoc-documentation-function)
21002110
'tide-eldoc-function)
21012111
(set (make-local-variable 'imenu-auto-rescan) t)

0 commit comments

Comments
 (0)