| 270 | } |
| 271 | |
| 272 | export async function navigateToSymbol( |
| 273 | view: EditorView, |
| 274 | symbol: FlatSymbol | ProcessedSymbol, |
| 275 | ): Promise<boolean> { |
| 276 | try { |
| 277 | const doc = view.state.doc; |
| 278 | let targetLine: number; |
| 279 | let targetChar: number; |
| 280 | |
| 281 | if ("line" in symbol) { |
| 282 | targetLine = symbol.line; |
| 283 | targetChar = symbol.character; |
| 284 | } else { |
| 285 | targetLine = symbol.selectionRange.startLine; |
| 286 | targetChar = symbol.selectionRange.startCharacter; |
| 287 | } |
| 288 | |
| 289 | const lineNumber = targetLine + 1; |
| 290 | if (lineNumber < 1 || lineNumber > doc.lines) { |
| 291 | return false; |
| 292 | } |
| 293 | |
| 294 | const line = doc.line(lineNumber); |
| 295 | const pos = Math.min(line.from + targetChar, line.to); |
| 296 | |
| 297 | view.dispatch({ |
| 298 | selection: { anchor: pos }, |
| 299 | scrollIntoView: true, |
| 300 | }); |
| 301 | |
| 302 | view.focus(); |
| 303 | return true; |
| 304 | } catch (error) { |
| 305 | console.warn("Failed to navigate to symbol:", error); |
| 306 | return false; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | export function supportsDocumentSymbols(view: EditorView): boolean { |
| 311 | const plugin = LSPPlugin.get(view) as LSPPluginAPI | null; |