Implement index insertion for new cache
ci/woodpecker/push/woodpecker Pipeline failed Details

WIP-cache
Hugo Thunnissen 8 months ago
parent 3e00c0647a
commit 50a8570252

@ -221,7 +221,7 @@ linked with."
(unless (memq (cdr class) indexed)
(let (imports namespace-name class-name class-obj)
(pcase-setq `(,imports ,namespace-name) (phpinspect-get-token-index-context namespaces buffer-imports (cdr class))
`(,class-name) (phpinspect--index-class-declaration
`(,_ign ,class-name) (phpinspect--index-class-declaration
(car class)
(phpinspect--make-type-resolver
(phpinspect--uses-to-types imports)
@ -236,7 +236,7 @@ linked with."
(phpinspect-splayt-traverse (class classes)
(pcase-let* ((declaration (phpinspect-toc-token-at-or-after-point declarations (phpinspect-meta-start class)))
(`(,imports ,namespace-name) (phpinspect-get-token-index-context namespaces buffer-imports class))
(`(,class-name) (phpinspect--index-class-declaration
(`(,_type ,class-name) (phpinspect--index-class-declaration
(phpinspect-meta-token declaration)
(phpinspect--make-type-resolver
(phpinspect--uses-to-types imports)

@ -595,6 +595,14 @@ then returned."
(cdr vals)))
(defun phpinspect--alist-keys (alist)
(let* ((keys (cons nil nil))
(keys-rear keys))
(dolist (cell alist)
(setq keys-rear (setcdr keys-rear (cons (car cell) nil))))
(cdr keys)))
(defun phpinspect-cache-query--do-delete-method (cache group param type member)
(when-let ((member-type
(car
@ -775,17 +783,62 @@ then returned."
(t (error "Insert not supported for entity type %s" type))))
(defun phpinspect-cache-query--do-get-type-wildcard (group param type namespace)
(if namespace
(when-let ((namespace (phpinspect-cache-group-get-namespace group namespace)))
(cons 'phpinspect-cache-multiresult
(mapcar #'cdr (phpinspect-cache-namespace-types namespace))))
(cons
'phpinspect-cache-multiresult
(mapcan
(lambda (namespace)
(mapcar #'cdr (phpinspect-cache-namespace-types namespace)))
(hash-table-values (phpinspect-cache-group-namespaces group))))))
(let* ((all
(if namespace
(when-let ((namespace (phpinspect-cache-group-get-namespace group namespace)))
(phpinspect--alist-values (phpinspect-cache-namespace-types namespace)))
(mapcan
(lambda (namespace)
(mapcar #'cdr (phpinspect-cache-namespace-types namespace)))
(hash-table-values (phpinspect-cache-group-namespaces group)))))
filtered)
(if (eq '@type type)
(setq filtered all)
(dolist (row all)
(when (eq (phpinspect-cache-type-category row) type)
(push row filtered))))
(cons 'phpinspect-cache-multiresult filtered)))
(defun phpinspect-cache-insert-index (cache group-spec index)
(cl-assert (eq 'phpinspect--root-index (car index)))
(phpinspect-cache-transact cache group-spec
:insert (alist-get 'functions index)
:as @function)
(dolist (class (alist-get 'classes index))
(let ((class-name (alist-get 'class-name class)))
(pcase (alist-get 'type class)
('@trait
(phpinspect-cache-transact cache group-spec
:insert class-name :as @trait))
('@interface
(phpinspect-cache-transact cache group-spec
:insert class-name :as @interface))
('@class
(phpinspect-cache-transact cache group-spec
:insert class-name
:implementing (alist-get 'implements class)
:extending (alist-get 'extending class)
:as @class))
(_ (error "Unexpected class type: %s" (alist-get 'type class))))
(phpinspect-cache-transact cache group-spec
:insert (append (alist-get 'methods class)
(alist-get 'static-methods class))
:as @method
:member-of class-name)
(phpinspect-cache-transact cache group-spec
:insert (append (alist-get 'variables class)
(alist-get 'constants class)
(alist-get 'static-variabes class))
:as @variable
:member-of class-name))))
(defun phpinspect-cache-query--do-get-type
(group param type member namespace implements extends)

@ -93,7 +93,7 @@ Conditionally executes BODY depending on
(cl-defmethod phpinspect--class-update-declaration
((class phpinspect--class) declaration imports namespace-name)
(phpinspect--class-edit class
(pcase-let ((`(,class-name ,extends ,implements ,_used-types)
(pcase-let ((`(,_ign ,class-name ,extends ,implements ,_used-types)
(phpinspect--index-class-declaration
declaration (phpinspect--make-type-resolver
(phpinspect--uses-to-types imports) nil namespace-name))))

@ -227,14 +227,15 @@ function (think \"new\" statements, return types etc.)."
(comment-before)
;; The types that are used within the code of this class' methods.
(used-types)
(add-used-types))
(add-used-types)
(class-type))
(setq add-used-types
(lambda (additional-used-types)
(if used-types
(nconc used-types additional-used-types)
(setq used-types additional-used-types))))
(pcase-setq `(,class-name ,extends ,implements ,used-types)
(pcase-setq `(,class-type ,class-name ,extends ,implements ,used-types)
(phpinspect--index-class-declaration (cadr class) type-resolver))
@ -337,6 +338,7 @@ function (think \"new\" statements, return types etc.)."
`(,class-name .
(phpinspect--indexed-class
(type . ,class-type)
(complete . ,(not (phpinspect-incomplete-class-p class)))
(class-name . ,class-name)
(declaration . ,(seq-find #'phpinspect-declaration-p class))

@ -352,7 +352,7 @@ mutability of the variable")
(defun phpinspect--index-class-declaration (decl type-resolver)
;; Find out what the class extends or implements
(let (encountered-extends encountered-implements encountered-class
class-name extends implements used-types)
class-name extends implements used-types class-type)
(dolist (word decl)
(if (phpinspect-word-p word)
(cond ((string= (cadr word) "extends")
@ -362,10 +362,11 @@ mutability of the variable")
(setq encountered-extends nil)
(phpinspect--log "Class %s implements in interface" class-name)
(setq encountered-implements t))
((string-match-p
(eval-when-compile
(concat "^" (phpinspect--class-keyword-handler-regexp) "?$"))
(cadr word))
((and (not encountered-class)
(setq class-type (pcase (cadr word)
("class" '@class)
("interface" '@interface)
("trait" '@trait))))
(setq encountered-class t))
(t
(phpinspect--log "Calling Resolver from index-class on %s" (cadr word))
@ -383,7 +384,7 @@ mutability of the variable")
(setq class-name (funcall type-resolver (phpinspect--make-type :name (cadr word)))
encountered-class nil)))))))
(list class-name extends implements used-types)))
(list class-type class-name extends implements used-types)))
(defun phpinspect-namespace-name (namespace)
(or (and (phpinspect-namespace-p namespace)

@ -514,3 +514,97 @@
:get *
:as @variable
:member-of (phpinspect--make-type :name "\\TestClass")))))
(ert-deftest phpinspect-cache-insert-index ()
(let ((cache (phpinspect-make-cache))
(index (phpinspect--index-tokens
(phpinspect-parse-string
"<?php
function foo() {};
namespace Bar;
class Baz {
private $boo;
const BEE;
function baa() {}
}
interface Banana {
function shouldImplement(): void;
}
trait Atrait {
function isOftenEvil() {}
}"))))
(phpinspect-cache-insert-index cache '((label test)) index)
(let ((result (phpinspect-cache-transact cache '((label test))
:get * :as @interface)))
(should result)
(should (= 1 (length result)))
(should (phpinspect--type= (phpinspect--make-type :name "\\Bar\\Banana")
(phpinspect--make-type
:name-symbol
(phpinspect-cache-type-name (car result)))))
(setq result (phpinspect-cache-transact cache '((label test))
:get * :as @class))
(should result)
(should (= 1 (length result)))
(should (phpinspect--type= (phpinspect--make-type :name "\\Bar\\Baz")
(phpinspect--make-type
:name-symbol
(phpinspect-cache-type-name (car result)))))
(setq result (phpinspect-cache-transact cache '((label test))
:get * :as @trait))
(should result)
(should (= 1 (length result)))
(should (phpinspect--type= (phpinspect--make-type :name "\\Bar\\Atrait")
(phpinspect--make-type
:name-symbol
(phpinspect-cache-type-name (car result)))))
(setq result (phpinspect-cache-transact cache '((label test))
:get *
:as @variable
:member-of (phpinspect--make-type :name "\\Bar\\Baz")))
(should result)
(should (= 2 (length result)))
(setq result (phpinspect-cache-transact cache '((label test))
:get *
:as @method
:member-of (phpinspect--make-type :name "\\Bar\\Baz")))
(should result)
(should (= 1 (length result)))
(setq result (phpinspect-cache-transact cache '((label test))
:get *
:as @method
:member-of (phpinspect--make-type :name "\\Bar\\Banana")))
(should result)
(should (= 1 (length result)))
(should (string= "shouldImplement"
(phpinspect--function-name (car result))))
(setq result (phpinspect-cache-transact cache '((label test))
:get * :as @type :in (phpinspect-intern-name "\\Bar")))
(should result)
(should (= 3 (length result)))
(setq result (phpinspect-cache-transact cache '((label test))
:get * :as @function))
(should result)
(should (= 1 (length result)))
(should (string= "foo"
(phpinspect--function-name (car result)))))))

@ -53,6 +53,7 @@
(classes
(,(phpinspect--make-type :name "\\Potato" :fully-qualified t)
phpinspect--indexed-class
(type . @class)
(complete . t)
(class-name . ,(phpinspect--make-type :name "\\Potato" :fully-qualified t))
(declaration . (:declaration (:word "class") (:word "Potato")))

Loading…
Cancel
Save