Skip to content

Commit

Permalink
Skip outdated trg-from-pos requests.
Browse files Browse the repository at this point in the history
- For large files, trg-from-pos requests can back up as you type. I can't think of any reason why we'd need to process a request if we got a newer request for a new position.
  • Loading branch information
ssigwart committed Jul 6, 2019
1 parent 4b8a10a commit ef5b10a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/codeintel/lib/codeintel2/oop/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def __init__(self, db_base_dir=None, fd_in=sys.stdin, fd_out=sys.stdout):

self.queue = collections.deque()
self.queue_cv = threading.Condition()
self.pending_trg_from_pos_cnts = {}
self.env = Environment(name="global",
send_fn=functools.partial(self.send, request=None))

Expand Down Expand Up @@ -384,6 +385,7 @@ def get_buffer(self, request=REQUEST_DEFAULT, path=None):
log.debug("Got buffer %r", buf)

self.buffers[path] = buf

return buf

def do_abort(self, request):
Expand Down Expand Up @@ -504,6 +506,11 @@ def start(self):
else:
log.debug("queuing request %r", request)
with self.queue_cv:
if request.get("command") == "trg-from-pos" and request.path:
if request.path in self.pending_trg_from_pos_cnts:
self.pending_trg_from_pos_cnts[request.path] += 1
else:
self.pending_trg_from_pos_cnts[request.path] = 1
self.queue.appendleft(request)
self.queue_cv.notify()
elif ch in "0123456789":
Expand Down Expand Up @@ -850,6 +857,20 @@ def do_trg_from_pos(self, request, driver):
except AttributeError:
raise RequestFailure(message="No position given for trigger")
buf = driver.get_buffer(request)

# If there's more than 1 pending requests, ignore until we get to the
# latest one. The others aren't important anymore
try:
if request.path in driver.pending_trg_from_pos_cnts:
if driver.pending_trg_from_pos_cnts[request.path] == 1:
del driver.pending_trg_from_pos_cnts[request.path]
else:
driver.pending_trg_from_pos_cnts[request.path] -= 1
driver.send(trg=None)
return
except:
log.error("Failed to check for pending requests")

if "curr-pos" in request:
trg = buf.preceding_trg_from_pos(pos, int(request["curr-pos"]))
elif request.get("type", None) == "defn":
Expand Down

0 comments on commit ef5b10a

Please sign in to comment.