@@ -68,15 +68,19 @@ func (h *definitionHandler) findMixinsDefinition(doc *string, params *lsp.Defini
6868
6969 filename := h .parser .extractFilenameFromMixins (doc , params .Position )
7070 if filename == "" {
71+ h .parser .log .Debugf ("no mixin filename resolved at %s:%d:%d" , path , params .Position .Line , params .Position .Character )
7172 return nil , nil
7273 }
7374
7475 absFilename := replacePathFilename (path , filename )
7576
7677 if ! util .FileExists (absFilename ) {
78+ h .parser .log .Debugf ("mixin target does not exist: %s" , absFilename )
7779 return nil , nil
7880 }
7981
82+ h .parser .log .Debugf ("resolved mixin definition %q -> %s" , filename , absFilename )
83+
8084 return []lsp.Location {
8185 {
8286 URI : pathToURI (absFilename ),
@@ -86,21 +90,28 @@ func (h *definitionHandler) findMixinsDefinition(doc *string, params *lsp.Defini
8690}
8791
8892func (h * definitionHandler ) findCommandDefinition (doc * string , params * lsp.DefinitionParams ) (any , error ) {
89- line := getLine (doc , params .Position .Line )
90- if line == "" {
91- return nil , nil
92- }
93+ path := normalizePath (params .TextDocument .URI )
9394
94- word := wordUnderCursor (line , & params .Position )
95- if word == "" {
95+ commandName := h .parser .extractCommandReference (doc , params .Position )
96+ if commandName == "" {
97+ h .parser .log .Debugf ("no command reference resolved at %s:%d:%d" , path , params .Position .Line , params .Position .Character )
9698 return nil , nil
9799 }
98100
99- command := h .parser .findCommand (doc , word )
101+ command := h .parser .findCommand (doc , commandName )
100102 if command == nil {
103+ h .parser .log .Debugf ("command reference %q did not match any local command" , commandName )
101104 return nil , nil
102105 }
103106
107+ h .parser .log .Debugf (
108+ "resolved command definition %q -> %s:%d:%d" ,
109+ commandName ,
110+ path ,
111+ command .position .Line ,
112+ command .position .Character ,
113+ )
114+
104115 // TODO: theoretically we can have multiple commands with the same name if we have mixins
105116 return []lsp.Location {
106117 {
@@ -159,13 +170,22 @@ func (s *lspServer) textDocumentDefinition(context *glsp.Context, params *lsp.De
159170 doc := s .storage .GetDocument (params .TextDocument .URI )
160171
161172 p := newParser (s .log )
162-
163- switch p .getPositionType (doc , params .Position ) {
173+ positionType := p .getPositionType (doc , params .Position )
174+ s .log .Debugf (
175+ "definition request uri=%s line=%d char=%d type=%s" ,
176+ normalizePath (params .TextDocument .URI ),
177+ params .Position .Line ,
178+ params .Position .Character ,
179+ positionType ,
180+ )
181+
182+ switch positionType {
164183 case PositionTypeMixins :
165184 return definitionHandler .findMixinsDefinition (doc , params )
166- case PositionTypeDepends :
185+ case PositionTypeDepends , PositionTypeCommandAlias :
167186 return definitionHandler .findCommandDefinition (doc , params )
168187 default :
188+ s .log .Debugf ("definition request ignored: unsupported cursor position" )
169189 return nil , nil
170190 }
171191}
0 commit comments