From 6a1c9a6b52103e438dd228a2427fff92af55cee5 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Sun, 17 May 2020 19:15:39 +0100 Subject: [PATCH] Enable embedded vim python debugging This allows us to use vimspector to debug vimspector. The idea is that in Vim you call 'py3 from vimspector.developer import SetUpDebugpy; SetUpDebugpy()' and then just attach to localhost:5678 using the new multi-session mode support. Oof. --- .vimspector.json | 14 +++++++++++ python3/vimspector/developer.py | 42 +++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 .vimspector.json create mode 100644 python3/vimspector/developer.py diff --git a/.vimspector.json b/.vimspector.json new file mode 100644 index 0000000..4a9889e --- /dev/null +++ b/.vimspector.json @@ -0,0 +1,14 @@ +{ + "configurations": { + "Python: Attach To Vim": { + "variables": { + "port": "5678", + "host": "localhost" + }, + "adapter": "multi-session", + "configuration": { + "request": "attach" + } + } + } +} diff --git a/python3/vimspector/developer.py b/python3/vimspector/developer.py new file mode 100644 index 0000000..4945e6a --- /dev/null +++ b/python3/vimspector/developer.py @@ -0,0 +1,42 @@ +# vimspector - A multi-language debugging system for Vim +# Copyright 2020 Ben Jackson +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import sys +import os + +from vimspector import install, utils + + +def SetUpDebugpy( wait=False, port=5678 ): + sys.path.insert( + 1, + os.path.join( install.GetGadgetDir( utils.GetVimspectorBase(), + install.GetOS() ), + 'debugpy', + 'build', + 'lib' ) ) + import debugpy + + exe = sys.executable + try: + # debugpy uses sys.executable (which is `vim`, so we hack it) + sys.executable = 'python3' + debugpy.listen( port ) + finally: + sys.executable = exe + + if wait: + debugpy.wait_for_client()