Skip to content

Commit 96bc03e

Browse files
committed
Future-proof location detection (new feature in Crystal JSON)
crystal-lang/crystal#10122
1 parent 254d4c8 commit 96bc03e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

mkdocstrings/handlers/crystal/items.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,19 @@ def args_html(self) -> crystal_html.TextWithLinks:
325325

326326
@cached_property
327327
def location(self) -> Optional[DocLocation]:
328-
m = re.fullmatch(r".+?/(?:blob|tree)/[^/]+/(.+)#L(\d+)", self.data.get("source_link") or "")
329-
if m:
330-
filename, line = m.groups()
331-
return DocLocation(filename, line, self.data.get("source_link"))
328+
# https://github.com/crystal-lang/crystal/pull/10122
329+
try:
330+
loc = self.data["location"]
331+
except KeyError:
332+
m = re.fullmatch(
333+
r".+?/(?:blob|tree)/[^/]+/(.+)#L(\d+)", self.data.get("source_link") or ""
334+
)
335+
if m:
336+
filename, line = m.groups()
337+
return DocLocation(filename, line, self.data.get("source_link"))
338+
else:
339+
if loc:
340+
return DocLocation(loc["filename"], loc["line_number"], loc["url"])
332341

333342

334343
class DocInstanceMethod(DocMethod):

0 commit comments

Comments
 (0)