From 4538df88bbbc05b8d27fde3628123673be0816a9 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 31 Mar 2017 23:17:45 +0300 Subject: [PATCH 1/3] allow script to do further jumping around without adding to jump list we are using requirejs and many times tern jumps into the `return` of the function ( which is correct since this is where the variable was defined ) but we want to further jump and get to the initial definition of what we were looking for. I've added a piece of code that does just that, based on our codestyle a simple regex may inform us that this is not the place we wanted to see... but we are getting additional stop on our way back with ctrl+o. we would like to ask tern for additional jumps without addind to the jump list. --- script/tern.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/script/tern.py b/script/tern.py index 49e29f4..0caa6e4 100644 --- a/script/tern.py +++ b/script/tern.py @@ -334,7 +334,7 @@ def tern_lookupArgumentHints(fname, apos): True, True) if data: tern_echoWrap(data.get("type", ""),name=fname) -def tern_lookupDefinition(cmd): +def tern_lookupDefinition(cmd, add_jump_position=True): data = tern_runCommand("definition", fragments=False) if data is None: return @@ -344,7 +344,8 @@ def tern_lookupDefinition(cmd): filename = data["file"] if cmd == "edit" and filename == tern_relativeFile(): - vim.command("normal! m`") + if add_jump_position: + vim.command("normal! m`") vim.command("call cursor(" + str(lnum) + "," + str(col) + ")") else: vim.command(cmd + " +call\ cursor(" + str(lnum) + "," + str(col) + ") " + From 98c979d2a01d24dd828ccc6205aea8743c7f531f Mon Sep 17 00:00:00 2001 From: David Date: Sat, 17 Jun 2017 15:27:46 +0300 Subject: [PATCH 2/3] support jsx --- package.json | 3 ++- script/tern.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 81d81fe..73eeeab 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "url": "git://github.com/ternjs/tern_for_vim.git" }, "dependencies": { - "tern": ">=0.5" + "tern": ">=0.5", + "tern-jsx": "^1.0.2" } } diff --git a/script/tern.py b/script/tern.py index 0caa6e4..a35724d 100644 --- a/script/tern.py +++ b/script/tern.py @@ -375,6 +375,23 @@ def tern_refs(): "text": name + " (file not loaded)" if len(text)==0 else text[0]}) vim.command("call setloclist(0," + json.dumps(refs) + ") | lopen") + +def tern_refs2(): + data = tern_runCommand("refs", fragments=False) + refs = [] + if data is not None: + for ref in data["refs"]: + lnum = ref["start"]["line"] + 1 + col = ref["start"]["ch"] + 1 + filename = tern_projectFilePath(ref["file"]) + name = data["name"] + text = vim.eval("getbufline('" + filename + "'," + str(lnum) + ")") + refs.append({"lnum": lnum, + "col": col, + "filename": filename, + "text": name + " (file not loaded)" if len(text)==0 else text[0]}) + vim.command("call DefaultTernHandler(" + json.dumps(refs) + ")") + # Copied here because Python 2.6 and lower don't have it built in, and # python 3.0 and higher don't support old-style cmp= args to the sort # method. There's probably a better way to do this... From b05129a3bdc0046bcb635df1e9c6bb2778f5e404 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 10 Mar 2018 12:37:09 +0200 Subject: [PATCH 3/3] . --- package.json | 1 + script/tern.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/package.json b/package.json index 73eeeab..19eca6f 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "url": "git://github.com/ternjs/tern_for_vim.git" }, "dependencies": { + "acorn": "^5.3.0", "tern": ">=0.5", "tern-jsx": "^1.0.2" } diff --git a/script/tern.py b/script/tern.py index a32307b..69d5454 100644 --- a/script/tern.py +++ b/script/tern.py @@ -31,6 +31,10 @@ def tern_makeRequest(port, doc, silent=False): localhost = 'localhost' if platform.system().lower()=='windows': localhost = '127.0.0.1' + # file=open("/tmp/ternrequest", "w") + # file.write(json.dumps(doc)) + # file.close() + req = opener.open("http://" + localhost + ":" + str(port) + "/", payload, float(vim.eval("g:tern_request_timeout"))) result = req.read()