From b97a02df791822b3295a32d1bf7af92d8fc2e790 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 23 Feb 2021 12:52:38 -0800 Subject: [PATCH] Revert a0d393a to avoid potentially loading from C:/ --- README.md | 17 --------- typescript/libs/editor_client.py | 60 +++++++------------------------- 2 files changed, 13 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index b56d3f78..7bd74df2 100644 --- a/README.md +++ b/README.md @@ -22,23 +22,6 @@ This plugin can be configured to load an alternate version of TypeScript. This i "typescript_tsdk": "/node_modules/typescript/lib" ``` -The path may be relative. In such case the plugin will look in the following locations in this order: - -``` -/foo/project_folder_1/ -/foo/ -/ -/bar/project_folder_2/ -/bar/ -/baz/open_file_1_folder/ -/baz/ -/baz/open_file_2_folder/ -``` - -In case of Yarn 2, just [install its editor SDK](https://yarnpkg.com/advanced/editor-sdks) using `yarn dlx @yarnpkg/pnpify --sdk base` and set `typescript_tsdk` to `.yarn/sdks/typescript/lib`. - -**Note.** The plugin isn't reloaded when switching projects or updating settings at the moment, so you must restart Sublime Text when doing so, unfortunately. When in doubt, check the console for "Path of tsserver.js" and "Path of tsc.js", and see if they point where you expect them to point. - Installation ------------ If using [Package Control](https://packagecontrol.io/) for Sublime Text, simply install the `TypeScript` package. diff --git a/typescript/libs/editor_client.py b/typescript/libs/editor_client.py index f8a3b1e7..97393f1c 100644 --- a/typescript/libs/editor_client.py +++ b/typescript/libs/editor_client.py @@ -52,53 +52,19 @@ def initialize(self): initialized during loading time """ - # Default to and fall back to the bundled SDK - tsdk_location_default = os.path.join(PLUGIN_DIR, "tsserver") - tsdk_location = tsdk_location_default - - is_tsdk_location_good = lambda x: ( - os.path.isfile(os.path.join(x, "tsserver.js")) - and os.path.isfile(os.path.join(x, "tsc.js")) - ) - - active_window = sublime.active_window() - settings = active_window.active_view().settings() - typescript_tsdk_setting = settings.get("typescript_tsdk") - if typescript_tsdk_setting: - if os.path.isabs(typescript_tsdk_setting): - if is_tsdk_location_good(typescript_tsdk_setting): - tsdk_location = typescript_tsdk_setting - else: - def look_for_tsdk(x): - x_appended = os.path.join(x, typescript_tsdk_setting) - if is_tsdk_location_good(x_appended): - return x_appended - parent = os.path.dirname(x) - if parent == x: - return None # We have reached the root - return look_for_tsdk(parent) - - # list(OrderedDict.fromkeys(x)) = deduped x, order preserved - folders = active_window.folders() + list( - collections.OrderedDict.fromkeys( - [ - os.path.dirname(x.file_name()) - for x in active_window.views() - if x.file_name() # It's None for unsaved files - ] - ) - ) - for folder in folders: - x = look_for_tsdk(folder) - if x != None: - tsdk_location = x - break - - proc_file = os.path.join(tsdk_location, "tsserver.js") - global_vars._tsc_path = os.path.join(tsdk_location, "tsc.js") - - log.warn("Path of tsserver.js: " + proc_file) - log.warn("Path of tsc.js: " + get_tsc_path()) + # retrieve the path to tsserver.js + # first see if user set the path to the file + settings = sublime.load_settings("Preferences.sublime-settings") + tsdk_location = settings.get("typescript_tsdk") + if tsdk_location: + proc_file = os.path.join(tsdk_location, "tsserver.js") + global_vars._tsc_path = os.path.join(tsdk_location, "tsc.js") + else: + # otherwise, get tsserver.js from package directory + proc_file = os.path.join(PLUGIN_DIR, "tsserver", "tsserver.js") + global_vars._tsc_path = os.path.join(PLUGIN_DIR, "tsserver", "tsc.js") + log.debug("Path of tsserver.js: " + proc_file) + log.debug("Path of tsc.js: " + get_tsc_path()) self.node_client = ServerClient(proc_file) self.worker_client = WorkerClient(proc_file)