handleDocumentSymbol returns symbols in the document (SQL statements, tables, columns)
(params json.RawMessage)
| 1188 | |
| 1189 | // handleDocumentSymbol returns symbols in the document (SQL statements, tables, columns) |
| 1190 | func (h *Handler) handleDocumentSymbol(params json.RawMessage) ([]DocumentSymbol, error) { |
| 1191 | var p DocumentSymbolParams |
| 1192 | if err := json.Unmarshal(params, &p); err != nil { |
| 1193 | return nil, err |
| 1194 | } |
| 1195 | |
| 1196 | content, ok := h.server.Documents().GetContent(p.TextDocument.URI) |
| 1197 | if !ok { |
| 1198 | return []DocumentSymbol{}, nil |
| 1199 | } |
| 1200 | |
| 1201 | // Parse the SQL to extract symbols |
| 1202 | ast, err := gosqlx.Parse(content) |
| 1203 | if err != nil { |
| 1204 | // Return empty symbols on parse error |
| 1205 | return []DocumentSymbol{}, nil |
| 1206 | } |
| 1207 | |
| 1208 | symbols := []DocumentSymbol{} |
| 1209 | lines := strings.Split(content, "\n") |
| 1210 | |
| 1211 | // Extract symbols from each statement |
| 1212 | for i, stmt := range ast.Statements { |
| 1213 | symbol := h.extractStatementSymbol(stmt, i, lines, content) |
| 1214 | if symbol != nil { |
| 1215 | symbols = append(symbols, *symbol) |
| 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | return symbols, nil |
| 1220 | } |
| 1221 | |
| 1222 | // extractStatementSymbol extracts a document symbol from a SQL statement |
| 1223 | func (h *Handler) extractStatementSymbol(stmt interface{}, index int, lines []string, content string) *DocumentSymbol { |
no test coverage detected