@@ -360,6 +360,8 @@ def goto_definition(self, line, character):
360360 re .compile (r""".*{% ?(extends|include) ('|")([\w\-\./]*)$""" ),
361361 self .get_template_definition ,
362362 ),
363+ (re .compile (r"^.*{% ?(\w*)$" ), self .get_tag_definition ),
364+ (re .compile (r"^.*({%|{{).*?\|(\w*)$" ), self .get_filter_definition ),
363365 (
364366 re .compile (r".*({{|{% \w+ ).*?([\w\d_\.]*)$" ),
365367 self .get_context_definition ,
@@ -370,24 +372,43 @@ def goto_definition(self, line, character):
370372 return definition (line , character , match )
371373 return None
372374
375+ def create_location (self , location , path , line ):
376+ root_path = (
377+ self .workspace_index .src_path
378+ if location == "src"
379+ else self .workspace_index .env_path
380+ )
381+ return Location (
382+ uri = f"file://{ root_path } /{ path } " ,
383+ range = Range (
384+ start = Position (line = int (line ), character = 0 ),
385+ end = Position (line = int (line ), character = 0 ),
386+ ),
387+ )
388+
373389 def get_template_definition (self , line , character , match : Match ):
374390 if match_after := re .match (r'^(.*)".*' , self .document .lines [line ][character :]):
375391 template_name = match .group (3 ) + match_after .group (1 )
376392 logger .debug (f"Find template goto definition for: { template_name } " )
377393 if template := self .workspace_index .templates .get (template_name ):
378394 location , path = template .path .split (":" )
379- root_path = (
380- self .workspace_index .src_path
381- if location == "src"
382- else self .workspace_index .env_path
383- )
384- return Location (
385- uri = f"file://{ root_path } /{ path } " ,
386- range = Range (
387- start = Position (line = 0 , character = 0 ),
388- end = Position (line = 0 , character = 0 ),
389- ),
390- )
395+ return self .create_location (location , path , 0 )
396+
397+ def get_tag_definition (self , line , character , match : Match ):
398+ full_match = self ._get_full_definition_name (line , character , match .group (1 ))
399+ logger .debug (f"Find tag goto definition for: { full_match } " )
400+ for lib in self .loaded_libraries :
401+ if tag := self .workspace_index .libraries [lib ].tags .get (full_match ):
402+ if tag .source :
403+ return self .create_location (* tag .source .split (":" ))
404+
405+ def get_filter_definition (self , line , character , match : Match ):
406+ full_match = self ._get_full_definition_name (line , character , match .group (2 ))
407+ logger .debug (f"Find filter goto definition for: { full_match } " )
408+ for lib in self .loaded_libraries :
409+ if filter_ := self .workspace_index .libraries [lib ].filters .get (full_match ):
410+ if filter_ .source :
411+ return self .create_location (* filter_ .source .split (":" ))
391412
392413 def get_context_definition (self , line , character , match : Match ):
393414 first_match = match .group (2 )
0 commit comments