( snippet: string, symbol: string, language?: string, )
| 246 | // --------------------------------------------------------------------------- |
| 247 | |
| 248 | export function classifyMatch( |
| 249 | snippet: string, |
| 250 | symbol: string, |
| 251 | language?: string, |
| 252 | ): "definition" | "reference" { |
| 253 | const escaped = escapeRegex(symbol); |
| 254 | |
| 255 | if (language) { |
| 256 | const langPatterns = DEFINITION_PATTERNS.find((p) => |
| 257 | p.languages.includes(language), |
| 258 | ); |
| 259 | if (langPatterns) { |
| 260 | for (const pattern of langPatterns.patterns) { |
| 261 | const re = new RegExp(pattern.replace("SYMBOL", escaped)); |
| 262 | if (re.test(snippet)) return "definition"; |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | for (const pattern of GENERIC_DEFINITION_PATTERNS) { |
| 268 | const re = new RegExp(pattern.replace("SYMBOL", escaped)); |
| 269 | if (re.test(snippet)) return "definition"; |
| 270 | } |
| 271 | |
| 272 | return "reference"; |
| 273 | } |
| 274 | |
| 275 | // --------------------------------------------------------------------------- |
| 276 | // Ranking |
no test coverage detected