Skip to content
This repository was archived by the owner on Oct 20, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8,264 changes: 8,264 additions & 0 deletions bin/lib.d.ts

Large diffs are not rendered by default.

34,383 changes: 34,383 additions & 0 deletions bin/main.js

Large diffs are not rendered by default.

23,710 changes: 23,710 additions & 0 deletions bin/typescript.js

Large diffs are not rendered by default.

32,848 changes: 32,848 additions & 0 deletions bin/typescriptServices.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/ts/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///<reference path='compilerservice.ts'/>
///<reference path='../lib/typescript/samples/node/node.d.ts'/>
///<reference path='../../lib/typescript/samples/node/node.d.ts'/>

var readline = require('readline');

Expand Down
File renamed without changes.
11 changes: 6 additions & 5 deletions core/install.py → ts_helpers/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
if os.name == 'nt':
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW

if ts_settings.has("node_path"):
node_path = ts_settings.get("node_path")
def get_node_path():
Expand All @@ -25,7 +24,7 @@ def check_for_node():
node_path = get_node_path()
try:
subprocess.call([node_path, "--help"], startupinfo = startupinfo)
except Exception, e:
except Exception as e:
sublime.error_message("The node executable hasn't been found, you might want to set it in your typescript settings by adding the \"node_path\" key")
raise e

Expand All @@ -52,7 +51,8 @@ def check_plugin_path():
sublime.save_settings("typescript.sublime-settings")

def needs_to_compile_plugin():
return not path.exists(path.join(ts_settings.get("plugin_path"), "bin/main.js"))
mainPath = path.join(ts_settings.get("plugin_path"), "bin/main.js")
return not path.exists(mainPath)

def compile_plugin(plugin_path):
def plugin_file(f):
Expand All @@ -63,10 +63,10 @@ def plugin_file(f):

if len(os.listdir(typescript_dir)) == 0:
# We need to get typescript and unzip it
import urllib
import urllib.request, urllib.parse, urllib.error
import zipfile
zf_path = plugin_file("lib/typescript/ts.zip")
urllib.urlretrieve(TYPESCRIPT_SOURCE_LINK, zf_path)
urllib.request.urlretrieve(TYPESCRIPT_SOURCE_LINK, zf_path)
zipf = zipfile.ZipFile(zf_path)
zipf.extractall(path=plugin_file("lib/typescript/"))
zipf.close()
Expand All @@ -77,6 +77,7 @@ def plugin_file(f):
if not path.exists(bindir):
os.makedirs(bindir)

