From 2ee80f0b84bdaa3f5d4fc7c128cfdd8aae421d9b Mon Sep 17 00:00:00 2001 From: Gerard Vermeulen Date: Tue, 8 Feb 2022 13:34:50 +0100 Subject: [PATCH] Simplify the logic with respect to the pylsp server patch --- README.org | 40 +++++++++++++++++++-------------- pylsp-auto-import-modules.patch | 6 ++--- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/README.org b/README.org index 3d4f505..2eeb0bf 100644 --- a/README.org +++ b/README.org @@ -2369,32 +2369,38 @@ functions are neither builtin methods nor data instances but a kind of "callable instances", the [[https://docs.python.org/3/library/inspect.html][Python inspect]] module also fails to handle the universal functions properly. -Listing [[lst:make-pylsp-server-patch]] generates listing -[[lst:show-pylsp-server-patch]] that shows the patch to make [[https://jedi.readthedocs.io/en/latest/][jedi]] import -[[https://numpy.org/][numpy-1.22.0]] in order to serve the information to [[https://github.com/python-lsp/python-lsp-server][python-lsp-server]] allowing it -to handle universal functions. Listing [[lst:show-pylsp-server-patch]] tangles to -=pylsp-auto-import-modules.patch=. +Listing [[lst:make-pylsp-server-patch]] generates and listing +[[lst:echo-pylsp-server-patch]] echos the patch in listing +[[lst:show-pylsp-server-patch]] to make [[https://jedi.readthedocs.io/en/latest/][jedi]] import [[https://numpy.org/][numpy-1.22.2]] in order to serve +the information to [[https://github.com/python-lsp/python-lsp-server][python-lsp-server]] allowing it to handle universal functions. #+caption[Make =pylsp-auto-import-modules.patch= listing]: #+caption: Make =pylsp-auto-import-modules.patch= listing. #+name: lst:make-pylsp-server-patch -#+begin_src shell :exports both :results drawer :shebang - echo "#+attr_latex: :options breaklines" - echo "#+caption[Show and tangle =pylsp-auto-import-modules.patch=]:" - echo "#+caption: Show and tangle =pylsp-auto-import-modules.patch=." - echo "#+name: lst:show-pylsp-server-patch" - echo "#+begin_src diff :exports code :tangle pylsp-auto-import-modules.patch" - git -C $HOME/VCS/python-lsp-server diff - echo "#+end_src" +#+begin_src shell :exports code :results none + git -C $HOME/VCS/python-lsp-server diff >pylsp-auto-import-modules.patch #+end_src -#+RESULTS: lst:make-pylsp-server-patch +#+caption[Echo =pylsp-auto-import-modules.patch= listing]: +#+caption: Echo =pylsp-auto-import-modules.patch= listing. +#+name: lst:echo-pylsp-server-patch +#+begin_src shell :exports both :results drawer + echo "#+attr_latex: :options breaklines" + echo "#+caption[Show =pylsp-auto-import-modules.patch=]:" + echo "#+caption: Show =pylsp-auto-import-modules.patch=." + echo "#+name: lst:show-pylsp-server-patch" + echo "#+begin_src diff :tangle no" + cat pylsp-auto-import-modules.patch + echo -n "#+end_src" +#+end_src + +#+RESULTS: lst:echo-pylsp-server-patch :results: #+attr_latex: :options breaklines -#+caption[Show and tangle =pylsp-auto-import-modules.patch=]: -#+caption: Show and tangle =pylsp-auto-import-modules.patch=. +#+caption[Show =pylsp-auto-import-modules.patch=]: +#+caption: Show =pylsp-auto-import-modules.patch=. #+name: lst:show-pylsp-server-patch -#+begin_src diff :exports code :tangle pylsp-auto-import-modules.patch +#+begin_src diff :tangle no diff --git a/pylsp/config/schema.json b/pylsp/config/schema.json index c29d78b..4f30101 100644 --- a/pylsp/config/schema.json diff --git a/pylsp-auto-import-modules.patch b/pylsp-auto-import-modules.patch index e9c1cee..033751e 100644 --- a/pylsp-auto-import-modules.patch +++ b/pylsp-auto-import-modules.patch @@ -22,16 +22,16 @@ index bf312f6..4758b53 100644 --- a/pylsp/workspace.py +++ b/pylsp/workspace.py @@ -14,6 +14,8 @@ from . import lsp, uris, _utils - + log = logging.getLogger(__name__) - + +DEFAULT_AUTO_IMPORT_MODULES = ["numpy", "gi"] + # TODO: this is not the best e.g. we capture numbers RE_START_WORD = re.compile('[A-Za-z_0-9]*$') RE_END_WORD = re.compile('^[A-Za-z_0-9]*') @@ -252,6 +254,8 @@ class Document: - + if self._config: jedi_settings = self._config.plugin_settings('jedi', document_path=self.path) + jedi.settings.auto_import_modules = jedi_settings.get('auto_import_modules',