Inconsistent type inference in LSP and CLI for external search paths

Open
#4,987 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python, rust

Research direction

Reproduce the mismatch with the supplied project structure, pyproject.toml, test.py, and Zed settings.json, comparing pyrefly check with the LSP result. Start by tracing workspace configuration and external search-path handling in the LSP and CLI entry points. Done means both paths infer datetime for now().

Written by the indexing model from the issue text.

Description

language-server
Describe the Bug

I have a file system structure like this:

./
├── extproject/
│   └── src/
│       └── extpkg/
│           ├── __init__.py
│           └── date.py
└── project/
    ├── .zed/
    │   └── settings.json
    ├── pyproject.toml
    └── test.py

project is the project I'm working on with Zed, and extproject is a third-party project that my project depends on.

When running pyrefly as a language server in Zed, the return type of now() is inferred as "Unknown":
Image

However, on the command line it is recognized correctly:

$ pyrefly check
 INFO Checking project configured at `/home/jan/Downloads/pyrefly-test/project/pyproject.toml`
 INFO revealed type: datetime [reveal-type]
 --> test.py:5:12
  |
5 | reveal_type(test)
  |            ------
 INFO 0 errors

$ pyrefly --version
pyrefly 1.3.1

project/test.py:

from typing_extensions import reveal_type
from extpkg.date import now

test = now()
reveal_type(test)

project/pyproject.toml:

[tool.pyrefly]
search-path = ["../extproject/src"]
preset = "default"

projects/.zed/settings.json:

{
  "languages": {
    "Python": {
      "language_servers": [
        "pyrefly",
        "!ruff",
        "!ty",
        "!basedpyright",
        "!pyright",
        "!pylsp",
        "...",
      ],
    },
  },
}

exproject/src/extpkg/date.py:

from datetime import datetime
from zoneinfo import ZoneInfo

def now():
    return datetime.now(ZoneInfo("UTC"))

I've also attached the files here.
pyrefly-test.zip

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

Zed 1.20.2
Commit: 7c451e694f3c52ee0aeb01d7e28b5fa18cd0ad2f
Version: 1.20.2+stable.360.7c451e694f3c52ee0aeb01d7e28b5fa18cd0ad2f

Pyrefly extension version 0.0.1

LSP log
 INFO Language server processed event `DidChangeConfiguration` in 0.00s (0.01s waiting)
 INFO File /home/jan/Downloads/pyrefly-test/project/test.py opened, prepare to validate open files.
 INFO Ran task on sourcedb_queue heavy task queue. Queue time: 0.00, task time: 0.00
 INFO Published 1 diagnostics for file:///home/jan/Downloads/pyrefly-test/project/test.py
 INFO Validated open files and committed transaction.
 INFO Language server processed event `DidOpenTextDocument` in 0.09s (0.01s waiting)
 INFO Language server processed event `LspResponse` in 0.00s (0.09s waiting)
 INFO Could not decode `LspConfig` from Null, skipping client configuration request: invalid type: null, expected struct LspConfig.
 INFO Client configuration applied to workspace: Some(Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/home/jan/Downloads/pyrefly-test/project", query: None, fragment: None })
 INFO Could not decode `LspConfig` from Null, skipping client configuration request: invalid type: null, expected struct LspConfig.
 INFO Client configuration applied to workspace: None
 INFO Language server processed event `LspResponse` in 0.00s (0.09s waiting)
 INFO Could not decode `LspConfig` from Null, skipping client configuration request: invalid type: null, expected struct LspConfig.
 INFO Client configuration applied to workspace: Some(Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/home/jan/Downloads/pyrefly-test/project", query: None, fragment: None })
 INFO Could not decode `LspConfig` from Null, skipping client configuration request: invalid type: null, expected struct LspConfig.
 INFO Client configuration applied to workspace: None
 INFO Language server processed event `LspResponse` in 0.00s (0.09s waiting)
 INFO Handling non-canceled request textDocument/inlayHint (2)
 INFO Language server processed event `LspRequest(textDocument/inlayHint)` in 0.00s (0.05s waiting)
 INFO Handling non-canceled request textDocument/semanticTokens/full (3)
 INFO Language server processed event `LspRequest(textDocument/semanticTokens/full)` in 0.00s (0.01s waiting)
 INFO Publishing workspace diagnostics for 1 non-open files.
 INFO Ran task on recheck_queue heavy task queue. Queue time: 0.00, task time: 0.00
 INFO Populating all files in the config (File("/home/jan/Downloads/pyrefly-test/project/pyproject.toml")).
 INFO Language server processed event `LspResponse` in 0.00s (0.00s waiting)
 INFO Language server processed event `LspResponse` in 0.00s (0.00s waiting)
 INFO Language server processed event `LspResponse` in 0.00s (0.00s waiting)
 INFO Prepare to check 1 files.
 INFO Populated all files in the project path, prepare to recheck open files.
 INFO Ran task on recheck_queue heavy task queue. Queue time: 0.00, task time: 0.00
 INFO Populating up to 2000 files in the workspace ("/home/jan/Downloads/pyrefly-test/project").
 INFO Published 1 diagnostics for file:///home/jan/Downloads/pyrefly-test/project/test.py
 INFO Validated open files and committed transaction.
 INFO Publishing workspace diagnostics for 1 non-open files.
 INFO Language server processed event `RecheckFinished` in 0.00s (0.00s waiting)
 INFO Prepare to check 1 files.
 INFO Populated all files in the workspace, prepare to recheck open files.
 INFO Ran task on recheck_queue heavy task queue. Queue time: 0.00, task time: 0.00
 INFO Publishing workspace diagnostics for 1 non-open files.
 INFO Ran task on recheck_queue heavy task queue. Queue time: 0.00, task time: 0.00
 INFO Published 1 diagnostics for file:///home/jan/Downloads/pyrefly-test/project/test.py
 INFO Validated open files and committed transaction.
 INFO Publishing workspace diagnostics for 1 non-open files.
 INFO Language server processed event `RecheckFinished` in 0.00s (0.00s waiting)
 INFO Language server processed event `LspResponse` in 0.00s (0.00s waiting)
 INFO Language server processed event `LspResponse` in 0.00s (0.00s waiting)
 INFO Language server processed event `LspResponse` in 0.00s (0.00s waiting)
 INFO Language server processed event `LspResponse` in 0.00s (0.00s waiting)
 INFO Language server processed event `LspResponse` in 0.00s (0.00s waiting)
 INFO Handling non-canceled request textDocument/documentHighlight (4)
 INFO Language server processed event `LspRequest(textDocument/documentHighlight)` in 0.00s (0.00s waiting)
 INFO Handling non-canceled request textDocument/foldingRange (5)
 INFO Language server processed event `LspRequest(textDocument/foldingRange)` in 0.00s (0.00s waiting)
 INFO Handling non-canceled request textDocument/codeLens (6)
 INFO Language server processed event `LspRequest(textDocument/codeLens)` in 0.00s (0.00s waiting)
 INFO Handling non-canceled request textDocument/semanticTokens/full (7)
 INFO Language server processed event `LspRequest(textDocument/semanticTokens/full)` in 0.00s (0.00s waiting)
 INFO Handling non-canceled request textDocument/codeAction (8)
 INFO Language server processed event `LspRequest(textDocument/codeAction)` in 0.00s (0.00s waiting)
Dominant language
Rust
Stars
7k
Forks
521
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from facebook/pyrefly

All issues in facebook/pyrefly

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.