diff --git a/.gitignore b/.gitignore index 9dfdcfc74a..8267c9df55 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ *.elc /benchmarks/profile.txt -/.cask \ No newline at end of file +/.cask + +# ELPA-generated files +/phpinspect-autoloads.el +/phpinspect-pkg.el diff --git a/benchmarks/parse-file.el b/benchmarks/parse-file.el index 604ba2e833..7bea574fa6 100644 --- a/benchmarks/parse-file.el +++ b/benchmarks/parse-file.el @@ -1,3 +1,4 @@ +;; -*- lexical-binding: t; -*- (require 'phpinspect-parser) @@ -13,25 +14,25 @@ (message "Incremental parse (warmup):") (phpinspect-with-parse-context (phpinspect-make-pctx :incremental t) - (benchmark 1 '(phpinspect-parse-current-buffer))) + (benchmark-run 1 (phpinspect-parse-current-buffer))) (let ((bmap (phpinspect-make-bmap)) (bmap2 (phpinspect-make-bmap))) (message "Incremental parse:") (phpinspect-with-parse-context (phpinspect-make-pctx :incremental t :bmap bmap) - (benchmark 1 '(phpinspect-parse-current-buffer))) + (benchmark-run 1 (phpinspect-parse-current-buffer))) (garbage-collect) (message "Incremental parse (no edits):") (phpinspect-with-parse-context (phpinspect-make-pctx :incremental t :bmap bmap2 :previous-bmap bmap :edtrack (phpinspect-make-edtrack)) - (benchmark 1 '(phpinspect-parse-current-buffer))) + (benchmark-run 1 (phpinspect-parse-current-buffer))) (garbage-collect) (message "Incremental parse repeat (no edits):") (phpinspect-with-parse-context (phpinspect-make-pctx :incremental t :previous-bmap bmap2 :edtrack (phpinspect-make-edtrack)) - (benchmark 1 '(phpinspect-parse-current-buffer))) + (benchmark-run 1 (phpinspect-parse-current-buffer))) (garbage-collect) @@ -45,13 +46,13 @@ (message "Incremental parse after buffer edit:") ;; Removes closing curly brace of __construct (goto-char 9062) - (delete-backward-char 1) + (delete-char -1) (garbage-collect) (phpinspect-edtrack-register-edit edtrack 9061 9061 1) (phpinspect-with-parse-context (phpinspect-make-pctx :bmap bmap-after :incremental t :previous-bmap bmap :edtrack edtrack) - (benchmark 1 '(phpinspect-parse-current-buffer))) + (benchmark-run 1 (phpinspect-parse-current-buffer))) (phpinspect-edtrack-clear edtrack) (insert "{") @@ -65,7 +66,7 @@ ;;(profiler-start 'cpu) (message "Incremental parse after 2 more edits:") (phpinspect-with-parse-context (phpinspect-make-pctx :incremental t :previous-bmap bmap-after :edtrack edtrack) - (benchmark 1 '(phpinspect-parse-current-buffer))) + (benchmark-run 1 (phpinspect-parse-current-buffer))) ;; (save-current-buffer ;; (profiler-stop) @@ -78,9 +79,9 @@ (garbage-collect) (message "Bare (no token reuse) parse (warmup):") - (benchmark 1 '(phpinspect-parse-current-buffer)) + (benchmark-run 1 (phpinspect-parse-current-buffer)) (garbage-collect) (message "Bare (no token reuse) parse:") - (benchmark 1 '(phpinspect-parse-current-buffer)))) + (benchmark-run 1 (phpinspect-parse-current-buffer)))) diff --git a/benchmarks/splay-tree.el b/benchmarks/splay-tree.el index 261ddfe08a..934487d199 100644 --- a/benchmarks/splay-tree.el +++ b/benchmarks/splay-tree.el @@ -1,3 +1,4 @@ +;; -*- lexical-binding: t; -*- (require 'phpinspect-splayt) @@ -6,28 +7,28 @@ (tree (phpinspect-make-splayt))) (message "Splay tree 10000 insertions:") (garbage-collect) - (benchmark - 1 '(dotimes (i 10000) - (phpinspect-splayt-insert tree i 'value))) + (benchmark-run + 1 (dotimes (i 10000) + (phpinspect-splayt-insert tree i 'value))) (message "Splay tree 10000 lookups:") (garbage-collect) - (benchmark - 1 '(dotimes (i 10000) - (phpinspect-splayt-find tree i)))) + (benchmark-run + 1 (dotimes (i 10000) + (phpinspect-splayt-find tree i)))) (let (map) (message "Hashtable 10000 insertions:") (garbage-collect) - (benchmark - 1 '(progn - (setq map (make-hash-table :test #'eq :size 10000 :rehash-size 1.5)) - (dotimes (i 10000) - (puthash i 'value map)))) + (benchmark-run + 1 (progn + (setq map (make-hash-table :test #'eq :size 10000 :rehash-size 1.5)) + (dotimes (i 10000) + (puthash i 'value map)))) (message "Hashtable 10000 lookups:") (garbage-collect) - (benchmark - 1 '(dotimes (i 10000) - (gethash i map)))) + (benchmark-run + 1 (dotimes (i 10000) + (gethash i map)))) diff --git a/phpinspect-bmap.el b/phpinspect-bmap.el index 0fded42705..2f2796e6fe 100644 --- a/phpinspect-bmap.el +++ b/phpinspect-bmap.el @@ -1,6 +1,6 @@ ;;; phpinspect-bmap.el --- PHP parsing and completion package -*- lexical-binding: t; -*- -;; Copyright (C) 2021 Free Software Foundation, Inc +;; Copyright (C) 2021-2023 Free Software Foundation, Inc ;; Author: Hugo Thunnissen ;; Keywords: php, languages, tools, convenience @@ -25,7 +25,7 @@ (require 'phpinspect-splayt) (require 'phpinspect-meta) -(require 'phpinspect-changeset) +;; (require 'phpinspect-changeset) ;; FIXME: Circular dependency :-( (require 'phpinspect-util) (require 'compat) diff --git a/phpinspect-cache.el b/phpinspect-cache.el index cdf89ee124..e33029378a 100644 --- a/phpinspect-cache.el +++ b/phpinspect-cache.el @@ -1,6 +1,6 @@ ;;; phpinspect.el --- PHP parsing and completion package -*- lexical-binding: t; -*- -;; Copyright (C) 2021 Free Software Foundation, Inc +;; Copyright (C) 2021-2023 Free Software Foundation, Inc ;; Author: Hugo Thunnissen ;; Keywords: php, languages, tools, convenience @@ -45,8 +45,7 @@ If its value is nil, it is created and then returned." "A `hash-table` with the root directories of projects as keys and project caches as values.")) -(cl-defgeneric phpinspect--cache-getproject - ((cache phpinspect--cache) (project-name string)) +(cl-defgeneric phpinspect--cache-getproject (cache project-name) "Get project by PROJECT-NAME that is located in CACHE.") (cl-defmethod phpinspect--cache-getproject diff --git a/phpinspect-changeset.el b/phpinspect-changeset.el index 7f19ed2201..382de3c730 100644 --- a/phpinspect-changeset.el +++ b/phpinspect-changeset.el @@ -1,6 +1,6 @@ ;;; phpinspect-changeset.el --- Metadata changeset module -*- lexical-binding: t; -*- -;; Copyright (C) 2021 Free Software Foundation, Inc +;; Copyright (C) 2021-2023 Free Software Foundation, Inc ;; Author: Hugo Thunnissen ;; Keywords: php, languages, tools, convenience @@ -23,6 +23,8 @@ ;;; Code: +(require 'phpinspect-parse-context) ;; FIXME: Circular dependency :-( + (define-inline phpinspect-make-changeset (meta) (inline-letevals (meta) (inline-quote diff --git a/phpinspect-completion.el b/phpinspect-completion.el index 59b7d7d823..f5546169d8 100644 --- a/phpinspect-completion.el +++ b/phpinspect-completion.el @@ -1,6 +1,6 @@ ;;; phpinspect-type.el --- PHP parsing and completion package -*- lexical-binding: t; -*- -;; Copyright (C) 2021 Free Software Foundation, Inc +;; Copyright (C) 2021-2023 Free Software Foundation, Inc ;; Author: Hugo Thunnissen ;; Keywords: php, languages, tools, convenience @@ -97,11 +97,11 @@ candidate. Candidates can be indexed functions and variables.") :type phpinspect-buffer)) -(cl-defgeneric phpinspect-comp-strategy-supports (strategy (query phpinspect-completion-query) (context phpinspect--resolvecontext)) +(cl-defgeneric phpinspect-comp-strategy-supports (strategy query context) "Should return non-nil if STRATEGY should be deployed for QUERY and CONTEXT. All strategies must implement this method.") -(cl-defgeneric phpinspect-comp-strategy-execute (strategy (query phpinspect-completion-query) (context phpinspect--resolvecontext)) +(cl-defgeneric phpinspect-comp-strategy-execute (strategy query context) "Should return a list of objects for which `phpinspect--make-completion' is implemented.") diff --git a/phpinspect-edtrack.el b/phpinspect-edtrack.el index bd065932ca..96fb77579b 100644 --- a/phpinspect-edtrack.el +++ b/phpinspect-edtrack.el @@ -24,6 +24,7 @@ ;;; Code: (require 'phpinspect-util) +(require 'phpinspect-meta) (eval-when-compile (phpinspect--declare-log-group 'edtrack)) @@ -73,11 +74,6 @@ (defsubst phpinspect-edit-original-end (edit) (or (caar edit) 0)) -(defsubst phpinspect-edit-end (edit) - (let ((end (or (caar edit) 0)) - (previous-edit (cdr edit))) - (+ end (phpinspect-edit-delta previous-edit)))) - (defsubst phpinspect-edit-delta (edit) (let ((delta (or (cdar edit) 0)) (previous-edit edit)) @@ -85,6 +81,11 @@ (setq delta (+ delta (cdar previous-edit)))) delta)) +(defsubst phpinspect-edit-end (edit) + (let ((end (or (caar edit) 0)) + (previous-edit (cdr edit))) + (+ end (phpinspect-edit-delta previous-edit)))) + (defsubst phpinspect-edtrack-original-position-at-point (track point) (let ((edit (phpinspect-edtrack-edits track)) (encroached) diff --git a/phpinspect-eldoc.el b/phpinspect-eldoc.el index 8efa9b7e72..a1a28a6984 100644 --- a/phpinspect-eldoc.el +++ b/phpinspect-eldoc.el @@ -1,6 +1,6 @@ ;;; phpinspect-eldoc.el --- PHP parsing and completion package -*- lexical-binding: t; -*- -;; Copyright (C) 2021 Free Software Foundation, Inc +;; Copyright (C) 2021-2023 Free Software Foundation, Inc ;; Author: Hugo Thunnissen ;; Keywords: php, languages, tools, convenience @@ -26,6 +26,7 @@ (require 'phpinspect-meta) (require 'phpinspect-parser) (require 'phpinspect-resolve) +(require 'phpinspect-buffer) (defvar phpinspect-eldoc-word-width 14 "The maximum width of words in eldoc strings.") @@ -38,11 +39,11 @@ :type phpinspect-buffer)) -(cl-defgeneric phpinspect-eld-strategy-supports (strategy (query phpinspect-eldoc-query) (context phpinspect--resolvecontext)) +(cl-defgeneric phpinspect-eld-strategy-supports (strategy query context) "Should return non-nil if STRATEGY should be deployed for QUERY and CONTEXT. All strategies must implement this method.") -(cl-defgeneric phpinspect-eld-strategy-execute (strategy (query phpinspect-eldoc-query) (context phpinspect--resolvecontext)) +(cl-defgeneric phpinspect-eld-strategy-execute (strategy query context) "Should return an object for which `phpinspect-eldoc-string' is implemented.") (cl-defgeneric phpinspect-eldoc-string (response) diff --git a/phpinspect-parse-context.el b/phpinspect-parse-context.el index fb2ae38db2..b3fcf12ffd 100644 --- a/phpinspect-parse-context.el +++ b/phpinspect-parse-context.el @@ -1,6 +1,6 @@ ;;; phpinspect-parse-context.el --- PHP parsing context module -*- lexical-binding: t; -*- -;; Copyright (C) 2021 Free Software Foundation, Inc +;; Copyright (C) 2021, 2023 Free Software Foundation, Inc ;; Author: Hugo Thunnissen ;; Keywords: php, languages, tools, convenience @@ -25,7 +25,7 @@ (require 'phpinspect-util) (require 'phpinspect-meta) -(require 'phpinspect-changeset) +;; (require 'phpinspect-changeset) ;; FIXME: Circular dependency :-( (require 'phpinspect-bmap) (defvar phpinspect-parse-context nil @@ -36,7 +36,7 @@ parsing. Usually used in combination with (cl-defstruct (phpinspect-pctx (:constructor phpinspect-make-pctx)) "Parser Context" (incremental nil) - (interrupt-threshold (time-convert '(2 . 1000)) + (interrupt-threshold (time-convert '(2 . 1000) t) :documentation "After how much time `interrupt-predicate' should be polled. This is 2ms by default.") @@ -98,7 +98,7 @@ thrown.") (inline-quote (progn (unless (phpinspect-pctx--start-time ,pctx) - (setf (phpinspect-pctx--start-time ,pctx) (time-convert nil))) + (setf (phpinspect-pctx--start-time ,pctx) (time-convert nil t))) ;; Interrupt when blocking too long while input is pending. (when (and (time-less-p (phpinspect-pctx-interrupt-threshold ,pctx) @@ -107,6 +107,12 @@ thrown.") (phpinspect-pctx-cancel ,pctx) (throw 'phpinspect-parse-interrupted nil)))))) + +(defsubst phpinspect-pctx-consume-whitespace (pctx) + (let ((whitespace (phpinspect-pctx-whitespace-before pctx))) + (setf (phpinspect-pctx-whitespace-before pctx) "") + whitespace)) + (define-inline phpinspect-pctx-register-token (pctx token start end) (inline-letevals (pctx) (inline-quote @@ -117,11 +123,6 @@ thrown.") (inline-quote (setf (phpinspect-pctx-whitespace-before ,pctx) ,whitespace))) -(defsubst phpinspect-pctx-consume-whitespace (pctx) - (let ((whitespace (phpinspect-pctx-whitespace-before pctx))) - (setf (phpinspect-pctx-whitespace-before pctx) "") - whitespace)) - (defun phpinspect-pctx-cancel (pctx) (phpinspect--log "Cancelling parse context") (dolist (changeset (phpinspect-pctx-changesets pctx)) diff --git a/phpinspect-parser.el b/phpinspect-parser.el index d3d70a348b..fc1ae56734 100644 --- a/phpinspect-parser.el +++ b/phpinspect-parser.el @@ -1,6 +1,6 @@ ;;; phpinspect-parser.el --- PHP parsing module -*- lexical-binding: t; -*- -;; Copyright (C) 2021 Free Software Foundation, Inc +;; Copyright (C) 2021-2023 Free Software Foundation, Inc ;; Author: Hugo Thunnissen ;; Keywords: php, languages, tools, convenience @@ -79,17 +79,18 @@ Type can be any of the token types returned by (phpinspect-comma-p token) (phpinspect-html-p token))) -(defsubst phpinspect-end-of-statement-p (token) - (or (phpinspect-end-of-token-p token) - (phpinspect-block-p token))) - (defsubst phpinspect-incomplete-block-p (token) (phpinspect-token-type-p token :incomplete-block)) + (defsubst phpinspect-block-p (token) (or (phpinspect-token-type-p token :block) (phpinspect-incomplete-block-p token))) +(defsubst phpinspect-end-of-statement-p (token) + (or (phpinspect-end-of-token-p token) + (phpinspect-block-p token))) + (defun phpinspect-end-of-use-p (token) (or (phpinspect-block-p token) (phpinspect-end-of-token-p token))) @@ -184,6 +185,10 @@ Type can be any of the token types returned by (or (phpinspect-token-type-p token :array) (phpinspect-incomplete-array-p token))) + +(defsubst phpinspect-root-p (object) + (phpinspect-token-type-p object :root)) + (defsubst phpinspect-incomplete-root-p (token) (and (phpinspect-root-p token) (seq-find #'phpinspect-incomplete-token-p (cdr token)))) @@ -227,10 +232,6 @@ Type can be any of the token types returned by (defun phpinspect-use-keyword-p (token) (and (phpinspect-word-p token) (string= (car (last token)) "use"))) - -(defsubst phpinspect-root-p (object) - (phpinspect-token-type-p object :root)) - (defsubst phpinspect-namespace-or-root-p (object) (or (phpinspect-namespace-p object) (phpinspect-root-p object))) @@ -261,6 +262,7 @@ Type can be any of the token types returned by "Apply inverse of `phpinspect-class-p' to TOKEN." (not (phpinspect-class-p token))) +(eval-and-compile (defun phpinspect-handler-func-name (handler-name) (intern (concat "phpinspect--" (symbol-name handler-name) "-handler"))) @@ -268,7 +270,7 @@ Type can be any of the token types returned by (intern (concat "phpinspect--" (symbol-name handler-name) "-handler-regexp"))) (defun phpinspect-parser-func-name (name &optional suffix) - (intern (concat "phpinspect--parse-" (symbol-name name) (if suffix (concat "-" suffix) "")))) + (intern (concat "phpinspect--parse-" (symbol-name name) (if suffix (concat "-" suffix) ""))))) (defmacro phpinspect-defhandler (name arguments docstring attribute-alist &rest body) "Define a parser handler that becomes available for use with phpinspect-parse. @@ -552,15 +554,12 @@ parsing incrementally." (incremental-name (phpinspect-parser-func-name name "incremental"))) `(let ((parser (phpinspect-make-parser ,@parameters))) - (defconst ,simple-name nil) - (defconst ,incremental-name nil) + (defconst ,simple-name parser) + (defconst ,incremental-name parser) (put (quote ,simple-name) 'phpinspect--parser t) (put (quote ,incremental-name) 'phpinspect--incremental-parser t) - (setf ,simple-name parser) - (setf ,incremental-name parser) - ;; Stub function to please the byte compiler (real function will be ;; defined by `phpinspect-define-parser-functions'. (defun ,func-name (_buffer _max-point &optional _continue-condition _root))))) diff --git a/phpinspect-pipeline.el b/phpinspect-pipeline.el index 3c3069d1f0..3ae2a14a3c 100644 --- a/phpinspect-pipeline.el +++ b/phpinspect-pipeline.el @@ -1,6 +1,6 @@ ;;; phpinspect-pipeline.el --- PHP parsing and completion package -*- lexical-binding: t; -*- -;; Copyright (C) 2021 Free Software Foundation, Inc +;; Copyright (C) 2021-2023 Free Software Foundation, Inc ;; Author: Hugo Thunnissen ;; Keywords: php, languages, tools, convenience @@ -276,8 +276,12 @@ directories." (when (eq :with-context key) (setq value `(quote ,value))) (setq key (intern (string-replace ":with-" ":" (symbol-name key)))) + ;; FIXME: There's an O(N²) complexity here :-( (setq construct-params (nconc construct-params (list key value))))) - (push (eval `(phpinspect--make-pipeline-step ,@construct-params :name (quote ,name))) + ;; FIXME: Instead of constructing an expression to pass to `eval', + ;; with all the quoting that implies, can't we create a list of + ;; values to pass to `apply', saving untold kittens along the way? + (push (eval `(phpinspect--make-pipeline-step ,@construct-params :name (quote ,name)) t) steps))) (_ (error "unexpected key %s" key)))) @@ -320,7 +324,7 @@ directories." ,queue-sym (phpinspect-make-pipeline-end :thread (current-thread))) (while ,collecting-sym - (ignore-error 'phpinspect-pipeline-incoming + (ignore-error phpinspect-pipeline-incoming (progn (phpinspect-pipeline--register-wakeup-function ,end-queue-sym) (while (not (phpinspect-pipeline-end-p diff --git a/phpinspect-project.el b/phpinspect-project.el index 0df08d9821..8a04993fbf 100644 --- a/phpinspect-project.el +++ b/phpinspect-project.el @@ -1,6 +1,6 @@ ;;; phpinspect-project.el --- PHP parsing and completion package -*- lexical-binding: t; -*- -;; Copyright (C) 2021 Free Software Foundation, Inc +;; Copyright (C) 2021-2023 Free Software Foundation, Inc ;; Author: Hugo Thunnissen ;; Keywords: php, languages, tools, convenience @@ -265,6 +265,13 @@ before the search is executed." (cl-defmethod phpinspect-project-add-file-index ((project phpinspect-project) (filename string)) (phpinspect-project-add-index project (phpinspect-project-index-file project filename))) +(defcustom phpinspect-projects nil + "PHPInspect Projects." + :type '(alist :key-type string + :value-type (alist :key-type symbol + :options ((include-dirs (repeat string))))) + :group 'phpinspect) + (defun phpinspect-project-enqueue-include-dirs (project) (interactive (list (phpinspect--cache-get-project-create (phpinspect--get-or-create-global-cache) @@ -279,13 +286,6 @@ before the search is executed." (phpinspect-project-worker project) (phpinspect-make-index-dir-task :dir dir :project project))))) -(defcustom phpinspect-projects nil - "PHPInspect Projects." - :type '(alist :key-type string - :value-type (alist :key-type symbol - :options ((include-dirs (repeat string))))) - :group 'phpinspect) - (defun phpinspect-project-add-include-dir (dir) "Configure DIR as an include dir for the current project." (interactive (list (read-directory-name "Include Directory: "))) diff --git a/phpinspect-resolve.el b/phpinspect-resolve.el index 76e2159249..a2442e6b54 100644 --- a/phpinspect-resolve.el +++ b/phpinspect-resolve.el @@ -1,6 +1,6 @@ ;;; phpinspect-resolve.el --- PHP parsing and completion package -*- lexical-binding: t; -*- -;; Copyright (C) 2021 Free Software Foundation, Inc +;; Copyright (C) 2021-2023 Free Software Foundation, Inc ;; Author: Hugo Thunnissen ;; Keywords: php, languages, tools, convenience @@ -26,6 +26,7 @@ (require 'phpinspect-resolvecontext) (require 'phpinspect-type) (require 'phpinspect-parser) +(require 'phpinspect-index) ;For `phpinspect-get-or-create-cached-project-class'. (cl-defstruct (phpinspect--assignment (:constructor phpinspect--make-assignment)) diff --git a/phpinspect-type.el b/phpinspect-type.el index 8fc60064fa..d4b27b59e1 100644 --- a/phpinspect-type.el +++ b/phpinspect-type.el @@ -1,6 +1,6 @@ ;;; phpinspect-type.el --- Data structures that represent phpinspect types -*- lexical-binding: t; -*- -;; Copyright (C) 2021 Free Software Foundation, Inc +;; Copyright (C) 2021-2023 Free Software Foundation, Inc ;; Author: Hugo Thunnissen ;; Keywords: php, languages, tools, convenience @@ -24,6 +24,8 @@ ;;; Code: (require 'phpinspect-util) +(require 'phpinspect-parser) ;For `phpinspect-const-p'. +;; (require 'phpinspect-index) ;FIXME: Circular dependency :-( (cl-defstruct (phpinspect--type (:constructor phpinspect--make-type-generated) @@ -230,7 +232,7 @@ return type of the function.")) (cl-defmethod phpinspect--function-set-name ((func phpinspect--function) (name string)) (setf (phpinspect--function-name-symbol func) (intern name phpinspect-name-obarray))) -(cl-defgeneric phpinspect--function-name ((func phpinspect--function))) +(cl-defgeneric phpinspect--function-name (func)) (cl-defmethod phpinspect--function-name ((func phpinspect--function)) (symbol-name (phpinspect--function-name-symbol func))) diff --git a/phpinspect-util.el b/phpinspect-util.el index 190bfec77f..fc723800bd 100644 --- a/phpinspect-util.el +++ b/phpinspect-util.el @@ -1,6 +1,6 @@ ;;; phpinspect-util.el --- PHP parsing and completion package -*- lexical-binding: t; -*- -;; Copyright (C) 2021 Free Software Foundation, Inc +;; Copyright (C) 2021-2023 Free Software Foundation, Inc ;; Author: Hugo Thunnissen ;; Keywords: php, languages, tools, convenience @@ -31,6 +31,25 @@ PHP. Used to optimize string comparison.") '("composer.json" "composer.lock" ".git" ".svn" ".hg") "List of files that could indicate a project root directory.") +(eval-and-compile (defvar phpinspect-log-groups nil)) + +(defmacro phpinspect--log (&rest args) + (let ((log-group (alist-get (if (fboundp 'macroexp-file-name) ;Emacs≥28 + (macroexp-file-name) + (or load-file-name buffer-file-name)) + phpinspect-log-groups nil nil #'string=))) + `(when (and phpinspect--debug + (or (not phpinspect-enabled-log-groups) + ,(when log-group + `(member (quote ,log-group) phpinspect-enabled-log-groups)))) + (with-current-buffer (get-buffer-create "**phpinspect-logs**") + (unless window-point-insertion-type + (set (make-local-variable 'window-point-insertion-type) t)) + (goto-char (buffer-end 1)) + (insert (concat "[" (format-time-string "%H:%M:%S") "]: " + ,(if log-group (concat "(" (symbol-name log-group) ") ") "") + (format ,@args) "\n")))))) + (defun phpinspect--find-project-root (&optional start-file) "(Attempt to) Find the root directory of the visited PHP project. If a found project root has a parent directory called \"vendor\", @@ -65,7 +84,6 @@ level of START-FILE in stead of `default-directory`." (message "Enabled phpinspect logging.") (message "Disabled phpinspect logging."))) -(defvar phpinspect-log-groups nil) (defvar phpinspect-enabled-log-groups nil) (defvar-local phpinspect--current-log-group nil) @@ -85,20 +103,6 @@ level of START-FILE in stead of `default-directory`." (phpinspect--declare-log-group 'bam) -(defmacro phpinspect--log (&rest args) - (let ((log-group (alist-get (or load-file-name buffer-file-name) phpinspect-log-groups nil nil #'string=))) - `(when (and phpinspect--debug - (or (not phpinspect-enabled-log-groups) - ,(when log-group - `(member (quote ,log-group) phpinspect-enabled-log-groups)))) - (with-current-buffer (get-buffer-create "**phpinspect-logs**") - (unless window-point-insertion-type - (set (make-local-variable 'window-point-insertion-type) t)) - (goto-char (buffer-end 1)) - (insert (concat "[" (format-time-string "%H:%M:%S") "]: " - ,(if log-group (concat "(" (symbol-name log-group) ") ") "") - (format ,@args) "\n")))))) - (defun phpinspect-filter-logs (group-name) (interactive (list (completing-read "Log group: " (mapcar (lambda (g) (symbol-name (cdr g))) diff --git a/phpinspect-worker.el b/phpinspect-worker.el index 0d42dd73bf..bc9c5a2855 100644 --- a/phpinspect-worker.el +++ b/phpinspect-worker.el @@ -1,6 +1,6 @@ ;;; phpinspect-worker.el --- PHP parsing and completion package -*- lexical-binding: t; -*- -;; Copyright (C) 2021 Free Software Foundation, Inc +;; Copyright (C) 2021-2023 Free Software Foundation, Inc ;; Author: Hugo Thunnissen ;; Keywords: php, languages, tools, convenience @@ -134,7 +134,7 @@ already present in the queue." ;; This error is used to wake up the thread when new tasks are added to the ;; queue. (condition-case err - (ignore-error 'phpinspect-wakeup-thread + (ignore-error phpinspect-wakeup-thread (let* ((task (phpinspect-queue-dequeue (phpinspect-worker-queue worker))) (mx (make-mutex)) (continue (make-condition-variable mx))) @@ -238,8 +238,7 @@ already present in the queue." :documentation "The type whose file should be indexed.")) -(cl-defgeneric phpinspect-make-index-task ((project phpinspect-project) - (type phpinspect--type)) +(cl-defgeneric phpinspect-make-index-task (project type) (phpinspect-make-index-task-generated :project project :type type)) diff --git a/phpinspect.el b/phpinspect.el index e42f92c3e4..3110bb48b6 100644 --- a/phpinspect.el +++ b/phpinspect.el @@ -1,6 +1,6 @@ ;;; phpinspect.el --- PHP parsing and completion package -*- lexical-binding: t; -*- -;; Copyright (C) 2021 Free Software Foundation, Inc +;; Copyright (C) 2021-2023 Free Software Foundation, Inc ;; Author: Hugo Thunnissen ;; Keywords: php, languages, tools, convenience @@ -179,14 +179,14 @@ at point (capf) functions: (defun my-php-personal-hook () ;; Shortcut to add use statements for classes you use. - (define-key php-mode-map (kbd \"C-c u\") 'phpinspect-fix-imports) + (define-key php-mode-map (kbd \"C-c u\") #\\='phpinspect-fix-imports) ;; Shortcuts to quickly search/open files of PHP classes. ;; You can make these local to php-mode, but making them global ;; like this makes them work in other modes/filetypes as well, which ;; can be handy when jumping between templates, config files and PHP code. - (global-set-key (kbd \"C-c a\") 'phpinspect-find-class-file) - (global-set-key (kbd \"C-c c\") 'phpinspect-find-own-class-file) + (global-set-key (kbd \"C-c a\") #\\='phpinspect-find-class-file) + (global-set-key (kbd \"C-c c\") #\\='phpinspect-find-own-class-file) ;; Enable phpinspect-mode (phpinspect-mode)) @@ -316,7 +316,7 @@ currently opened projects." (defun phpinspect-get-all-fqns (&optional filter) "Return a list of all FQNS congruent with FILTER in the currently active project. -FILTER must be nil or the symbol 'own' if FILTER is 'own', only +FILTER must be nil or the symbol `own' if FILTER is `own', only fully qualified names from the project's source, and not its dependencies, are returned." (let* ((project (phpinspect--cache-get-project-create