Skip to content

Commit e45e059

Browse files
Merge pull request #770 from microsoft/undoUpwardsWalking
Revert a0d393a to avoid potentially loading from C:/
2 parents 70f8ede + b97a02d commit e45e059

File tree

2 files changed

+13
-64
lines changed

2 files changed

+13
-64
lines changed

README.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,6 @@ This plugin can be configured to load an alternate version of TypeScript. This i
2222
"typescript_tsdk": "<path to your folder>/node_modules/typescript/lib"
2323
```
2424

25-
The path may be relative. In such case the plugin will look in the following locations in this order:
26-
27-
```
28-
/foo/project_folder_1/<typescript_tsdk>
29-
/foo/<typescript_tsdk>
30-
/<typescript_tsdk>
31-
/bar/project_folder_2/<typescript_tsdk>
32-
/bar/<typescript_tsdk>
33-
/baz/open_file_1_folder/<typescript_tsdk>
34-
/baz/<typescript_tsdk>
35-
/baz/open_file_2_folder/<typescript_tsdk>
36-
```
37-
38-
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`.
39-
40-
**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.
41-
4225
Installation
4326
------------
4427
If using [Package Control](https://packagecontrol.io/) for Sublime Text, simply install the `TypeScript` package.

typescript/libs/editor_client.py

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -52,53 +52,19 @@ def initialize(self):
5252
initialized during loading time
5353
"""
5454

55-
# Default to and fall back to the bundled SDK
56-
tsdk_location_default = os.path.join(PLUGIN_DIR, "tsserver")
57-
tsdk_location = tsdk_location_default
58-
59-
is_tsdk_location_good = lambda x: (
60-
os.path.isfile(os.path.join(x, "tsserver.js"))
61-
and os.path.isfile(os.path.join(x, "tsc.js"))
62-
)
63-
64-
active_window = sublime.active_window()
65-
settings = active_window.active_view().settings()
66-
typescript_tsdk_setting = settings.get("typescript_tsdk")
67-
if typescript_tsdk_setting:
68-
if os.path.isabs(typescript_tsdk_setting):
69-
if is_tsdk_location_good(typescript_tsdk_setting):
70-
tsdk_location = typescript_tsdk_setting
71-
else:
72-
def look_for_tsdk(x):
73-
x_appended = os.path.join(x, typescript_tsdk_setting)
74-
if is_tsdk_location_good(x_appended):
75-
return x_appended
76-
parent = os.path.dirname(x)
77-
if parent == x:
78-
return None # We have reached the root
79-
return look_for_tsdk(parent)
80-
81-
# list(OrderedDict.fromkeys(x)) = deduped x, order preserved
82-
folders = active_window.folders() + list(
83-
collections.OrderedDict.fromkeys(
84-
[
85-
os.path.dirname(x.file_name())
86-
for x in active_window.views()
87-
if x.file_name() # It's None for unsaved files
88-
]
89-
)
90-
)
91-
for folder in folders:
92-
x = look_for_tsdk(folder)
93-
if x != None:
94-
tsdk_location = x
95-
break
96-
97-
proc_file = os.path.join(tsdk_location, "tsserver.js")
98-
global_vars._tsc_path = os.path.join(tsdk_location, "tsc.js")
99-
100-
log.warn("Path of tsserver.js: " + proc_file)
101-
log.warn("Path of tsc.js: " + get_tsc_path())
55+
# retrieve the path to tsserver.js
56+
# first see if user set the path to the file
57+
settings = sublime.load_settings("Preferences.sublime-settings")
58+
tsdk_location = settings.get("typescript_tsdk")
59+
if tsdk_location:
60+
proc_file = os.path.join(tsdk_location, "tsserver.js")
61+
global_vars._tsc_path = os.path.join(tsdk_location, "tsc.js")
62+
else:
63+
# otherwise, get tsserver.js from package directory
64+
proc_file = os.path.join(PLUGIN_DIR, "tsserver", "tsserver.js")
65+
global_vars._tsc_path = os.path.join(PLUGIN_DIR, "tsserver", "tsc.js")
66+
log.debug("Path of tsserver.js: " + proc_file)
67+
log.debug("Path of tsc.js: " + get_tsc_path())
10268

10369
self.node_client = ServerClient(proc_file)
10470
self.worker_client = WorkerClient(proc_file)

0 commit comments

Comments
 (0)