forked from michaelpnash/sublime-ensime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathensime_completions.py
48 lines (40 loc) · 1.68 KB
/
ensime_completions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os, sys, stat, random, getpass
import ensime_environment
from ensime_server import EnsimeOnly
import functools, socket, threading
import sublime_plugin, sublime
import sexp
from sexp import key,sym
class EnsimeCompletion:
def __init__(self, name, signature, type_id, is_callable = False, to_insert = None):
self.name = name
self.signature = signature
self.is_callable = is_callable
self.type_id = type_id
self.to_insert = to_insert
def ensime_completion(p):
return EnsimeCompletion(
p[":name"],
p[":type-sig"],
p[":type-id"],
bool(p[":is-callable"]) if ":is-callable" in p else False,
p[":to-insert"] if ":to-insert" in p else None)
class EnsimeCompletionsListener(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
#if view.is_dirty():
# view.run_command("save")
if not view.match_selector(locations[0], "source.scala") and not view.match_selector(locations[0], "source.java"):
return []
env = ensime_environment.ensime_env
if env.client() is None:
print("Ensime Server doesn't appear to be started")
return []
data = env.client().complete_member(view.file_name(), locations[0])
if data is None:
print("Returned data was None")
return []
print("Got data for completion:%s", data)
friend = sexp.sexp_to_key_map(data[1][1])
comps = friend[":completions"] if ":completions" in friend else []
comp_list = [ensime_completion(sexp.sexp_to_key_map(p)) for p in friend[":completions"]]
return ([(p.name + "\t" + p.signature, p.name) for p in comp_list], sublime.INHIBIT_EXPLICIT_COMPLETIONS | sublime.INHIBIT_WORD_COMPLETIONS)