Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple TernDef calls from within script: jumplist #162

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"url": "git://github.com/ternjs/tern_for_vim.git"
},
"dependencies": {
"tern": ">=0.5"
"acorn": "^5.3.0",
"tern": ">=0.5",
"tern-jsx": "^1.0.2"
}
}
26 changes: 24 additions & 2 deletions script/tern.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -354,7 +358,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

Expand All @@ -364,7 +368,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) + ") " +
Expand Down Expand Up @@ -401,6 +406,23 @@ def tern_refs():
index = next((i for i,ref in enumerate(refs) if ref["lnum"] == curRow), None)
if index is not None: vim.command(str(index + 1) + "ll")


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...
Expand Down