release: prepare WRNexusJS 0.8.8
This commit is contained in:
@@ -15,7 +15,9 @@ const SKIPPED_DIRECTORIES = new Set([
|
||||
]);
|
||||
const MAX_INDEX_FILES = 5_000;
|
||||
const MAX_SOURCE_BYTES = 1_048_576;
|
||||
const INDEX_TTL_MS = 5_000;
|
||||
// Completion can be requested repeatedly while the list is visible. Avoid
|
||||
// rescanning thousands of files on that hot path; document saves invalidate it.
|
||||
const INDEX_TTL_MS = 5 * 60_000;
|
||||
const MAX_CACHED_ROOTS = 8;
|
||||
const workspaceIndexCache = new Map<
|
||||
string,
|
||||
@@ -168,6 +170,30 @@ export function clearWorkspaceIndexCache(root?: string): void {
|
||||
else workspaceIndexCache.clear();
|
||||
}
|
||||
|
||||
export function workspaceSymbolLocations(root: string, name: string, limit = 1_000) {
|
||||
if (!/^[A-Za-z_$][\w$]*$/.test(name)) return [];
|
||||
const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
const pattern = new RegExp(`(?<![A-Za-z0-9_$])${escaped}(?![A-Za-z0-9_$])`, "g");
|
||||
const locations: Array<{ uri: string; range: Range }> = [];
|
||||
for (const file of walk(resolve(root), (path) => extname(path) === ".wrn").slice(0, limit)) {
|
||||
let source: string;
|
||||
try {
|
||||
source = readFileSync(file, "utf8");
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
for (const match of source.matchAll(pattern)) {
|
||||
const before = source.slice(0, match.index!).split(/\r?\n/);
|
||||
const start = { line: before.length - 1, character: before.at(-1)?.length ?? 0 };
|
||||
locations.push({
|
||||
uri: `file:///${file.replace(/\\/g, "/")}`,
|
||||
range: { start, end: { line: start.line, character: start.character + name.length } },
|
||||
});
|
||||
}
|
||||
}
|
||||
return locations;
|
||||
}
|
||||
|
||||
export function extractComponentRefactor(document: TextDocument, range: Range, name: string) {
|
||||
if (!/^[A-Z][A-Za-z0-9_$]*$/.test(name)) throw new Error("Component name must use PascalCase");
|
||||
const lines = document.text.split(/\r?\n/);
|
||||
|
||||
Reference in New Issue
Block a user