MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / navigateToSymbol

Function navigateToSymbol

src/cm/lsp/documentSymbols.ts:272–308  ·  view source on GitHub ↗
(
	view: EditorView,
	symbol: FlatSymbol | ProcessedSymbol,
)

Source from the content-addressed store, hash-verified

270}
271
272export 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
310export function supportsDocumentSymbols(view: EditorView): boolean {
311 const plugin = LSPPlugin.get(view) as LSPPluginAPI | null;

Callers

nothing calls this directly

Calls 1

focusMethod · 0.80

Tested by

no test coverage detected