@@ -216,9 +216,9 @@ def get_url_completions(self, match: Match):
216216 prefix = match .group (2 )
217217 logger .debug (f"Find url matches for: { prefix } " )
218218 return [
219- CompletionItem (label = url )
220- for url in self .workspace_index .urls
221- if url .startswith (prefix )
219+ CompletionItem (label = url . name , documentation = url . docs )
220+ for url in self .workspace_index .urls . values ()
221+ if url .name . startswith (prefix )
222222 ]
223223
224224 def get_template_completions (self , match : Match ):
@@ -315,6 +315,7 @@ def get_context_completions(self, match: Match):
315315 def hover (self , line , character ):
316316 line_fragment = self .document .lines [line ][:character ]
317317 matchers = [
318+ (re .compile (r""".*{% ?url ('|")([\w\-:]*)$""" ), self .get_url_hover ),
318319 (re .compile (r"^.*({%|{{) ?[\w \.\|]*\|(\w*)$" ), self .get_filter_hover ),
319320 (re .compile (r"^.*{% ?(\w*)$" ), self .get_tag_hover ),
320321 ]
@@ -323,6 +324,16 @@ def hover(self, line, character):
323324 return hover (line , character , match )
324325 return None
325326
327+ def get_url_hover (self , line , character , match : Match ):
328+ full_match = self ._get_full_hover_name (
329+ line , character , match .group (2 ), regex = r"^([\w\d:\-]+).*"
330+ )
331+ logger .debug (f"Find url hover for: { full_match } " )
332+ if url := self .workspace_index .urls .get (full_match ):
333+ return Hover (
334+ contents = url .docs ,
335+ )
336+
326337 def get_filter_hover (self , line , character , match : Match ):
327338 filter_name = self ._get_full_hover_name (line , character , match .group (2 ))
328339 logger .debug (f"Find filter hover for: { filter_name } " )
@@ -343,10 +354,8 @@ def get_tag_hover(self, line, character, match: Match):
343354 )
344355 return None
345356
346- def _get_full_hover_name (self , line , character , first_part ):
347- if match_after := re .match (
348- r"^([\w\d]+).*" , self .document .lines [line ][character :]
349- ):
357+ def _get_full_hover_name (self , line , character , first_part , regex = r"^([\w\d]+).*" ):
358+ if match_after := re .match (regex , self .document .lines [line ][character :]):
350359 return first_part + match_after .group (1 )
351360 return first_part
352361
@@ -360,6 +369,7 @@ def goto_definition(self, line, character):
360369 re .compile (r""".*{% ?(extends|include) ('|")([\w\-\./]*)$""" ),
361370 self .get_template_definition ,
362371 ),
372+ (re .compile (r""".*{% ?url ('|")([\w\-:]*)$""" ), self .get_url_definition ),
363373 (re .compile (r"^.*{% ?(\w*)$" ), self .get_tag_definition ),
364374 (re .compile (r"^.*({%|{{).*?\|(\w*)$" ), self .get_filter_definition ),
365375 (
@@ -394,6 +404,15 @@ def get_template_definition(self, line, character, match: Match):
394404 location , path = template .path .split (":" )
395405 return self .create_location (location , path , 0 )
396406
407+ def get_url_definition (self , line , character , match : Match ):
408+ full_match = self ._get_full_definition_name (
409+ line , character , match .group (2 ), regex = r"^([\w\d:\-]+).*"
410+ )
411+ logger .debug (f"Find url goto definition for: { full_match } " )
412+ if url := self .workspace_index .urls .get (full_match ):
413+ if url .source :
414+ return self .create_location (* url .source .split (":" ))
415+
397416 def get_tag_definition (self , line , character , match : Match ):
398417 full_match = self ._get_full_definition_name (line , character , match .group (1 ))
399418 logger .debug (f"Find tag goto definition for: { full_match } " )
@@ -430,9 +449,9 @@ def get_context_definition(self, line, character, match: Match):
430449 ),
431450 )
432451
433- def _get_full_definition_name (self , line , character , first_part ):
434- if match_after := re . match (
435- r"^([\w\d]+).*" , self . document . lines [ line ][ character :]
436- ):
452+ def _get_full_definition_name (
453+ self , line , character , first_part , regex = r"^([\w\d]+).*"
454+ ):
455+ if match_after := re . match ( regex , self . document . lines [ line ][ character :] ):
437456 return first_part + match_after .group (1 )
438457 return first_part
0 commit comments