дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 17:21:13 +02:00
Follow-up to #6520. Find Usages, Go to Declaration and Rename of a pytest fixture now search where pytest would look: the defining test module, the test files below a conftest.py, or the project's test files for a plugin or pytest_plugins module, with test files taken from python_files in the configuration file pytest reads. A fixture imported into a conftest or test module is that module's own. Rename merges the language server's rename of the fixture function, refuses names that clash with a parameter or body name, an override or another fixture in scope, and invalid identifiers, and reads of a parameter skip nested scopes that rebind it. Co-authored-by: wildcatDownstairs <[email protected]>
60 рядки
2.3 KiB
TypeScript
60 рядки
2.3 KiB
TypeScript
/**
|
|
* Find Usages and Rename for names the language server doesn't connect (pytest fixtures and
|
|
* the tests that request them). A provider answers only for positions it owns; the first
|
|
* answer wins, and everywhere else the server's answer is used as before.
|
|
*/
|
|
import type { EditorView } from "@codemirror/view";
|
|
import type { Location, Pos, RequestId, WorkspaceEdit } from "@/platform/ipc";
|
|
|
|
export interface UsageQuery {
|
|
doc: number;
|
|
path: string;
|
|
pos: Pos;
|
|
}
|
|
|
|
/** Usages of the symbol at `query`, or null when the provider doesn't own that position. */
|
|
type UsageProvider = (query: UsageQuery, request: RequestId) => Promise<Location[] | null>;
|
|
|
|
export interface ContributedRename {
|
|
/** The name being renamed, in the editor's document. */
|
|
from: number;
|
|
to: number;
|
|
/** Why it can't be renamed (defined outside the project, …); the rename stops with this hint. */
|
|
refused?: string;
|
|
/** The edit renaming it to `newName`, and a warning to show with it (in the preview). */
|
|
edit: (newName: string, request: RequestId) => Promise<{ edit: WorkspaceEdit; note?: string | null }>;
|
|
}
|
|
|
|
type RenameProvider = (view: EditorView, offset: number) => Promise<ContributedRename | null>;
|
|
|
|
const usageProviders = new Set<UsageProvider>();
|
|
const renameProviders = new Set<RenameProvider>();
|
|
|
|
export function registerUsageProvider(provider: UsageProvider): () => void {
|
|
usageProviders.add(provider);
|
|
return () => void usageProviders.delete(provider);
|
|
}
|
|
|
|
export function registerRenameProvider(provider: RenameProvider): () => void {
|
|
renameProviders.add(provider);
|
|
return () => void renameProviders.delete(provider);
|
|
}
|
|
|
|
export async function contributedUsages(query: UsageQuery, request: RequestId): Promise<Location[] | null> {
|
|
for (const provider of usageProviders) {
|
|
// oxlint-disable-next-line no-await-in-loop -- first owner wins
|
|
const found = await provider(query, request).catch(() => null);
|
|
if (found) return found;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export async function contributedRename(view: EditorView, offset: number): Promise<ContributedRename | null> {
|
|
for (const provider of renameProviders) {
|
|
// oxlint-disable-next-line no-await-in-loop -- first owner wins
|
|
const found = await provider(view, offset).catch(() => null);
|
|
if (found) return found;
|
|
}
|
|
return null;
|
|
}
|