Skip to content

Commit

Permalink
Don't let PSR4 CodeIntelError kill a lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
ssigwart authored Aug 23, 2019
1 parent e541400 commit bed4d63
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/codeintel/lib/codeintel2/tree_php.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,10 @@ def _classes_from_scope(self, expr, scoperef, allowGlobalClasses=False):
and child.get("symbol"):
module = "\\%s\\%s" % (child.get("module"), child.get("symbol"))
self.attemptingPSR4Autoloading = True
elem, scope = self._hit_from_citdl(module, scoperef)
try:
elem, scope = self._hit_from_citdl(module, scoperef)
except CodeIntelError:
elem = None
self.attemptingPSR4Autoloading = False
if elem and scope:
for subelem in elem:
Expand Down Expand Up @@ -1268,19 +1271,23 @@ def _hits_from_first_part(self, tokens, scoperef):
if expr not in attempted_psr4_exprs:
attempted_psr4_exprs[expr] = True
self.attemptingPSR4Autoloading = True
hit = self._hit_from_citdl(expr, scoperef)
try:
hit = self._hit_from_citdl(expr, scoperef)
except CodeIntelError:
hit = None
self.attemptingPSR4Autoloading = False
found_elem, scope = hit
if found_elem and scope and \
found_elem.get("ilk") == "class":
# TODO: technically PSR-4 requires only one class
# per file. Ideally we'd check for that here, but
# that's a bit more work that may not be worth it.
class_name = found_elem.get("name")
file_name = scope[0].get("name")
if file_name.endswith(".php") \
and file_name.startswith(class_name + "."):
return ([hit], 1)
if hit:
found_elem, scope = hit
if found_elem and scope and \
found_elem.get("ilk") == "class":
# TODO: technically PSR-4 requires only one class
# per file. Ideally we'd check for that here, but
# that's a bit more work that may not be worth it.
class_name = found_elem.get("name")
file_name = scope[0].get("name")
if file_name.endswith(".php") \
and file_name.startswith(class_name + "."):
return ([hit], 1)
else:
if "\\" not in first_token and elem.get("ilk") == "namespace":
self.log("_hits_from_first_part:: checking for a FQN hit")
Expand Down

0 comments on commit bed4d63

Please sign in to comment.