Skip to content

Commit

Permalink
fix: codeintel: Do not error on blank documents - fixes #895
Browse files Browse the repository at this point in the history
For some reason, there was an assumption there was always at least one token in the document.

rn=

(integrated from master branch change 9.2.1-700-ge195eea by Mitchell <mitchellb@activestate.com>)
  • Loading branch information
mitchell-as committed Nov 23, 2015
1 parent ca60b2d commit 89e91bd
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/codeintel/lib/codeintel2/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ def _token_at_pos(self, pos):
lower, upper = 0, len(self.tokens) # [lower-limit, upper-limit)
if upper == 1:
return self.tokens[0]
elif upper == 0:
return {"style": 0, "start_index": 0, "end_index": 0} # blank document
# This being a binary search, we should have a maximum of log2(upper)
# iterations. Enforce that in case we have an issue and hit an infinite
# loop.
Expand Down

0 comments on commit 89e91bd

Please sign in to comment.