33from ._util import download_file
44from ._util import extract_archive
55from ._util import logger
6+ from .constants import HOST_ARCH
67from .constants import SETTINGS_FILENAME
78from .helpers import rmtree_ex
89from .helpers import run_command_sync
910from .helpers import SemanticVersion
1011from .helpers import version_to_string
1112from .third_party .semantic_version import NpmSpec # pyright: ignore[reportPrivateLocalImportUsage]
1213from .third_party .semantic_version import Version # pyright: ignore[reportPrivateLocalImportUsage]
13- from contextlib import contextmanager
1414from LSP .plugin .core .logging import debug
1515from pathlib import Path
1616from sublime_lib import ActivityIndicator
1717from typing import Any
1818from typing import cast
1919from typing import final
20- from typing import Generator
2120from typing_extensions import override
2221import os
2322import shutil
@@ -131,6 +130,7 @@ def _resolve_node_runtime(
131130 log_lines .append (f' * { ex } ' )
132131 if not resolved_runtime :
133132 log_lines .append ('--- lsp_utils Node.js resolving end ---' )
133+ logger .debug ('\n ' .join (log_lines ))
134134 msg = 'Failed resolving Node.js Runtime. Please check in the console for more details.'
135135 raise Exception (msg )
136136 return resolved_runtime
@@ -280,7 +280,6 @@ def install_node(self) -> None:
280280 with ActivityIndicator (sublime .active_window (), '[LSP] Setting up local Node.js' ):
281281 install_node = NodeInstaller (self ._base_dir , self ._node_version )
282282 install_node .run ()
283- self ._resolve_paths ()
284283 self ._install_in_progress_marker_file .unlink ()
285284 self ._resolve_paths ()
286285
@@ -339,8 +338,8 @@ def run(self) -> None:
339338
340339 def _node_archive (self ) -> tuple [str , str ]:
341340 platform = sublime .platform ()
342- arch = sublime . arch ()
343- if platform == 'windows' and arch == 'x64' :
341+ arch = HOST_ARCH
342+ if platform == 'windows' :
344343 node_os = 'win'
345344 archive = 'zip'
346345 elif platform == 'linux' :
@@ -357,8 +356,10 @@ def _node_archive(self) -> tuple[str, str]:
357356 return filename , dist_url
358357
359358 def _install_node (self , archive_path : Path ) -> None :
360- install_directory = extract_archive (archive_path , self ._base_dir )
361- install_directory .rename (install_directory .parent / 'node' )
359+ temporary_target_path = self ._base_dir / 'node-temp'
360+ extracted_path = extract_archive (archive_path , temporary_target_path ) or temporary_target_path
361+ extracted_path .rename (self ._base_dir / 'node' )
362+ rmtree_ex (temporary_target_path , ignore_errors = True )
362363 archive_path .unlink ()
363364
364365
@@ -462,7 +463,7 @@ def run(self) -> None:
462463
463464 def _node_archive (self ) -> tuple [str , str ]:
464465 platform = sublime .platform ()
465- arch = sublime . arch ()
466+ arch = HOST_ARCH
466467 if platform == 'windows' :
467468 platform_code = 'win32'
468469 elif platform == 'linux' :
@@ -488,14 +489,3 @@ def _install(self, archive_path: Path) -> None:
488489 raise Exception (msg )
489490 finally :
490491 archive_path .unlink ()
491-
492-
493- @contextmanager
494- def chdir (new_dir : str ) -> Generator [None , None , None ]:
495- """Context Manager for changing the working directory."""
496- cur_dir = Path .cwd ()
497- os .chdir (new_dir )
498- try :
499- yield
500- finally :
501- os .chdir (cur_dir )
0 commit comments