Skip to content
New issue

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

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

Already on GitHub? # to your account

Pyright does not pick up new files. #94

Closed
Fingel opened this issue Nov 5, 2021 · 16 comments
Closed

Pyright does not pick up new files. #94

Fingel opened this issue Nov 5, 2021 · 16 comments
Labels
bug Something isn't working upstream Upstream issue

Comments

@Fingel
Copy link
Contributor

Fingel commented Nov 5, 2021

I'm not sure if this is an upstream bug or not, but when I create a new Python file and then try to import something from it in a a different python file, pyright will complain about undefined imports. I have to restart lsp-pyright for them to be picked up.

@jfcherng
Copy link
Collaborator

jfcherng commented Nov 6, 2021

Iirc it's a ST core issue that there is no callback when files are created/deleted/modified by an external program. But at the same time the LSP team created a file watcher package. I am not sure what's the situation now.

@rchl
Copy link
Member

rchl commented Nov 6, 2021

What platform are you on @Fingel?

You could see if it reproduces with https://packagecontrol.io/packages/LSP-file-watcher-chokidar installed but the last time I checked, pyright had been running its own file watcher and whether LSP supported file watching didn't really matter.

If you can still reproduce with that package then fell free to create a small repro and state your node version and OS.

@jfcherng
Copy link
Collaborator

jfcherng commented Nov 6, 2021

file_watcher.mp4

Pyright doesn't seem to watch a newly created files but after installing https://packagecontrol.io/packages/LSP-file-watcher-chokidar and config it for watching .py file, Pyright works on my side.

  • Node: v16.13.0 (stable)
  • OS: Win10 x64 21H1 (19043.1320)
  • LSP-pyright config:
    {
        "file_watcher": {
            "patterns": [
                "**/*.{py,pyi}",
            ],
        },
    }

@rwols
Copy link
Member

rwols commented Nov 6, 2021

So I guess it would be nice to have that in the default config

@rchl
Copy link
Member

rchl commented Nov 6, 2021

That raises some questions though:

  • why pyright doesn't handle it itself since it's already running a file watcher?
  • why it doesn't use dynamic registration to register watchers and requires manual configuration like old servers?

Those should probably be asked in the pyright repo.

@jfcherng
Copy link
Collaborator

jfcherng commented Nov 6, 2021

When I created new_file.py, I see the following payload in VSCode (Pylance)

[Trace - 下午6:08:29] Sending notification 'workspace/didChangeWatchedFiles'.
Params: {
    "changes": [
        {
            "uri": "file:///c%3A/Users/Tester/Desktop/my_project/my_package/new_file.py",
            "type": 1
        },
        {
            "uri": "file:///c%3A/Users/Tester/Desktop/my_project/my_package",
            "type": 2
        }
    ]
}

So I think it's VSCode's responsibility (or something from the client side) to notify Pylance there is a new file to be watched?


why it doesn't use dynamic registration to register watchers and requires manual configuration like old servers?

The configuration is for LSP-file-watcher-chokidar.

@rchl
Copy link
Member

rchl commented Nov 6, 2021

So I think it's VSCode's responsibility (or something from the client side) to notify Pylance there is a new file to be watched?

The client notifies, yes, but the client is told what to notify about either through manual configuration or dynamic registration from the server.

@rchl
Copy link
Member

rchl commented Nov 6, 2021

How do you enable trace logs for pylance?

Thanks. Realized before deleting the question. :)

So in Pylance the registration is done dynamically:


[Trace - 11:46:56 AM] Received request 'client/registerCapability - (1)'.
Params: {
    "registrations": [
        {
            "id": "4a407254-aede-40aa-b2a6-1dbb7e387c8d",
            "method": "workspace/didChangeWatchedFiles",
            "registerOptions": {
                "watchers": [
                    {
                        "globPattern": "**/pyrightconfig.json",
                        "kind": 7
                    },
                    {
                        "globPattern": "**",
                        "kind": 7
                    }
                ]
            }
        }
    ]
}

It would make sense to ask on the pyright repo to change pyright to do that itself.

Though I always think that they will be hesitant to add stuff because it would take away the competitive advantage of pylance...

@rchl
Copy link
Member

rchl commented Nov 6, 2021

Ops... pyright actually registers the capability dynamically. The issue was on our side. I've made a silly mistake and reported the capability in the wrong place. Fixing in sublimelsp/LSP#1892

With the fix it will be enough to install https://packagecontrol.io/packages/LSP-file-watcher-chokidar to have things working.

@rwols
Copy link
Member

rwols commented Nov 6, 2021

I’d argue this is part of LSP functionality, not part of the “AI” competitive advantage :)

Edit: I guess never mind.

@rchl
Copy link
Member

rchl commented Nov 6, 2021

Fun fact, the ** watch pattern makes VSCode report changes to all files, even inside .git/*. On our side we filter out those most obvious non-code directories at least. I wonder why the pattern has to be so wide though.

@rchl
Copy link
Member

rchl commented Nov 6, 2021

I’d argue this is part of LSP functionality, not part of the “AI” competitive advantage :)

I still have this feeling every time I think of reporting some enhancement suggestion...

@jfcherng
Copy link
Collaborator

jfcherng commented Nov 6, 2021

With the fix it will be enough to install packagecontrol.io/packages/LSP-file-watcher-chokidar to have things working.

Do you mean we don't have to add {"file_watcher": {"patterns": ["**/*.{py,pyi}"]}} to settings since then?
I mean it's somehow already working with LSP-file-watcher-chokidar.

@rchl
Copy link
Member

rchl commented Nov 6, 2021

Yes, with the fix in place we don't need to define the file_watcher configuration manually since the server registers the watcher through a dynamic capability.

@jfcherng jfcherng added upstream Upstream issue bug Something isn't working labels Nov 6, 2021
@predragnikolic
Copy link
Member

We now have LSP-file-watcher-chokidar as a current workaround that will fix this issue.

Can we close this,
because we already have an open ticket for tracking file watcher support in Sublime Text at sublimelsp/LSP#892

@rchl
Copy link
Member

rchl commented Aug 10, 2022

I think this is addressed with chokidar package, yes. Also LSP-pyright readme was updated to mention it.

@rchl rchl closed this as completed Aug 10, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working upstream Upstream issue
Projects
None yet
Development

No branches or pull requests

5 participants