Skip to content

Commit

Permalink
refactor: allow overwriting server files
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Cherng <[email protected]>
  • Loading branch information
jfcherng committed Jun 19, 2024
1 parent 2dfb9ed commit 23add57
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
File renamed without changes.
34 changes: 17 additions & 17 deletions plugin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import sublime
from LSP.plugin import ClientConfig, DottedDict, MarkdownLangMap, Response, WorkspaceFolder
from LSP.plugin.core.protocol import CompletionItem, Hover, SignatureHelp
from lsp_utils import NpmClientHandler, ServerNpmResource
from lsp_utils import NpmClientHandler
from sublime_lib import ResourcePath

from .constants import PACKAGE_NAME
Expand Down Expand Up @@ -92,20 +92,7 @@ def on_pre_start(
@classmethod
def install_or_update(cls) -> None:
super().install_or_update()

copies: list[tuple[str, str]] = [
(
f"Packages/{cls.package_name}/resources/",
os.path.join(cls.package_storage(), "resources"),
),
]
if server := cast(ServerNpmResource, cls.get_server()):
copies.append((
f"Packages/{cls.package_name}/overwrites/",
server.server_directory_path,
))
for src, dest in copies:
ResourcePath(src).copytree(dest, exist_ok=True)
cls.copy_overwrite_dirs()

@classmethod
def markdown_language_id_to_st_syntax_map(cls) -> MarkdownLangMap | None:
Expand Down Expand Up @@ -140,6 +127,19 @@ def on_server_response_async(self, method: str, response: Response) -> None:
# custom methods #
# -------------- #

@classmethod
def copy_overwrite_dirs(cls) -> None:
if not (server_dir := cls._server_directory_path()):
log_warning("Failed to get the server instance during copying overwrite dirs.")
return

dir_src = f"Packages/{cls.package_name}/overwrites/"
dir_dst = server_dir
try:
ResourcePath(dir_src).copytree(dir_dst, exist_ok=True)
except OSError:
raise RuntimeError(f'Failed to copy overwrite dirs from "{dir_src}" to "{dir_dst}".')

def update_status_bar_text(self) -> None:
if not (session := self.weaksession()):
return
Expand Down Expand Up @@ -221,8 +221,8 @@ def find_package_dependency_dirs(self, py_ver: tuple[int, int] = (3, 3)) -> list
dep_dirs.append(packages_path)

# sublime stubs - add as first
if py_ver == (3, 3):
dep_dirs.insert(0, os.path.join(self.package_storage(), "resources", "typings", "sublime_text"))
if py_ver == (3, 3) and (server_dir := self._server_directory_path()):
dep_dirs.insert(0, os.path.join(server_dir, "resources", "typings", "sublime_text_py33"))

return list(filter(os.path.isdir, dep_dirs))

Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ exclude = [
".venv",
".venv-*",
"branch-*",
"overwrites",
"resources",
"scripts/module_scraper",
"overwrites/node_modules/pyright/dist/typeshed-fallback",
"stubs",
"tests/files",
"typings",
Expand Down

0 comments on commit 23add57

Please sign in to comment.