Skip to content

Commit 1422f24

Browse files
committed
feat: support type completion over js files
1 parent eb57ceb commit 1422f24

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

Preferences.sublime-settings

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"typescript_auto_format": false,
33
"enable_typescript_language_service": true,
4+
"enable_language_service_for_javascript": true,
45
"enable_inline_error_tips": false
56
}

typescript/libs/editor_client.py

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def __init__(self):
3939
self.ts_auto_format_enabled = True
4040
self.ts_auto_indent_enabled = True
4141
self.auto_match_enabled = True
42+
self.enable_language_service_for_js = True
4243

4344
def initialize(self):
4445
"""
@@ -65,6 +66,9 @@ def initialize(self):
6566
self.worker_client = WorkerClient(proc_file)
6667
self.service = ServiceProxy(self.worker_client, self.node_client)
6768

69+
settings.add_on_change("enable_language_service_for_javascript", self.load_language_service_setting_for_js)
70+
self.load_language_service_setting_for_js()
71+
6872
# load formatting settings and set callbacks for setting changes
6973
for setting_name in [
7074
'tab_size',
@@ -79,6 +83,10 @@ def initialize(self):
7983

8084
self.initialized = True
8185

86+
def load_language_service_setting_for_js(self):
87+
settings = sublime.load_settings('Preferences.sublime-settings')
88+
self.enable_language_service_for_js = settings.get("enable_language_service_for_javascript", True)
89+
8290
def load_format_settings(self):
8391
settings = sublime.load_settings('Preferences.sublime-settings')
8492
self.tab_size = settings.get('tab_size', 4)

typescript/libs/view_helpers.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def get_info(view, open_if_not_cached=True):
4141
"""Find the file info on the server that matches the given view"""
4242
if not get_language_service_enabled():
4343
return
44-
44+
4545
if not cli.initialized:
4646
cli.initialize()
4747

@@ -106,15 +106,18 @@ def is_typescript(view):
106106
except:
107107
return False
108108

109-
return (view.match_selector(location, 'source.ts') or
110-
view.match_selector(location, 'source.tsx'))
109+
is_ts_file = view.match_selector(location, 'source.ts, source.tsx')
110+
is_js_file = cli.enable_language_service_for_js \
111+
and view.match_selector(location, 'source.js, source.jsx')
112+
113+
return is_ts_file or is_js_file
111114

112115

113116
def is_special_view(view):
114117
"""Determine if the current view is a special view.
115118
116119
Special views are mostly referring to panels. They are different from normal views
117-
in that they cannot be the active_view of their windows, therefore their ids
120+
in that they cannot be the active_view of their windows, therefore their ids
118121
shouldn't be equal to the current view id.
119122
"""
120123
return view is not None and view.window() and view.id() != view.window().active_view().id()
@@ -265,7 +268,7 @@ def reload_required(view):
265268
def check_update_view(view):
266269
"""Check if the buffer in the view needs to be reloaded
267270
268-
If we have changes to the view not accounted for by change messages,
271+
If we have changes to the view not accounted for by change messages,
269272
send the whole buffer through a temporary file
270273
"""
271274
if is_typescript(view):
@@ -276,7 +279,7 @@ def check_update_view(view):
276279

277280
def send_replace_changes_for_regions(view, regions, insert_string):
278281
"""
279-
Given a list of regions and a (possibly zero-length) string to insert,
282+
Given a list of regions and a (possibly zero-length) string to insert,
280283
send the appropriate change information to the server.
281284
"""
282285
if not is_typescript(view):

0 commit comments

Comments
 (0)