Skip to content

Commit

Permalink
fix: Semshi throwing errors on Python 3.12
Browse files Browse the repository at this point in the history
Print a warning message "python3.12 is unsupported" instead of emitting
intimidating unhandled exception errors..
  • Loading branch information
wookayin committed Sep 25, 2023
1 parent c803165 commit cc40bb9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions rplugin/python3/semshi/plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Optional, cast
from functools import partial, wraps
import sys

import pynvim
import pynvim.api
Expand Down Expand Up @@ -46,12 +47,25 @@ class Plugin:

def __init__(self, vim: pynvim.api.Nvim):
self._vim = vim

# A mapping (buffer number -> buffer handler)
self._handlers = {}
# The currently active buffer handler
self._cur_handler: Optional[BufferHandler] = None
self._options = None

# Python version check
if (3, 6) <= sys.version_info < (3, 12):
self._disabled = False
else:
self._disabled = True
self.echom("Semshi currently supports Python 3.6 - 3.11. " +
"(Current: {})".format(sys.version.split()[0]))

def echom(self, msg: str):
args = ([[msg, "WarningMsg"]], True, {})
self._vim.api.echo(*args)

def _init_with_vim(self):
"""Initialize with vim available.
Expand Down Expand Up @@ -152,6 +166,8 @@ def _internal_eval(self, args):

@subcommand
def enable(self):
if self._disabled:
return
self._attach_listeners()
self._select_handler(self._vim.current.buffer)
self._update_viewport(*self._vim.eval('[line("w0"), line("w$")]'))
Expand Down Expand Up @@ -202,6 +218,10 @@ def error(self):

@subcommand
def status(self):
if self._disabled:
self.echo('Semshi is disabled: unsupported python version.')
return

buffer: pynvim.api.Buffer = self._vim.current.buffer
attached: bool = buffer.vars.get('semshi_attached', False)

Expand Down

0 comments on commit cc40bb9

Please sign in to comment.