Skip to content

Inconsistent type inference in LSP and CLI for external search paths #4987

Description

@janlarres

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    language-serverIssues specific to our IDE integration rather than type checking

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions