Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/pyrefly_util/src/task_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::lock::Mutex;
#[derive(Debug)]
pub struct Cancelled;

#[derive(Clone, Dupe)]
#[derive(Clone, Default, Dupe)]
pub struct CancellationHandle(Arc<AtomicBool>);

impl CancellationHandle {
Expand Down
46 changes: 46 additions & 0 deletions lsp/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,18 @@ import {runDocstringFoldingCommand} from './docstring';
import {registerCodeLensCommands} from './code-lens';
import {registerHoverProvider} from './hover';
import {PythonEnvironment} from './python-environment';
import {
OverrideCodeLensProvider,
navigateToOverrideTarget,
showOverrideTargets,
} from './overrideCodeLens';
import {
triggerMsPythonRefreshLanguageServersIfInstalled,
} from './extension-interop';
import {describeError, resolveExecutable} from './lsp-path';

let client: LanguageClient;
let overrideCodeLensProvider: OverrideCodeLensProvider;
let outputChannel: vscode.OutputChannel;
let traceOutputChannel: vscode.OutputChannel;
let inferOutputChannel: vscode.OutputChannel;
Expand Down Expand Up @@ -96,6 +102,7 @@ async function replaceClient(): Promise<void> {
launchSpec,
clientOptions,
);
overrideCodeLensProvider.connectClient(client);
try {
await client.start();
logServerVersion();
Expand Down Expand Up @@ -252,6 +259,9 @@ export async function activate(
}

pythonEnv = new PythonEnvironment(context);
overrideCodeLensProvider = new OverrideCodeLensProvider(() => client);
context.subscriptions.push(overrideCodeLensProvider);
const scheduleCodeLensRefresh = () => overrideCodeLensProvider.refresh();

launchSpec = await resolveExecutable(
context.extensionUri,
Expand Down Expand Up @@ -343,12 +353,26 @@ export async function activate(
serverOptions,
clientOptions,
);
overrideCodeLensProvider.connectClient(client);
if (supportsHoverVerbosity) {
registerHoverProvider(context, () => client);
}

context.subscriptions.push(
vscode.languages.registerCodeLensProvider(
[
{scheme: 'file', language: 'python'},
{scheme: 'untitled', language: 'python'},
{scheme: 'vscode-notebook-cell', language: 'python'},
{scheme: 'inmemory', language: 'python'},
],
overrideCodeLensProvider,
),
);

context.subscriptions.push(
vscode.window.onDidChangeActiveTextEditor(async () => {
scheduleCodeLensRefresh();
await updateStatusBar(client);
}),
);
Expand Down Expand Up @@ -386,6 +410,7 @@ export async function activate(
client.sendNotification(DidChangeConfigurationNotification.type, {
settings: {},
});
scheduleCodeLensRefresh();
}
if (
event.affectsConfiguration('pyrefly.lspPath') ||
Expand All @@ -401,6 +426,14 @@ export async function activate(
}),
);

context.subscriptions.push(
workspace.onDidChangeTextDocument(event => {
if (event.document.languageId === 'python') {
scheduleCodeLensRefresh();
}
}),
);
Comment on lines +429 to +435

Copilot AI Mar 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refreshing CodeLenses on every onDidChangeTextDocument for Python means this provider will re-run (and potentially issue many LSP requests) on every keystroke. Consider debouncing this refresh (timer-based) and/or refreshing only on saves / when the edited document is the active editor to reduce churn.

Copilot uses AI. Check for mistakes.

context.subscriptions.push(
vscode.commands.registerCommand('pyrefly.restartClient', async () => {
// Clear the output channel but don't dispose it
Expand Down Expand Up @@ -435,6 +468,7 @@ export async function activate(
);
}
});
scheduleCodeLensRefresh();
}),
);

Expand Down Expand Up @@ -510,6 +544,17 @@ export async function activate(
);
registerCodeLensCommands(context, pythonEnv);

context.subscriptions.push(
vscode.commands.registerCommand(
'pyrefly.navigateToOverrideTarget',
navigateToOverrideTarget,
),
vscode.commands.registerCommand(
'pyrefly.showOverrideTargets',
showOverrideTargets,
),
);

// When our extension is activated, make sure ms-python knows
// TODO(kylei): remove this hack once ms-python has this behavior
await triggerMsPythonRefreshLanguageServersIfInstalled();
Expand Down Expand Up @@ -537,6 +582,7 @@ export async function activate(
}
});
logServerVersion();
scheduleCodeLensRefresh();

await updateStatusBar(client);
const statusBarItem = getStatusBarItem();
Expand Down
Loading
Loading