Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions LSP-pyvoice.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
"command_name": "get_spoken",
"session_name": "LSP-pyvoice",
"command_args": ["$file_uri","$position"]
}
}
},
]
]
7 changes: 1 addition & 6 deletions LSP-pyvoice.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
"command": [
"$server_path"
],
// the python interpreter to use for installing and running
// the pyvoice language server. it should be 3.8 and above
// pypy may also work. If null, the plug-in will try to
// automatically pick a suitable interpreter
"python_binary": null,
// environment variables to set when running the language server
"env": {},
// set the log level for the CLIENT SIDE code of the plugin
Expand Down Expand Up @@ -153,4 +148,4 @@
// Set the logging level for the pyvoice executable.
"logging.level": "INFO"
}
}
}
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ This plugin is implemented as an [LSP](https://packagecontrol.io/packages/LSP) p

## Pre-requisites

- Make sure you have some version of [Python](https://www.python.org/downloads/) >= 3.8 installed on your system. This is needed for installing and running the pyvoice executable

- Make sure you have [Package Control](https://packagecontrol.io/installation) installed in Sublime Text. If you install it for the first time, you may need to restart Sublime Text


Expand Down Expand Up @@ -98,7 +96,7 @@ The project builts on top of the standard [LSP client configuration](https://lsp

## Default settings

```json
```jsonc
{
// the command that actually launches the server process
// leave this as is to use the automatically installed
Expand All @@ -107,12 +105,6 @@ The project builts on top of the standard [LSP client configuration](https://lsp
"$server_path"
],

// the python interpreter to use for installing and running
// the pyvoice language server. it should be 3.8 and above
// pypy may also work. If null, the plug-in will try to
// automatically pick a suitable interpreter
"python_binary": null,

// environment variables to set when running the language server
"env": {},

Expand Down Expand Up @@ -316,7 +308,7 @@ To edit the settings for a specific project, click in the menu

and add the following settings

```json
```jsonc
{
"settings":
{
Expand All @@ -335,7 +327,7 @@ and add the following settings

so for example if you want to point pyvoice to a virtual environment your sublime-project file might look like this

```json
```jsonc
{
"settings":
{
Expand All @@ -356,7 +348,7 @@ so for example if you want to point pyvoice to a virtual environment your sublim

or to see debug logs from the server

```json
```jsonc
{
"settings":
{
Expand Down
7 changes: 2 additions & 5 deletions configure_logging.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import logging
import logging.config
import logging.handlers
import os
from __future__ import annotations

import logging
import sublime
import sublime_plugin

DEFAULT_LOG_LEVEL = logging.INFO
DEFAULT_LOG_LEVEL_NAME = logging.getLevelName(DEFAULT_LOG_LEVEL)
Expand Down
5 changes: 3 additions & 2 deletions listener.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import annotations

import logging
import sublime
import threading
import time

import sublime
import sublime_plugin

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -48,7 +50,6 @@ def __init__(self, *args, **kwargs):
def __del__(self):
self.kill_switch = True
self.thread.join(1.0)
super(PyvoiceListener, self).__del__()

def single_update_attempt(self):
logger.debug("Beggining single update attempt")
Expand Down
72 changes: 17 additions & 55 deletions plugin.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,35 @@
import base64
import json
from __future__ import annotations

import logging
import os
from datetime import datetime
from multiprocessing.connection import Client

import sublime
import sublime_plugin
from LSP.plugin import register_plugin, unregister_plugin
from LSP.plugin.core.typing import Dict
from lsp_utils import notification_handler
from lsp_utils.pip_client_handler import PipClientHandler
from sublime_lib import ResourcePath

from LSP.plugin import LspPlugin, OnPreStartContext, notification_handler
from lsp_utils import UvVenvManager
from typing_extensions import override

from .ipc import send_notification

logger = logging.getLogger(__name__)


class Pyvoice(PipClientHandler):
package_name = __package__
requirements_txt_path = "requirements.txt"
server_filename = "pyvoice"

# --- PipClientHandler handlers ------------------------------------------------------------------------------------

@classmethod
def get_python_binary(cls) -> str:
settings = sublime.load_settings("{}.sublime-settings".format(cls.package_name))
python_binary = settings.get("python_binary")
if python_binary and isinstance(python_binary, str):
return python_binary
if sublime.platform() == "windows":
# with update to latest pygls got around the python3.11 and above crashing
allowed_python_binaries = [
os.path.expanduser(
r"~\AppData\Local\Programs\Python\Python312\python.exe"
),
os.path.expanduser(
r"~\AppData\Local\Programs\Python\Python311\python.exe"
),
os.path.expanduser(
r"~\AppData\Local\Programs\Python\Python310\python.exe"
),
os.path.expanduser(
r"~\AppData\Local\Programs\Python\Python39\python.exe"
),
os.path.expanduser(
r"~\AppData\Local\Programs\Python\Python38\python.exe"
),
]
for python_binary in allowed_python_binaries:
if os.path.isfile(python_binary):
return python_binary
else:
return "python3"
# return super().get_python_binary()
class Pyvoice(LspPlugin):

@classmethod
def get_additional_variables(cls) -> Dict[str, str]:
variables = super().get_additional_variables()
variables.update(
@override
def on_pre_start_async(cls, context: OnPreStartContext) -> None:
package_name = cls.plugin_storage_path.name
UvVenvManager.on_pre_start_async(
context, cls.plugin_storage_path, ResourcePath("Packages", package_name, 'server'), 'pyvoice')
context.variables.update(
{
"sublime_py_files_dir": os.path.dirname(sublime.__file__),
}
)
return variables

@notification_handler("voice/sendRpc")
def m_voice_sendRpc(self, params):
def on_voice_send_rpc(self, params) -> None:
method = params["command"]
cmd_params = params["params"]
if not isinstance(method, str):
Expand All @@ -86,8 +48,8 @@ def m_voice_sendRpc(self, params):


def plugin_loaded() -> None:
register_plugin(Pyvoice)
Pyvoice.register()


def plugin_unloaded() -> None:
unregister_plugin(Pyvoice)
Pyvoice.unregister()
19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[tool.pyright]
pythonVersion = "3.8"
typeCheckingMode = "standard"

[tool.ruff]
line-length = 120
target-version = "py38"

[tool.ruff.lint]
# Enable preview rules.
preview = true
select = ["F401", "I"]

[tool.ruff.lint.isort]
case-sensitive = true
combine-as-imports = true
extra-standard-library = ["sublime", "sublime_lib", "sublime_types"]
order-by-type = false
required-imports = ["from __future__ import annotations"]
4 changes: 3 additions & 1 deletion quick_install_grammars.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import annotations

import logging
import os

import sublime

import sublime_plugin

logger = logging.getLogger(__name__)
Expand Down
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

7 changes: 7 additions & 0 deletions server/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[project]
name = "lsp-pyvoice"
version = "1.0"
requires-python = ">=3.8.0,<3.13"
dependencies = [
"pyvoice-language-server==0.1.4",
]
Loading