pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

[Bug][IDE]: pyrefly vscode ignores search_path in pyproject.toml

Open dzakarov opened this issue 8 months ago • 7 comments

Describe the Bug

The pyrefly cannot find my modules in vscode. The search path was set in pyproject.toml:

[tool.pyrefly]
search_path=["src","test"]

From the command line uv run pyrefly check is able to resolve imports in modules.

Codebase

No response

IDE Setup

No response

Output

No response

Other Attempts

No response

dzakarov avatar May 05 '25 06:05 dzakarov

Hi @dzakarov, we are working to have pyrefly.toml configuration picked up by the extension now. Our path finding logic for IDE should work for most cases out of the box. Can you share more about the Error? Do you have your Python interpreter selected?

Also, if you want the files included for type checking you should use project_includes. search_path is useful for paths that should be findable for checking, but not checked themselves.

lolpack avatar May 05 '25 15:05 lolpack

cc @kinto0 @connernilsen

lolpack avatar May 05 '25 16:05 lolpack

A little clarification on this

Also, if you want the files included for type checking you should use project_includes. search_path is useful for paths that should be findable for checking, but not checked themselves.

project_includes defines patterns for files that should be included in type checking. search_path defines the root(s and priorities) where project imports are importable from, where "project imports" are first-party code that should have very high import precedence.

It looks like @dzakarov's pyproject.toml makes that distinction, which is great! We have some changes that landed recently that should have added support for picking up config stuff in the IDE, and @kinto0 put up a new version earlier today. The version prior to that was released 4/28, which wouldn't have had the functionality yet.

@dzakarov, could you try to update your vscode version and let us know if that's still an issue?

connernilsen avatar May 05 '25 19:05 connernilsen

Today plugin crashes:

Identifier meta.pyrefly Version 0.14.0 Last Updated 2025-05-06, 09:22:51 Size 18.25MB

starting generic LSP server
Workspaces emtpy, skipping project file population
Reading messages
Handling non-canceled request (1)
Thread panicked, shutting down: panicked at lib/module/module_info.rs:118:9:
Module log_aggregator.main(in-memory /home/dz/prj/.../main.py): offset out of range, expected 12743 <= 4604
Backtrace:
   0: pyrefly::exit_on_panic::{{closure}}
   1: std::panicking::rust_panic_with_hook
   2: std::panicking::begin_panic_handler::{{closure}}
   3: std::sys::backtrace::__rust_end_short_backtrace
   4: rust_begin_unwind
   5: core::panicking::panic_fmt
   6: pyrefly::module::module_info::ModuleInfo::source_range
   7: pyrefly::error::collector::ErrorCollector::add
   8: pyrefly::solver::solver::Solver::error
   9: pyrefly::alt::callable::<impl pyrefly::alt::answers::AnswersSolver<Ans>>::callable_infer_params
  10: pyrefly::alt::callable::<impl pyrefly::alt::answers::AnswersSolver<Ans>>::callable_infer
  11: pyrefly::alt::call::<impl pyrefly::alt::answers::AnswersSolver<Ans>>::call_overloads
  12: pyrefly::alt::call::<impl pyrefly::alt::answers::AnswersSolver<Ans>>::call_infer
  13: pyrefly::alt::attr::<impl pyrefly::alt::answers::AnswersSolver<Ans>>::resolve_get_access
  14: pyrefly::alt::attr::<impl pyrefly::alt::answers::AnswersSolver<Ans>>::completions
  15: pyrefly::state::lsp::<impl pyrefly::state::state::Transaction>::completion
  16: pyrefly::commands::lsp::Server::process_lsp_message
  17: pyrefly::commands::lsp::Args::run
  18: pyrefly::run_command::{{closure}}
  19: pyrefly::main::{{closure}}
  20: tokio::runtime::runtime::Runtime::block_on
  21: pyrefly::main
  22: std::sys::backtrace::__rust_begin_short_backtrace
  23: std::rt::lang_start::{{closure}}
  24: std::rt::lang_start_internal
  25: main
  26: __libc_start_call_main
  27: __libc_start_main@GLIBC_2.2.5
  28: _start

[Error - 9:29:59 AM] The Pyrefly language server server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.

dzakarov avatar May 06 '25 08:05 dzakarov

Woah that's an interesting error message. Are you seeing that when you run a type check from CLI (pyrefly check [-c <your config>])?

Also, what were you doing when you got that? It looks like it might have been a completion event, so maybe on an unsaved file. Are you able to reproduce this consistently, and if so, could you share the file that you're seeing the issue with?

connernilsen avatar May 06 '25 19:05 connernilsen

No I do not see the error message when I manually run uv run pyrefly check

uv run pyrefly -V
pyrefly 0.14.0

And I don't see any errors I reported earlier now.

ps -aef | grep pyre
dz        193231       1  0 11:32 tty2     00:00:00 /home/dz/.vscode/extensions/meta.pyrefly-0.14.0-linux-x64/bin/release/pyrefly lsp
dz        194734  194615  1 11:32 tty2     00:00:06 /home/dz/.vscode/extensions/meta.pyrefly-0.14.0-linux-x64/bin/release/pyrefly lsp
dz        223528    8447  0 11:37 pts/0    00:00:00 grep pyre

dzakarov avatar May 07 '25 10:05 dzakarov

Ok got it, it's likely going to be a hard to reproduce bug, so we'll continue keeping an eye on it for now. Let us know any other information you can about what you were doing and the file you were working on if you see it happen again.

Otherwise, are module imports now working in VSCode, or are you still seeing issues with that?

connernilsen avatar May 08 '25 16:05 connernilsen

@dzakarov are you still seeing this issue after updating to the latest version of the IDE extension?

lolpack avatar May 20 '25 14:05 lolpack

I'm going to close this for now, but feel free to reopen or create a new issue if you run into the problem again @dzakarov

connernilsen avatar Jun 17 '25 17:06 connernilsen