@@ -12,7 +12,7 @@ import (
1212)
1313
1414// Gets the full code block surrounding the start of the input location
15- func GetFullDefinition (ctx context.Context , client * lsp.Client , startLocation protocol.Location ) (string , protocol.Location , error ) {
15+ func GetFullDefinition (ctx context.Context , client * lsp.Client , startLocation protocol.Location ) (string , protocol.Location , protocol. DocumentSymbolResult , error ) {
1616 symParams := protocol.DocumentSymbolParams {
1717 TextDocument : protocol.TextDocumentIdentifier {
1818 URI : startLocation .URI ,
@@ -22,22 +22,24 @@ func GetFullDefinition(ctx context.Context, client *lsp.Client, startLocation pr
2222 // Get all symbols in document
2323 symResult , err := client .DocumentSymbol (ctx , symParams )
2424 if err != nil {
25- return "" , protocol.Location {}, fmt .Errorf ("failed to get document symbols: %w" , err )
25+ return "" , protocol.Location {}, nil , fmt .Errorf ("failed to get document symbols: %w" , err )
2626 }
2727
2828 symbols , err := symResult .Results ()
2929 if err != nil {
30- return "" , protocol.Location {}, fmt .Errorf ("failed to process document symbols: %w" , err )
30+ return "" , protocol.Location {}, nil , fmt .Errorf ("failed to process document symbols: %w" , err )
3131 }
3232
3333 var symbolRange protocol.Range
34+ var symbol protocol.DocumentSymbolResult
3435 found := false
3536
3637 // Search for symbol at startLocation
3738 var searchSymbols func (symbols []protocol.DocumentSymbolResult ) bool
3839 searchSymbols = func (symbols []protocol.DocumentSymbolResult ) bool {
3940 for _ , sym := range symbols {
4041 if containsPosition (sym .GetRange (), startLocation .Range .Start ) {
42+ symbol = sym
4143 symbolRange = sym .GetRange ()
4244 found = true
4345 return true
@@ -62,14 +64,14 @@ func GetFullDefinition(ctx context.Context, client *lsp.Client, startLocation pr
6264 // Convert URI to filesystem path
6365 filePath , err := url .PathUnescape (strings .TrimPrefix (string (startLocation .URI ), "file://" ))
6466 if err != nil {
65- return "" , protocol.Location {}, fmt .Errorf ("failed to unescape URI: %w" , err )
67+ return "" , protocol.Location {}, nil , fmt .Errorf ("failed to unescape URI: %w" , err )
6668 }
6769
6870 // Read the file to get the full lines of the definition
6971 // because we may have a start and end column
7072 content , err := os .ReadFile (filePath )
7173 if err != nil {
72- return "" , protocol.Location {}, fmt .Errorf ("failed to read file: %w" , err )
74+ return "" , protocol.Location {}, nil , fmt .Errorf ("failed to read file: %w" , err )
7375 }
7476
7577 lines := strings .Split (string (content ), "\n " )
@@ -79,7 +81,7 @@ func GetFullDefinition(ctx context.Context, client *lsp.Client, startLocation pr
7981
8082 // Get the line at the end of the range
8183 if int (symbolRange .End .Line ) >= len (lines ) {
82- return "" , protocol.Location {}, fmt .Errorf ("line number out of range" )
84+ return "" , protocol.Location {}, nil , fmt .Errorf ("line number out of range" )
8385 }
8486
8587 line := lines [symbolRange .End .Line ]
@@ -128,14 +130,14 @@ func GetFullDefinition(ctx context.Context, client *lsp.Client, startLocation pr
128130
129131 // Return the text within the range
130132 if int (symbolRange .End .Line ) >= len (lines ) {
131- return "" , protocol.Location {}, fmt .Errorf ("end line out of range" )
133+ return "" , protocol.Location {}, nil , fmt .Errorf ("end line out of range" )
132134 }
133135
134136 selectedLines := lines [symbolRange .Start .Line : symbolRange .End .Line + 1 ]
135- return strings .Join (selectedLines , "\n " ), startLocation , nil
137+ return strings .Join (selectedLines , "\n " ), startLocation , symbol , nil
136138 }
137139
138- return "" , protocol.Location {}, fmt .Errorf ("symbol not found" )
140+ return "" , protocol.Location {}, nil , fmt .Errorf ("symbol not found" )
139141}
140142
141143// GetLineRangesToDisplay determines which lines should be displayed for a set of locations
@@ -146,7 +148,7 @@ func GetLineRangesToDisplay(ctx context.Context, client *lsp.Client, locations [
146148 // For each location, get its container and add relevant lines
147149 for _ , loc := range locations {
148150 // Use GetFullDefinition to find container
149- _ , containerLoc , err := GetFullDefinition (ctx , client , loc )
151+ _ , containerLoc , _ , err := GetFullDefinition (ctx , client , loc )
150152 if err != nil {
151153 // If container not found, just use the location's line
152154 refLine := int (loc .Range .Start .Line )
0 commit comments