print("compiling main.js")
subprocess.call([get_node_path(),
plugin_file("lib/typescript/bin/tsc.js"),
plugin_file("src/ts/main.ts"),
Expand Down
2 changes: 1 addition & 1 deletion core/project.py → ts_helpers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def find_project_file(file_path):
while b != "":
files = os.listdir(a)
if ".sublimets" in files:
print "FOUND project file", path.join(a, ".sublimets"), "for ts file ", file_path
print("FOUND project file", path.join(a, ".sublimets"), "for ts file ", file_path)
return path.join(a, ".sublimets")
a, b = path.split(a)

Expand Down
Empty file added ts_helpers/stderr.log
Empty file.
66 changes: 45 additions & 21 deletions typescript.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,20 @@
from time import sleep, time
import re
import difflib
from core import project, install
from .ts_helpers import project, install
from itertools import cycle, chain
from collections import defaultdict
import sys

# when using st3 import reload so we can reload
# the submodule ts_helpers whenever it changes during development
if sublime.version() == '' or int(sublime.version()) > 3000:
st_version = 3
from imp import reload

reload(sys.modules['sublime-typescript.ts_helpers.install'])
reload(sys.modules['sublime-typescript.ts_helpers.project'])


class AtomicValue:
def __init__(self):
Expand All @@ -34,14 +45,19 @@ def dec(self):
ts_settings = sublime.load_settings("typescript.sublime-settings")

install.check_for_node()

do_compile = install.check_plugin_path()
plugin_path = ts_settings.get("plugin_path")
def install_helper():
loading_files.inc()
install.compile_plugin(plugin_path)
loading_files.dec()
thread_install = None



if install.needs_to_compile_plugin():
print("we need to install the plugin")
thread_install = Thread(target=install_helper)
thread_install.start()

Expand Down Expand Up @@ -94,16 +110,16 @@ def format_diffs(old_content, new_content):
if oc[0] in ['insert', 'delete', 'replace']]

prefixes = {
"method": u"◉",
"property": u"●",
"class":u"◆",
"interface":u"◇",
"keyword":u"∆",
"variable": u"∨",
"method": "◉",
"property": "●",
"class":"◆",
"interface":"◇",
"keyword":"∆",
"variable": "∨",
}

js_id_re = re.compile(
ur'^[_$a-zA-Z\u00FF-\uFFFF][_$a-zA-Z0-9\u00FF-\uFFFF]*'
r'^[_$a-zA-Z\u00FF-\uFFFF][_$a-zA-Z0-9\u00FF-\uFFFF]*'
)

def is_member_completion(line):
Expand All @@ -115,7 +131,7 @@ def partial_completion():
return line.endswith(".") or partial_completion()

def format_completion_entry(c_entry):
prefix = prefixes.get(c_entry["kind"], u"-")
prefix = prefixes.get(c_entry["kind"], "-")
prefix += " "
middle = c_entry["name"]
suffix = "\t" + c_entry["type"]
Expand All @@ -125,7 +141,7 @@ def partition_by(lst, disc):
partitions = defaultdict(list)
for el in lst:
partitions[disc(el)].append(el)
return partitions.values()
return list(partitions.values())

def sort_completions(entries):
return [(format_completion_entry(item), item["name"])
Expand Down Expand Up @@ -163,7 +179,7 @@ def get_node_path():

class PluginInstance(object):
def __init__(self):
print "PLUGIN_FILE ", plugin_file("bin/main.js")
print("PLUGIN_FILE ", plugin_file("bin/main.js"))
self.open_files = set()
self.views_text = {}
self.errors_intervals = {}
Expand All @@ -173,23 +189,25 @@ def init_async():
if thread_install:
thread_install.join()
loading_files.inc()
# kwargs = {"stderr":open(plugin_file('stderr.log'),'a+')}
kwargs = {}
errorlog = None
if os.name == 'nt':
errorlog = open(os.devnull, 'w')
errorlog = open(os.devnull, 'a+')
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
kwargs = {"stderr":errorlog, "startupinfo":startupinfo}
self.p = Popen([get_node_path(), plugin_file("bin/main.js")], stdin=PIPE, stdout=PIPE, **kwargs)
self.p = Popen([get_node_path(), plugin_file("bin/main.js")], stdin=PIPE, stdout=PIPE,cwd=get_plugin_path(), **kwargs)

if errorlog:
errorlog.close()

self.serv_add_file(plugin_file("bin/lib.d.ts"))
loading_files.dec()
print "OUT OF INIT ASYNC"
print("OUT OF INIT ASYNC")
self.init_sem.release()


self.init_sem.acquire()
Thread(target=init_async).start()

Expand All @@ -199,10 +217,16 @@ def close_process(self):
def msg(self, *args):
res = None
message = json.dumps(args) + "\n"
t = time()
self.p.stdin.write(message)
self.p.stdin.write(bytes(message, 'utf-8'))
self.p.stdin.flush()
self.p.stdout.flush()
msg_content = self.p.stdout.readline()
res = json.loads(msg_content)

if len(msg_content) == 0:
return json.loads("{}")

# print(msg_content.decode('utf-8'))
res = json.loads(msg_content.decode('utf-8'))
return res

def serv_add_file(self, file_name):
Expand Down Expand Up @@ -263,7 +287,7 @@ def update_server_code(self, filename, new_content):
self.serv_edit_file(filename, *diff)

if bydiff_content != new_content:
print "ERROR WITH DIFF ALGORITHM"
print("ERROR WITH DIFF ALGORITHM")
raise Exception("ERROR WITH DIFF ALGORITHM")
else:
self.views_text[filename] = new_content
Expand All @@ -287,7 +311,7 @@ def handle_errors(self, view, ts_errors):
)

def get_error_for_pos(self, pos):
for (l, h), error in self.errors_intervals.iteritems():
for (l, h), error in self.errors_intervals.items():
if pos >= l and pos <= h:
return error
return None
Expand Down Expand Up @@ -420,7 +444,7 @@ def get_worker_thread(self, view):
return self.workers[bid]

def on_load(self, view):
print "IN ON LOAD FOR VIEW : ", view.file_name()
print("IN ON LOAD FOR VIEW : ", view.file_name())
if is_ts(view):
init_view(view)

Expand All @@ -445,7 +469,7 @@ def on_query_completions(self, view, prefix, locations):
line = view.substr(sublime.Region(view.line(pos-1).a, pos))
bword_pos = sublime.Region(view.word(pos).a, pos)
word = view.substr(bword_pos)
print "WORD : ", word
print("WORD : ", word)
completions_json = get_plugin(view).serv_get_completions(
view.file_name(), bword_pos.a, is_member_completion(line)
)
Expand Down
5 changes: 3 additions & 2 deletions typescript.sublime-settings
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extensions": ["ts", "str"],
"auto_complete": false
"extensions": ["ts", "str"],
"auto_complete": true,
"node_path" : "/Users/martijnlaarman/.nvm/v0.10.4/bin/node"
}