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

Function fetchReferences

src/cm/lsp/references.ts:101–157  ·  view source on GitHub ↗
(
	view: EditorView,
)

Source from the content-addressed store, hash-verified

99}
100
101async function fetchReferences(
102 view: EditorView,
103): Promise<{ symbolName: string; references: ReferenceWithContext[] } | null> {
104 const plugin = LSPPlugin.get(view);
105 if (!plugin) {
106 return null;
107 }
108
109 const client = plugin.client;
110 const capabilities = client.serverCapabilities;
111
112 if (!capabilities?.referencesProvider) {
113 const toast = (globalThis as Record<string, unknown>).toast as
114 | ((msg: string) => void)
115 | undefined;
116 toast?.("Language server does not support find references");
117 return null;
118 }
119
120 const { state } = view;
121 const pos = state.selection.main.head;
122 const line = state.doc.lineAt(pos);
123 const lineNumber = line.number - 1;
124 const character = pos - line.from;
125 const uri = plugin.uri;
126
127 const symbolName = getWordAtCursor(view);
128
129 client.sync();
130
131 const params: ReferenceParams = {
132 textDocument: { uri },
133 position: { line: lineNumber, character },
134 context: { includeDeclaration: true },
135 };
136
137 const locations = await client.request<ReferenceParams, Location[] | null>(
138 "textDocument/references",
139 params,
140 );
141
142 if (!locations || locations.length === 0) {
143 return { symbolName, references: [] };
144 }
145
146 const refsWithContext: ReferenceWithContext[] = await Promise.all(
147 locations.map(async (loc) => {
148 const lineText = await fetchLineText(loc.uri, loc.range.start.line);
149 return {
150 ...loc,
151 lineText,
152 };
153 }),
154 );
155
156 return { symbolName, references: refsWithContext };
157}
158

Callers 2

findAllReferencesFunction · 0.85
findAllReferencesInTabFunction · 0.85

Calls 3

getWordAtCursorFunction · 0.85
fetchLineTextFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected