Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent vscode extension from locking the language server executable #100

Merged
merged 1 commit into from
Feb 19, 2024
Merged
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
18 changes: 11 additions & 7 deletions packages/vscode-pyright/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
} from 'vscode-languageclient/node';
import { FileBasedCancellationStrategy } from './cancellationUtils';
import { githubRepo, toolName } from 'pyright-internal/constants';
import { cp } from 'fs/promises';

let cancellationStrategy: FileBasedCancellationStrategy | undefined;

Expand Down Expand Up @@ -95,16 +96,19 @@ export async function activate(context: ExtensionContext) {
let serverOptions: ServerOptions | undefined = undefined;
if (workspace.getConfiguration('basedpyright').get('importStrategy') === 'fromEnvironment') {
const pythonApi = await PythonExtension.api();
const scriptName = 'basedpyright-langserver';
const executablePath = path.join(
pythonApi.environments.getActiveEnvironmentPath().path,
'..',
os.platform() === 'win32' ? `${scriptName}.exe` : scriptName
);
const executableName = `basedpyright-langserver${os.platform() === 'win32' ? '.exe' : ''}`;
const executableDir = path.join(pythonApi.environments.getActiveEnvironmentPath().path, '..');
const executablePath = path.join(executableDir, executableName);
if (existsSync(executablePath)) {
console.log('using pyright executable:', executablePath);

// make a copy of the exe to avoid locking it, which would otherwise cause crashes when you try to
// update/uninstall basedpyright while vscode is open
const copiedExecutablePath = path.join(executableDir, `_vscode_copy_${executableName}`);
await cp(executablePath, copiedExecutablePath, { force: true });

serverOptions = {
command: executablePath,
command: copiedExecutablePath,
transport: TransportKind.stdio,
args: cancellationStrategy.getCommandLineArguments(),
};
Expand Down
Loading