Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Plugin entry point."""
# pylint: disable=broad-except
import re
from contextlib import contextmanager
import logging
import logging.config
from typing import Dict
import pynvim # type: ignore
from gdb.common import BaseCommon, Common
from gdb.app import App
from gdb.config import Config
from gdb.logger import LOGGING_CONFIG
@pynvim.plugin
class Gdb(Common):
"""Plugin implementation."""
def __init__(self, vim):
"""ctor."""
logging.config.dictConfig(LOGGING_CONFIG)
common = BaseCommon(vim, None)
super().__init__(common)
self.apps: Dict[int, App] = {}
self.ansi_escaper = re.compile(r'\x1B[@-_][0-?]*[ -/]*[@-~]')
def _get_app(self):
return self.apps.get(self.vim.current.tabpage.handle, None)
@pynvim.function('GdbInit', sync=True)
def gdb_init(self, args):
WaitingForSearchTimeout = 5.0
class ProjectInfo:
def __init__(self):
self.idMap = ReadWriteLockableValue({})
self.nameMap = ReadWriteLockableValue({})
self.totalCount = LockableValue(0)
self.isUpdating = LockableValue(True)
class FileInfo:
def __init__(self, path, name):
self.path = path
self.name = name
self.modificationTime = ReadWriteLockableValue(datetime.min)
@pynvim.plugin
class Marksman(object):
def __init__(self, nvim):
self._nvim = nvim
self._hasInitialized = False
@pynvim.function('MarksmanForceRefresh')
def forceRefresh(self, args):
self._lazyInit()
assert len(args) == 1, 'Wrong number of arguments to MarksmanForceRefresh'
rootPath = self._getCanonicalPath(args[0])
info = self._getProjectInfo(rootPath)
if info.isUpdating.getValue():
import typing
from importlib.util import find_spec
if find_spec('yarp'):
import vim
elif find_spec('pynvim'):
import pynvim as vim
from pynvim import Nvim
if hasattr(vim, 'plugin'):
# Neovim only
from deoppet.deoppet import Deoppet
@vim.plugin
class DeoppetHandlers(object):
def __init__(self, vim: Nvim) -> None:
self._vim = vim
@vim.function('_deoppet_init', sync=False) # type: ignore
def init_channel(self, args: typing.List[str]) -> None:
self._vim.vars['deoppet#_channel_id'] = self._vim.channel_id
self._deoppet = Deoppet(self._vim)
@vim.function('_deoppet_mapping', sync=True) # type: ignore
def mapping(self, args: typing.List[str]) -> None:
self._deoppet.mapping(args[0])
@vim.function('_deoppet_event', sync=True) # type: ignore
def event(self, args: typing.List[str]) -> None:
from importlib.util import find_spec
from defx.rplugin import Rplugin
if find_spec('yarp'):
import vim
else:
import pynvim as vim
Args = typing.List[typing.Any]
if hasattr(vim, 'plugin'):
# Neovim only
@vim.plugin
class DefxHandlers:
def __init__(self, vim: vim.Nvim) -> None:
self._rplugin = Rplugin(vim)
@vim.function('_defx_init', sync=True) # type: ignore
def init_channel(self, args: Args) -> None:
self._rplugin.init_channel()
@vim.rpc_export('_defx_start', sync=True) # type: ignore
def start(self, args: Args) -> None:
self._rplugin.start(args)
@vim.rpc_export('_defx_do_action', sync=True) # type: ignore
def do_action(self, args: Args) -> None:
self._rplugin.do_action(args)