Skip to content

Commit fbd3c05

Browse files
authored
improve github search URL generation (#233)
I had accidentally reverted to a worse github search link URL. This PR improves the link generation so that a fully-qualified class name + templates is extracted to the component class names and template names. E.g., https://github.com/search?q=repo%3Allvm%2Fllvm-project+ExpandIfCondition+ExitDataOp+path%3Amlir&type=code Which produces <img width="1130" height="579" alt="image" src="https://github.com/user-attachments/assets/d79ac4cf-16ad-4aa5-ad5a-bc72602493b7" /> I can't match the exact line because the classname available to the UI has the fully-qualified template parameter (with a leading `::mlir`) but the code has that part implicit. Since I can't know in advance how the source will use the template parameter, it seems simplest to just have a conjunction in the query and deal with the slightly imprecise GitHub search UI. Co-authored-by: Jeremy Kun <[email protected]>
1 parent 7c241cd commit fbd3c05

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

website/static/js/pattern-search.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,50 @@ class MLIRSearch {
155155
}
156156

157157
generateGitHubURL(className) {
158-
return `https://github.com/llvm/llvm-project/search?q=${encodeURIComponent(className)}&type=code`;
158+
// Extract bare class name and template parameters without namespaces
159+
// Example: ::foo::bar::ClassName<baz::Quux, other::Type> -> search for "ClassName Quux Type"
160+
161+
const searchTerms = [];
162+
163+
// Extract bare class name (everything after last :: before any <)
164+
const templateStart = className.indexOf("<");
165+
const classNamePart =
166+
templateStart >= 0 ? className.substring(0, templateStart) : className;
167+
const lastColonIndex = classNamePart.lastIndexOf("::");
168+
const bareClassName =
169+
lastColonIndex >= 0
170+
? classNamePart.substring(lastColonIndex + 2)
171+
: classNamePart;
172+
searchTerms.push(bareClassName);
173+
174+
// Extract template parameters if they exist
175+
if (templateStart >= 0) {
176+
const templateEnd = className.lastIndexOf(">");
177+
if (templateEnd > templateStart) {
178+
const templateContent = className.substring(
179+
templateStart + 1,
180+
templateEnd,
181+
);
182+
183+
// Split by comma and extract bare names from each parameter
184+
const params = templateContent.split(",");
185+
params.forEach((param) => {
186+
const trimmed = param.trim();
187+
// Remove any namespace qualification from the parameter
188+
const lastColonInParam = trimmed.lastIndexOf("::");
189+
const bareParam =
190+
lastColonInParam >= 0
191+
? trimmed.substring(lastColonInParam + 2)
192+
: trimmed;
193+
if (bareParam) {
194+
searchTerms.push(bareParam);
195+
}
196+
});
197+
}
198+
}
199+
200+
const searchQuery = searchTerms.join(" ") + " path:mlir";
201+
return `https://github.com/llvm/llvm-project/search?q=${encodeURIComponent(searchQuery)}&type=code`;
159202
}
160203
}
161204

0 commit comments

Comments
 (0)