Fully reindex buffer after save

master
Hugo Thunnissen 1 month ago
parent 9877166986
commit e9ffa3a0ad

@ -33,6 +33,8 @@
(require 'phpinspect-resolve) (require 'phpinspect-resolve)
(require 'phpinspect-util) (require 'phpinspect-util)
(phpinspect--declare-log-group 'buffer)
(defvar-local phpinspect-current-buffer nil (defvar-local phpinspect-current-buffer nil
"An instance of `phpinspect-buffer' local to the active "An instance of `phpinspect-buffer' local to the active
buffer. This variable is only set for buffers where buffer. This variable is only set for buffers where
@ -106,11 +108,13 @@ linked with."
(gethash token (phpinspect-buffer-token-index buffer))) (gethash token (phpinspect-buffer-token-index buffer)))
(cl-defmethod phpinspect-buffer-set-index-reference-for-token ((buffer phpinspect-buffer) token index) (cl-defmethod phpinspect-buffer-set-index-reference-for-token ((buffer phpinspect-buffer) token index)
(phpinspect--log "Setting index reference for token %s" token)
(unless (phpinspect-probably-token-p token) (unless (phpinspect-probably-token-p token)
(error "%s does not seem to be a token" token)) (error "%s does not seem to be a token" token))
(puthash token index (phpinspect-buffer-token-index buffer))) (puthash token index (phpinspect-buffer-token-index buffer)))
(cl-defmethod phpinspect-buffer-update-index-reference-for-token ((buffer phpinspect-buffer) old new) (cl-defmethod phpinspect-buffer-update-index-reference-for-token ((buffer phpinspect-buffer) old new)
(phpinspect--log "Updating index reference for old token %s to new token %s" old new)
(unless (and (phpinspect-probably-token-p old) (phpinspect-probably-token-p new)) (unless (and (phpinspect-probably-token-p old) (phpinspect-probably-token-p new))
(when (and old new) (when (and old new)
(error "old and new parameters should be tokens"))) (error "old and new parameters should be tokens")))
@ -123,6 +127,7 @@ linked with."
(unless (phpinspect-probably-token-p token) (unless (phpinspect-probably-token-p token)
(error "%s does not seem to be a token" token)) (error "%s does not seem to be a token" token))
(phpinspect--log "Deleting index for token %s" token)
(cond ((phpinspect-class-p token) (cond ((phpinspect-class-p token)
(when-let ((class (gethash token (phpinspect-buffer-token-index buffer)))) (when-let ((class (gethash token (phpinspect-buffer-token-index buffer))))
(remhash token (phpinspect-buffer-token-index buffer)) (remhash token (phpinspect-buffer-token-index buffer))
@ -299,9 +304,10 @@ linked with."
type-resolver type-resolver
scope scope
(and (phpinspect-comment-p comment-before) comment-before))) (and (phpinspect-comment-p comment-before) comment-before)))
(if static (unless (phpinspect--function-anonyous-p indexed)
(phpinspect--class-set-static-method class-obj indexed) (if static
(phpinspect--class-set-method class-obj indexed)) (phpinspect--class-set-static-method class-obj indexed)
(phpinspect--class-set-method class-obj indexed)))
(phpinspect-buffer-set-index-reference-for-token (phpinspect-buffer-set-index-reference-for-token
buffer (phpinspect-meta-token func) buffer (phpinspect-meta-token func)
@ -421,6 +427,10 @@ linked with."
(setf (phpinspect-buffer-map buffer) (phpinspect-make-bmap)) (setf (phpinspect-buffer-map buffer) (phpinspect-make-bmap))
(setf (phpinspect-buffer-declarations buffer) nil) (setf (phpinspect-buffer-declarations buffer) nil)
(setf (phpinspect-buffer-imports buffer) nil) (setf (phpinspect-buffer-imports buffer) nil)
(setf (phpinspect-buffer-namespaces buffer) nil)
(setf (phpinspect-buffer-classes buffer) nil)
(setf (phpinspect-buffer-class-variables buffer) nil)
(setf (phpinspect-buffer-functions buffer) nil)
(setf (phpinspect-buffer-token-index buffer) (setf (phpinspect-buffer-token-index buffer)
(make-hash-table :test 'eq :size 100 :rehash-size 1.5)) (make-hash-table :test 'eq :size 100 :rehash-size 1.5))
(phpinspect-edtrack-clear (phpinspect-buffer-edit-tracker buffer))) (phpinspect-edtrack-clear (phpinspect-buffer-edit-tracker buffer)))
@ -429,6 +439,13 @@ linked with."
(phpinspect-buffer-reset buffer) (phpinspect-buffer-reset buffer)
(phpinspect-buffer-parse buffer 'no-interrupt)) (phpinspect-buffer-parse buffer 'no-interrupt))
(cl-defmethod phpinspect-buffer-reindex ((buffer phpinspect-buffer))
(dolist (token (hash-table-keys (phpinspect-buffer-token-index buffer)))
(phpinspect-buffer-delete-index-for-token buffer token))
(phpinspect-buffer-reparse buffer)
(phpinspect-buffer-update-project-index buffer))
(cl-defmethod phpinspect-buffer-update-project-index ((buffer phpinspect-buffer)) (cl-defmethod phpinspect-buffer-update-project-index ((buffer phpinspect-buffer))
"Update project index using the last parsed token map of this "Update project index using the last parsed token map of this
buffer. When `phpinspect-buffer-parse' has been executed before buffer. When `phpinspect-buffer-parse' has been executed before
@ -440,12 +457,14 @@ continuing execution."
(unless (phpinspect-buffer-map buffer) (unless (phpinspect-buffer-map buffer)
(phpinspect-buffer-parse buffer)) (phpinspect-buffer-parse buffer))
(phpinspect--log "Preparing to update project index")
;; Use inhibit-quit to prevent index corruption though partial index ;; Use inhibit-quit to prevent index corruption though partial index
;; application. ;; application.
(let ((inhibit-quit t)) (let ((inhibit-quit t))
(when (phpinspect-buffer-project buffer) (when (phpinspect-buffer-project buffer)
(let ((map (phpinspect-buffer-map buffer))) (let ((map (phpinspect-buffer-map buffer)))
(unless (eq map (phpinspect-buffer--last-indexed-bmap buffer)) (unless (eq map (phpinspect-buffer--last-indexed-bmap buffer))
(phpinspect--log "Updating project index")
(phpinspect-buffer-index-imports buffer (phpinspect-bmap-imports map)) (phpinspect-buffer-index-imports buffer (phpinspect-bmap-imports map))
(phpinspect-buffer-index-declarations buffer (phpinspect-bmap-declarations map)) (phpinspect-buffer-index-declarations buffer (phpinspect-bmap-declarations map))
(phpinspect-buffer-index-namespaces buffer (phpinspect-bmap-namespaces map)) (phpinspect-buffer-index-namespaces buffer (phpinspect-bmap-namespaces map))

@ -172,7 +172,7 @@ currently opened projects."
(cl-defmethod phpinspect--cache-get-project-create (cl-defmethod phpinspect--cache-get-project-create
((cache phpinspect--cache) (project-root string)) ((cache phpinspect--cache) (project-root string))
"Get a project that is located in PROJECT-ROOT from CACHE. "Get a project that is located in PROJECT-ROOT from CACHE.
If no such project exists in the cache yet, it is created and If no such project exists in the cache yet, it is created and
then returned." then returned."
(let ((project (phpinspect--cache-get-project cache project-root))) (let ((project (phpinspect--cache-get-project cache project-root)))

@ -241,29 +241,37 @@ indexation, but indexed synchronously before returning."
(phpinspect-project-edit project (phpinspect-project-edit project
(when (and no-enqueue (phpinspect--class-initial-index class)) (when (and no-enqueue (phpinspect--class-initial-index class))
(phpinspect--log "Indexing type file for %s" class-fqn) (phpinspect--log "Indexing type file for %s" class-fqn)
(phpinspect-project-index-type-file project class-fqn))) (phpinspect-project-add-index
project
(phpinspect-project-index-type-file project class-fqn))))
class)) class))
(cl-defmethod phpinspect-project-get-class-extra-or-create (cl-defmethod phpinspect-project-get-class-extra-or-create
((project phpinspect-project) (class-fqn phpinspect--type) &optional no-enqueue) ((project phpinspect-project) (class-fqn phpinspect--type) &optional no-enqueue)
(or (phpinspect-project-get-class-or-extra project class-fqn) (or (phpinspect-project-get-class-or-extra project class-fqn no-enqueue)
(phpinspect-project-get-class-create project class-fqn no-enqueue))) (phpinspect-project-get-class-create project class-fqn no-enqueue)))
(cl-defmethod phpinspect-project-get-class (cl-defmethod phpinspect-project-get-class
((project phpinspect-project) (class-fqn phpinspect--type)) ((project phpinspect-project) (class-fqn phpinspect--type) &optional index)
"Get indexed class by name of CLASS-FQN stored in PROJECT." "Get indexed class by name of CLASS-FQN stored in PROJECT."
(let ((class (gethash (phpinspect--type-name-symbol class-fqn) (let ((class (gethash (phpinspect--type-name-symbol class-fqn)
(phpinspect-project-class-index project)))) (phpinspect-project-class-index project))))
(when (and class (phpinspect-project-read-only-p project) (when class
(not (phpinspect--class-read-only-p class))) (when (and (phpinspect-project-read-only-p project)
(setf (phpinspect--class-read-only-p class) t)) (not (phpinspect--class-read-only-p class)))
(setf (phpinspect--class-read-only-p class) t))
(when (and index (not (phpinspect--class-initial-index class)))
(phpinspect-project-add-index
project
(phpinspect-project-index-type-file project class-fqn))))
class)) class))
(cl-defmethod phpinspect-project-get-class-or-extra (cl-defmethod phpinspect-project-get-class-or-extra
((project phpinspect-project) (class-fqn phpinspect--type)) ((project phpinspect-project) (class-fqn phpinspect--type) &optional index)
(or (phpinspect-project-get-class project class-fqn) (or (phpinspect-project-get-class project class-fqn index)
(and (phpinspect-project-extra-class-retriever project) (and (phpinspect-project-extra-class-retriever project)
(funcall (phpinspect-project-extra-class-retriever project) (funcall (phpinspect-project-extra-class-retriever project)
class-fqn)))) class-fqn))))

@ -30,6 +30,8 @@
(require 'phpinspect-project) (require 'phpinspect-project)
(require 'phpinspect-class) (require 'phpinspect-class)
(phpinspect--declare-log-group 'suggest)
(defun phpinspect-suggest-functions (rctx) (defun phpinspect-suggest-functions (rctx)
(let* ((project (phpinspect--resolvecontext-project rctx))) (let* ((project (phpinspect--resolvecontext-project rctx)))
(phpinspect-project-get-functions-with-extra project))) (phpinspect-project-get-functions-with-extra project)))
@ -76,7 +78,6 @@
"Retrieved class index, starting method collection %s (%s)" "Retrieved class index, starting method collection %s (%s)"
"No class index found in %s for %s") "No class index found in %s for %s")
project-root class-fqn) project-root class-fqn)
(when class (when class
(if static (if static
(phpinspect--class-get-static-method-list class) (phpinspect--class-get-static-method-list class)
@ -138,9 +139,12 @@ static variables and static methods."
(phpinspect--log "Statement type: %s" statement-type) (phpinspect--log "Statement type: %s" statement-type)
(when statement-type (when statement-type
(let ((type (funcall type-resolver statement-type))) (let ((type (funcall type-resolver statement-type)))
(append (phpinspect--get-variables-for-class (when-let ((result
type (append (phpinspect--get-variables-for-class
static) type
(funcall method-lister type))))))) static)
(funcall method-lister type))))
(phpinspect--log "Returning attributes %s" result)
result))))))
(provide 'phpinspect-suggest) (provide 'phpinspect-suggest)

@ -248,6 +248,9 @@ as first element and the type as second element.")
"A phpinspect--type object representing the the "A phpinspect--type object representing the the
return type of the function.")) return type of the function."))
(defun phpinspect--function-anonyous-p (fn)
(eq (phpinspect-intern-name "anonymous") (phpinspect--function-name-symbol fn)))
(defmacro phpinspect--make-function (&rest property-list) (defmacro phpinspect--make-function (&rest property-list)
`(phpinspect--make-function-generated `(phpinspect--make-function-generated
,@(phpinspect--wrap-plist-name-in-symbol property-list))) ,@(phpinspect--wrap-plist-name-in-symbol property-list)))
@ -269,6 +272,9 @@ return type of the function."))
"When the variable is an object attribute, this should "When the variable is an object attribute, this should
contain the scope of the variable as returned by contain the scope of the variable as returned by
`phpinspect-parse-scope'") `phpinspect-parse-scope'")
(readonly nil
:documentation
"Whether or not the variable is readonly")
(lifetime nil (lifetime nil
:documentation :documentation
"The lifetime of the variable (e.g. whether it is static or not). Will "The lifetime of the variable (e.g. whether it is static or not). Will

@ -112,7 +112,7 @@
Reparses the entire buffer without token reuse." Reparses the entire buffer without token reuse."
(when (and (boundp 'phpinspect-mode) phpinspect-mode) (when (and (boundp 'phpinspect-mode) phpinspect-mode)
(phpinspect-buffer-reparse phpinspect-current-buffer))) (phpinspect-buffer-reindex phpinspect-current-buffer)))
(defun phpinspect--disable-mode () (defun phpinspect--disable-mode ()
"Clean up the buffer environment for the mode to be disabled." "Clean up the buffer environment for the mode to be disabled."

Loading…
Cancel
Save