@ -139,7 +139,7 @@
( cadr class-token ) ) ) )
( cadr subtoken ) ) )
( defun phpinspect--index-class ( type-resolver class )
( defun phpinspect--index-class ( imports type-resolver class )
" Create an alist with relevant attributes of a parsed class. "
( phpinspect--log " INDEXING CLASS " )
( let ( ( methods )
@ -267,6 +267,7 @@
( let ( ( class-name ( funcall type-resolver ( phpinspect--make-type :name class-name ) ) ) )
` ( , class-name .
( phpinspect--indexed-class
( imports . , imports )
( methods . , methods )
( class-name . , class-name )
( static-methods . , static-methods )
@ -283,22 +284,26 @@ Accounts for namespaces that are defined with '{}' blocks."
( cdaddr namespace )
( cdr namespace ) ) )
( defun phpinspect--index-classes ( type s classes &optional namespace indexed )
" Index the class tokens in ` classes ` , using the types in ` type s`
( defun phpinspect--index-classes ( import s classes &optional namespace indexed )
" Index the class tokens in ` classes ` , using the imports in ` import s`
as Fully Qualified names. ` namespace ` will be assumed the root
namespace if not provided "
( if classes
( let ( ( class ( pop classes ) ) )
( push ( phpinspect--index-class
( phpinspect--make-type-resolver types class namespace )
imports
( phpinspect--make-type-resolver imports class namespace )
class )
indexed )
( phpinspect--index-classes type s classes namespace indexed ) )
( phpinspect--index-classes import s classes namespace indexed ) )
( nreverse indexed ) ) )
( defun phpinspect--use-to-type ( use )
( let* ( ( fqn ( cadr ( cadr use ) ) )
( type ( phpinspect--make-type :name fqn :fully-qualified t ) )
( type ( phpinspect--make-type :name ( if ( string-match " ^ \\ \\ " fqn )
fqn
( concat " \\ " fqn ) )
:fully-qualified t ) )
( type-name ( if ( and ( phpinspect-word-p ( caddr use ) )
( string= " as " ( cadr ( caddr use ) ) ) )
( cadr ( cadddr use ) )
@ -327,16 +332,18 @@ namespace if not provided"
( defun phpinspect--index-tokens ( tokens )
" Index TOKENS as returned by ` phpinspect--parse-current-buffer ` . "
( let ( ( imports ( phpinspect--uses-to-types ( seq-filter #' phpinspect-use-p tokens ) ) ) )
` ( phpinspect--root-index
( imports . , imports )
, ( append
( append ' ( classes )
( phpinspect--index-namespaces ( seq-filter #' phpinspect-namespace-p tokens ) )
( phpinspect--index-classes
( phpinspect--uses-to-types ( seq-filter #' phpinspect-use-p tokens ) )
imports
( seq-filter #' phpinspect-class-p tokens ) ) ) )
( functions ) )
;; TODO: Implement function indexation
)
) )
( defun phpinspect-index-file ( file-name )
( phpinspect--index-tokens ( phpinspect-parse-file file-name ) ) )
@ -379,15 +386,17 @@ namespace if not provided"
( defsubst phpinspect--make-queue ( &optional subscription )
( phpinspect--make-queue-item :subscription subscription ) )
;; Recursion causes max-eval-depth error here for long queues. Hence the loop
;; implementation for these two functions.
( cl-defmethod phpinspect--queue-last ( ( item phpinspect--queue-item ) )
( if ( phpinspect--queue-item-next item )
( phpinspect--queue-last ( phpinspect--queue-item-next item ) )
item ) )
( while ( phpinspect--queue-item-next item )
( setq item ( phpinspect--queue-item-next item ) ) )
item )
( cl-defmethod phpinspect--queue-first ( ( item phpinspect--queue-item ) )
( if ( phpinspect--queue-item-previous item )
( phpinspect--queue-first ( phpinspect--queue-item-previous item ) )
item ) )
( while ( phpinspect--queue-item-previous item )
( setq item ( phpinspect--queue-item-previous item ) ) )
item )
( cl-defmethod phpinspect--queue-enqueue ( ( item phpinspect--queue-item ) thing )
( let ( ( last ( phpinspect--queue-last item ) ) )
@ -478,10 +487,10 @@ namespace if not provided"
;; and skipped, as we haven't done any intensive work that
;; may cause hangups.
( setq skip-pause t ) )
( let ( ( type -index ( phpinspect--index-t ype
project
( phpinspect--index-task-type task ) ) ) )
( when type-index ( phpinspect--project-add-class project type -index) ) ) ) ) )
( let * ( ( type ( phpinspect--index-t ask-t ype task ) )
( root-index ( phpinspect--index-type-file project type ) ) )
( when root-index
( phpinspect--project-add-index project root -index) ) ) ) ) )
;; else: join with the main thread until wakeup is signaled
( thread-join main-thread ) )
@ -535,8 +544,9 @@ namespace if not provided"
( defsubst phpinspect--make-index-task ( project-root type )
( list project-root type ) )
( cl-defmethod phpinspect--index-type ( ( project phpinspect--project )
( cl-defmethod phpinspect--index-type -file ( ( project phpinspect--project )
( type phpinspect--type ) )
( condition-case error
( let* ( ( class-file ( with-temp-buffer
( cd ( phpinspect--project-root project ) )
( phpinspect-type-filepath type ) ) )
@ -545,13 +555,16 @@ namespace if not provided"
( class-index ) )
( when class-file
( if visited-buffer
( setq new-index ( with-current-buffer visited-buffer
( phpinspect--index-current-buffer ) ) )
( setq new-index ( phpinspect-index-file class-file ) ) )
( alist-get type ( alist-get 'classes new-index )
nil
nil
#' phpinspect--type= ) ) ) )
( with-current-buffer visited-buffer ( phpinspect--index-current-buffer ) )
( phpinspect-index-file class-file ) ) ) )
( file-missing
( phpinspect--log " Failed to find file for type %s: %s " type error )
nil ) ) )
( defsubst phpinspect--index-thread-enqueue ( task )
( phpinspect--queue-enqueue-noduplicate phpinspect--index-queue
task
#' phpinspect--index-task= ) )
( provide 'phpinspect-index )
;;; phpinspect-index.el ends here