Skip to content

Commit 4641013

Browse files
committed
Merge remote-tracking branch 'origin/master' into tooltips
Conflicts: Default.sublime-keymap
2 parents b38cf18 + 622f071 commit 4641013

File tree

12 files changed

+101
-87
lines changed

12 files changed

+101
-87
lines changed

Default.sublime-keymap

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -136,57 +136,6 @@
136136

137137
]
138138
},
139-
{
140-
"keys": [ "}" ],
141-
"command": "typescript_format_on_key",
142-
"args": { "key": "}" },
143-
"context": [
144-
{ "key": "selector", "operator": "equal", "operand": "source.ts" },
145-
{ "key": "setting.typescript_auto_format", "operator": "equal", "operand": true },
146-
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
147-
{ "key": "num_selections", "operator": "equal", "operand": 1},
148-
{ "key": "selection_empty", "operator": "equal", "operand": true },
149-
150-
{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "\\{$" },
151-
{ "key": "following_text", "operator": "not_regex_contains", "operand": "^\\}" }
152-
]
153-
},
154-
// In case when auto match is disabled, format the block regardless
155-
{
156-
"keys": [ "}" ],
157-
"command": "typescript_format_on_key",
158-
"args": { "key": "}" },
159-
"context": [
160-
{ "key": "num_selections", "operator": "equal", "operand": 1},
161-
{ "key": "setting.typescript_auto_format", "operator": "equal", "operand": true },
162-
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
163-
{ "key": "selector", "operator": "equal", "operand": "source.ts" },
164-
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": false }
165-
]
166-
},
167-
{
168-
"keys": [ ";" ],
169-
"command": "typescript_format_on_key",
170-
"args": { "key": ";" },
171-
"context": [
172-
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
173-
{ "key": "setting.typescript_auto_format", "operator": "equal", "operand": true },
174-
{ "key": "selector", "operator": "equal", "operand": "source.ts" }
175-
]
176-
},
177-
{
178-
"keys": [ "enter" ],
179-
"command": "typescript_format_on_key",
180-
"args": { "key": "\n" },
181-
"context": [
182-
{ "key": "setting.typescript_auto_indent", "operator": "equal", "operand": true },
183-
{ "key": "auto_complete_visible", "operator": "equal", "operand": false },
184-
{ "key": "selector", "operator": "not_equal", "operand": "meta.scope.between-tag-pair" },
185-
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
186-
{ "key": "num_selections", "operator": "equal", "operand": 1},
187-
{ "key": "selector", "operator": "equal", "operand": "source.ts" }
188-
]
189-
},
190139
{
191140
"keys": [ "enter" ],
192141
"command": "typescript_go_to_ref",

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
TypeScript Plugin for Sublime Text
22
==================================
33

4+
[![Join the chat at https://gitter.im/Microsoft/TypeScript-Sublime-Plugin](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Microsoft/TypeScript-Sublime-Plugin?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5+
46
The plugin uses an IO wrapper around the TypeScript language services to provide
57
an enhanced Sublime Text experience when working with TypeScript code.
68

typescript/commands/format.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ def run(self, text, key="", insert_key=True):
1414
if 0 == len(key):
1515
return
1616
check_update_view(self.view)
17-
loc = self.view.sel()[0].begin()
18-
19-
if insert_key:
20-
active_view().run_command('hide_auto_complete')
21-
insert_text(self.view, text, loc, key)
2217

2318
format_response = cli.service.format_on_key(self.view.file_name(), get_location_from_view(self.view), key)
2419
if format_response["success"]:

typescript/libs/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from .popup_manager import get_popup_manager
66
from .logger import log
77
from . import logger
8-
98
__all__ = [
109
'cli',
1110
'EditorClient',

typescript/libs/editor_client.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def __init__(self):
3434
self.tab_size = 4
3535
self.indent_size = 4
3636
self.translate_tab_to_spaces = False
37+
self.ts_auto_format_enabled = True
38+
self.ts_auto_indent_enabled = True
39+
self.auto_match_enabled = True
3740

3841
def initialize(self):
3942
"""
@@ -55,7 +58,14 @@ def initialize(self):
5558
self.service = ServiceProxy(self.node_client)
5659

5760
# load formatting settings and set callbacks for setting changes
58-
for setting_name in ['tab_size', 'indent_size', 'translate_tabs_to_spaces']:
61+
for setting_name in [
62+
'tab_size',
63+
'indent_size',
64+
'translate_tabs_to_spaces',
65+
'typescript_auto_format',
66+
'typescript_auto_indent',
67+
'auto_match_enabled'
68+
]:
5969
settings.add_on_change(setting_name, self.load_format_settings)
6070
self.load_format_settings()
6171

@@ -66,6 +76,9 @@ def load_format_settings(self):
6676
self.tab_size = settings.get('tab_size', 4)
6777
self.indent_size = settings.get('indent_size', 4)
6878
self.translate_tab_to_spaces = settings.get('translate_tabs_to_spaces', False)
79+
self.ts_auto_format_enabled = settings.get("typescript_auto_format")
80+
self.ts_auto_indent_enabled = settings.get("typescript_auto_indent")
81+
self.auto_match_enabled = settings.get("auto_match_enabled")
6982
self.set_features()
7083

7184
def set_features(self):

typescript/libs/global_vars.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,34 @@
44
import sublime
55
from os.path import dirname
66

7+
# determine if the host is sublime text 2
8+
IS_ST2 = int(sublime.version()) < 3000
79

810
# Get the directory path to this file;
9-
# Note: MODULE_DIR, PLUGIN_DIR and PLUGIN_NAME only works correctly when:
10-
# 1. Using sublime 3
11-
# 2. Using sublime 2, and the plugin folder is not a symbol link
12-
# On sublime 2 with the plugin folder being a symbol link, the PLUGIN_FOLDER will points
13-
# to the linked real path instead, and the PLUGIN_NAME will be wrong too.
14-
MODULE_DIR = dirname(dirname(os.path.abspath(__file__)))
15-
PLUGIN_DIR = dirname(MODULE_DIR)
11+
# Note: there are several ways this plugin can be installed
12+
# 1. from the package control -> the absolute path of __file__ is real and contains plugin name
13+
# 2. git clone directly to the sublime packages folder -> the absolute path of __file__ is real and contains plugin name
14+
# 3. git clone to somewhere else, and link to the sublime packages folder -> the absolute path is real in Sublime 3,
15+
# but is somewhere else in Sublime 2;and therefore in Sublime 2 there is no direct way to obtain the plugin name
16+
if not IS_ST2:
17+
PLUGIN_DIR = dirname(dirname(dirname(os.path.abspath(__file__))))
18+
else:
19+
_sublime_packages_dir = sublime.packages_path()
20+
_cur_file_abspath = os.path.abspath(__file__)
21+
if _sublime_packages_dir not in _cur_file_abspath:
22+
# The plugin is installed as a link
23+
for p in os.listdir(_sublime_packages_dir):
24+
link_path = _sublime_packages_dir + os.sep + p
25+
if os.path.realpath(link_path) in _cur_file_abspath:
26+
PLUGIN_DIR = link_path
27+
break
28+
else:
29+
PLUGIN_DIR = dirname(dirname(dirname(os.path.abspath(__file__))))
1630
PLUGIN_NAME = os.path.basename(PLUGIN_DIR)
1731

1832
# only Sublime Text 3 build after 3072 support tooltip
1933
TOOLTIP_SUPPORT = int(sublime.version()) >= 3072
2034

21-
# determine if the host is sublime text 2
22-
IS_ST2 = int(sublime.version()) < 3000
23-
2435
# detect if quick info is available for symbol
2536
SUBLIME_WORD_MASK = 515
2637

typescript/libs/node_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ def getEvent(self): pass
2121

2222
def postCmd(self, cmd): pass
2323

24-
def sendCmd(self, cb, cmd): pass
24+
def sendCmd(self, cmd, cb): pass
2525

2626
def sendCmdSync(self, cmd): pass
2727

28-
def sendCmdAsync(self, cmd): pass
28+
def sendCmdAsync(self, cmd, cb): pass
2929

3030

3131
class NodeCommClient(CommClient):
@@ -111,7 +111,7 @@ def makeTimeoutMsg(self, cmd, seq):
111111
}
112112
return timeoutMsg
113113

114-
def sendCmd(self, cb, cmd, seq):
114+
def sendCmd(self, cmd, cb, seq):
115115
"""
116116
send single-line command string; no sequence number; wait for response
117117
this assumes stdin/stdout; for TCP, need to add correlation with sequence numbers
@@ -133,7 +133,7 @@ def sendCmd(self, cb, cmd, seq):
133133
if (cb):
134134
cb(self.makeTimeoutMsg(cmd, seq))
135135

136-
def sendCmdAsync(self, cmd, seq, cb):
136+
def sendCmdAsync(self, cmd, cb, seq):
137137
"""
138138
Sends the command and registers a callback
139139
"""

typescript/libs/popup_manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import re
2+
13
from string import Template
24

35
from .logger import log
@@ -270,6 +272,8 @@ def get_popup_manager():
270272

271273
log.info('Popup resource path: {0}'.format(rel_path))
272274
popup_text = sublime.load_resource(rel_path)
275+
re_remove = re.compile("[\n\t\r]")
276+
popup_text = re_remove.sub("", popup_text)
273277
log.info('Loaded tooltip template from {0}'.format(rel_path))
274278

275279
PopupManager.html_template = Template(popup_text)

typescript/libs/service_proxy.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import collections
22

33
from . import json_helpers
4+
from .global_vars import IS_ST2
45
from .node_client import CommClient
56
from .text_helpers import Location
67

@@ -45,32 +46,32 @@ def completions(self, path, location=Location(1, 1), prefix="", on_completed=Non
4546
req_dict = self.create_req_dict("completions", args)
4647
json_str = json_helpers.encode(req_dict)
4748
self.__comm.sendCmd(
48-
lambda json_dict: None if on_completed is None else on_completed(json_dict),
4949
json_str,
50+
lambda response_dict: None if on_completed is None else on_completed(response_dict),
5051
req_dict["seq"]
5152
)
5253

5354
def async_completions(self, path, location=Location(1, 1), prefix="", on_completed=None):
5455
args = {"file": path, "line": location.line, "offset": location.offset, "prefix": prefix}
5556
req_dict = self.create_req_dict("completions", args)
5657
json_str = json_helpers.encode(req_dict)
57-
self.__comm.sendCmdAsync(json_str, req_dict["seq"], on_completed)
58+
self.__comm.sendCmdAsync(json_str, on_completed, req_dict["seq"])
5859

5960
def signature_help(self, path, location=Location(1, 1), prefix="", on_completed=None):
6061
args = {"file": path, "line": location.line, "offset": location.offset, "prefix": prefix}
6162
req_dict = self.create_req_dict("signatureHelp", args)
6263
json_str = json_helpers.encode(req_dict)
6364
self.__comm.sendCmd(
64-
lambda response_dict: None if on_completed is None else on_completed(response_dict),
6565
json_str,
66+
lambda response_dict: None if on_completed is None else on_completed(response_dict),
6667
req_dict["seq"]
6768
)
6869

6970
def async_signature_help(self, path, location=Location(1, 1), prefix="", on_completed=None):
7071
args = {"file": path, "line": location.line, "offset": location.offset, "prefix": prefix}
7172
req_dict = self.create_req_dict("signatureHelp", args)
7273
json_str = json_helpers.encode(req_dict)
73-
self.__comm.sendCmdAsync(json_str, req_dict["seq"], on_completed)
74+
self.__comm.sendCmdAsync(json_str, on_completed, req_dict["seq"])
7475

7576
def definition(self, path, location=Location(1, 1)):
7677
args = {"file": path, "line": location.line, "offset": location.offset}
@@ -129,7 +130,7 @@ def reload_async(self, path, alternate_path, on_completed):
129130
args = {"file": path, "tmpfile": alternate_path}
130131
req_dict = self.create_req_dict("reload", args)
131132
json_str = json_helpers.encode(req_dict)
132-
self.__comm.sendCmdAsync(json_str, req_dict["seq"], on_completed)
133+
self.__comm.sendCmdAsync(json_str, on_completed, req_dict["seq"])
133134

134135
def rename(self, path, location=Location(1, 1)):
135136
args = {"file": path, "line": location.line, "offset": location.offset}
@@ -151,15 +152,23 @@ def type(self, path, location=Location(1, 1)):
151152
response_dict = self.__comm.sendCmdSync(json_str, req_dict["seq"])
152153
return response_dict
153154

154-
def quick_info(self, path, location=Location(1, 1), onCompleted=None):
155+
def quick_info(self, path, location=Location(1, 1), on_completed=None):
155156
args = {"file": path, "line": location.line, "offset": location.offset}
156157
req_dict = self.create_req_dict("quickinfo", args)
157158
json_str = json_helpers.encode(req_dict)
158-
self.__comm.sendCmd(
159-
lambda json_dict: None if onCompleted is None else onCompleted(json_dict),
160-
json_str,
161-
req_dict["seq"]
162-
)
159+
callback = on_completed or (lambda: None)
160+
if not IS_ST2:
161+
self.__comm.sendCmdAsync(
162+
json_str,
163+
callback,
164+
req_dict["seq"]
165+
)
166+
else:
167+
self.__comm.sendCmd(
168+
json_str,
169+
callback,
170+
req_dict["seq"]
171+
)
163172

164173
def get_event(self):
165174
event_json_str = self.__comm.getEvent()

typescript/libs/view_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def is_special_view(view):
106106
in that they cannot be the active_view of their windows, therefore their ids
107107
shouldn't be equal to the current view id.
108108
"""
109-
return view.window() and view.id() != view.window().active_view().id()
109+
return view is not None and view.window() and view.id() != view.window().active_view().id()
110110

111111

112112
def get_location_from_view(view):

0 commit comments

Comments
 (0)