Skip to content

Commit

Permalink
Merge pull request #53 from wasamasa/fix-reparsing-todo
Browse files Browse the repository at this point in the history
Use `buffer-chars-modified-tick` to reparse less
  • Loading branch information
felipeochoa authored Oct 9, 2017
2 parents 487ce00 + f5cf35b commit c19d07a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions rjsx-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -775,14 +775,16 @@ closing tag was parsed."
(throw 'rjsx-eof-while-parsing t))
(t (js2-add-to-string c)))))))

(js2-deflocal rjsx-buffer-chars-modified-tick 0 "Variable holding the last per-buffer value of `buffer-chars-modified-tick'.")

(defun rjsx-maybe-reparse ()
"Called before accessing the parse tree.
For small buffers, will do an immediate reparse to ensure the
parse tree is up to date."
;; TODO: We could look at the last parse time and the last buffer
;; modification time to avoid some reparsing
(when (<= (point-max) rjsx-max-size-for-frequent-reparse)
(js2-reparse)))
(when (and (<= (point-max) rjsx-max-size-for-frequent-reparse)
(/= rjsx-buffer-chars-modified-tick (buffer-chars-modified-tick)))
(js2-reparse)
(setq rjsx-buffer-chars-modified-tick (buffer-chars-modified-tick))))

(defun rjsx--tag-at-point ()
"Return the JSX tag at point, if any, or nil."
Expand Down

0 comments on commit c19d07a

Please sign in to comment.