microsoft / PTVS

Python Tools for Visual Studio
https://aka.ms/PTVS
Apache License 2.0
2.53k stars 675 forks source link

Stub paths setting not observed #7092

Closed eclazi closed 11 months ago

eclazi commented 2 years ago

Describe the bug Setting stubs / search paths does not pass on to pylance server

Steps to Reproduce

  1. Open visual studio 2022 settings
  2. Navigate to Python > Analysis
  3. Set log level to Trace
  4. Add path to stubs path
  5. See in pylance server log Warning: (29816) stubPath typings is not a valid directory. even though "typings" is not set in the stub path

Expected behavior pylance should observe analysis options

Additional context and screenshots

Info: (29816) Pylance language server 2022.3.3 (pyright dd7420c5) starting
Info: (29816) Server root directory: c:\program files\microsoft visual studio\2022\professional\common7\ide\extensions\microsoft\python\core\pylance\dist
Error: (29816) Error reading settings: TypeError: Cannot read properties of null (reading '0')
Info: (29816) No pyproject.toml file found.
Warning: (29816) stubPath typings is not a valid directory.
Info: (29816) Assuming Python platform Windows
Info: (29816) Searching for source files
Info: (29816) No source files found.
Info: (29816) Background analysis(1) root directory: c:\program files\microsoft visual studio\2022\professional\common7\ide\extensions\microsoft\python\core\pylance\dist
Info: (29816) Background analysis(1) started

image

Configuration information (If you are providing a diagnostics file (see below), skip this section)

Microsoft Visual Studio Professional 2022
Version 17.2.6
VisualStudio.17.Release/17.2.6+32630.192
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Professional

Visual C++ 2022   00476-80000-00000-AA237
Microsoft Visual C++ 2022

ASP.NET and Web Tools 2019   17.2.393.26812
ASP.NET and Web Tools 2019

Azure App Service Tools v3.0.0   17.2.393.26812
Azure App Service Tools v3.0.0

C# Tools   4.2.0-4.22281.5+8d3180e5f00d42f0f0295165f756f368f0cbfa44
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Child Process Debugging Power Tool   1.0
Power tool to add child process debugging to Visual Studio.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter   17.0.22089.1
Provides tools for finding, instantiating and customizing templates in cookiecutter format.

Linux Core Dump Debugging   1.0.9.32408
Enables debugging of Linux core dumps.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

NuGet Package Manager   6.2.1
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Python - Django support   17.0.22089.1
Provides templates and integration for the Django web framework.

Python - Profiling support   17.0.22089.1
Profiling support for Python projects.

Python with Pylance   17.0.22089.1
Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Test Adapter for Boost.Test   1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test.  The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test   1.0
Enables Visual Studio's testing tools with unit tests written for Google Test.  The use terms and Third Party Notices are available in the extension installation directory.

TypeScript Tools   17.0.10418.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   4.2.0-4.22281.5+8d3180e5f00d42f0f0295165f756f368f0cbfa44
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual C++ for Cross Platform Mobile Development (iOS)   17.0.32408.312
Visual C++ for Cross Platform Mobile Development (iOS)

Visual C++ for Linux Development   1.0.9.32408
Visual C++ for Linux Development

Visual F# Tools   17.1.0-beta.22329.1+702b8e77f5fbfe21e6743324c1750503e02f182d
Microsoft Visual F# Tools

Visual Studio IntelliCode   2.2
AI-assisted development for Visual Studio.

Diagnostics file The diagnostics file contains information such as the Python version, environments, loaded assemblies, configuration options, etc. This file makes it easier for us to reproduce and fix bugs, so we would really appreciate it if you could provide it to us. This file can be generated by going to Tools->Options->Python->Diagnostics. You can attach the file to this issue or email it to us at ptvshelp@microsoft.com. If you email it, please add a link to this issue.

This is not an option in VS 2022

excubo-jg commented 2 years ago

I am seeing the same pattern of Error reading settings and stubPath being invalid - irrespective of the path being set or not Microsoft Visual Studio Community 2022 (64-bit) - Preview Version 17.3.0 Preview 5.0

Info: (16028) Pylance language server 2022.6.30 (pyright 212d1465) starting Info: (16028) Server root directory: c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist Log: Notebook support: Legacy Error: (16028) Error reading settings: TypeError: Cannot read properties of undefined (reading 'variableTypes') Info: (16028) No pyproject.toml file found. Warning: (16028) stubPath typings is not a valid directory.

StellaHuang95 commented 2 years ago

Thanks for reporting this. It will be fixed in the next version.

excubo-jg commented 2 years ago

I have updated to Version 17.4.0 Preview 2.0 and I am still seeing the warning "stubPath typings is not a valid directory". It appears regardless of whether Stubs Path is being set or not in Python analysis.

StellaHuang95 commented 2 years ago

@excubo-jg Thanks, did the warning show up before or after you set the stubs path? In other words, if you set the stubs path, clear the pylance server log, reload the project, do you still see the warning?

StellaHuang95 commented 2 years ago

Going to close this out. If the issue still persists, please reopen with the information requested. Thanks.😊

excubo-jg commented 2 years ago

Apologies, I never received a notification about the request for information but received one now...

Setting a stubs path (copied the path from file manager so there should be not typos) immediately triggers the warning message in the log: Warning: (12020) stubPath typings is not a valid directory.

The message will continue to appear after closing and reloading the project

excubo-jg commented 2 years ago

This is odd: I have deleted the entry in the stubs path but I'm still receiving the warning when restarting the project image

StellaHuang95 commented 2 years ago

This is odd: I have deleted the entry in the stubs path but I'm still receiving the warning when restarting the project image

That's expected behavior, the stubs path is defaulted to "typings" when the input is blank and passed to the language server. You can ignore that warning. 😊

excubo-jg commented 2 years ago

Well, there is a directory "typings"... I think there shouldn't be a warning when the input is left blank and the default resolves to a valid directory.

excubo-jg commented 2 years ago

Checked with another project without a typings-directory and there I also see the warning. That project is a trivial one and there is no need for additional typing information. Isn't it a bit too strong to issue a warning in that case? A missing pyproject.toml-file triggers one info entry when the project is loaded but no (further) warning messages

StellaHuang95 commented 1 year ago

@excubo-jg The warning is just intended to be informational and help diagnose potential problems. You can ignore it if you are not using a stub path.

For this one, could you provide repro steps? Where is your typings directory? I wasn't able to repro this if the directory exists.

Well, there is a directory "typings"... I think there shouldn't be a warning when the input is left blank and the default resolves to a valid directory.

excubo-jg commented 1 year ago

If the warning is informational I'd expect it to cause an Info-entry. To issue a warning is too strong imo

I played around and I have 3 repos all of which throw the warning in spite of a typings-directory being present. They all exhibit the same behavior:

directory typings does not exist -> Warning: (18008) stubPath c:\Users\Admin\Documents\Visual Studio 2022\Projects\projectname\typings is not a valid directory.

directory typings exists -> Warning: (11100) stubPath typings is not a valid directory.

directory typings gets created while the project is open in VS: output general: Error: Unknown change event received at e.update (c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist\pyright-internal\node_modules\vscode-languageserver-textdocument\lib\esm\main.js:92:23) at Object.update (c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist\pyright-internal\node_modules\vscode-languageserver-textdocument\lib\esm\main.js:181:22) at t.SourceFile.setClientVersion (c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist\pyright-internal\src\analyzer\sourceFile.ts:676:49) at L.setFileOpened (c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist\pyright-internal\src\analyzer\program.ts:361:35) at _0x4635b7.setFileOpened (c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist\pyright-internal\src\analyzer\backgroundAnalysisProgram.ts:101:23) at C.setFileOpened (c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist\pyright-internal\src\analyzer\service.ts:310:41) at _0x45764f.onDidOpenTextDocument (c:\program files\microsoft visual studio\2022\preview\common7\ide\extensions\microsoft\python\core\pylance\dist\pyright-internal\src\languageServerBase.ts:1247:35)

and output - pylance disappears

StellaHuang95 commented 11 months ago

Hello! While we'd love to address all issues, our resources are limited, making it challenging to manage a large number of open requests. Pylance has recently made some improvements to stubPath such that if python.analysis.stubPath is unset, omit it from the configuration response rather than sending the default value ("typings"). This way the server knows that it's not set (rather than explicitly set to "typings") and can skip showing the warning in that case. This might have resolved your issue. If the problem persists and falls within the scope of PTVS, could you please open a new issue with:

  1. Detailed reproduction steps with expected and actual behavior.
  2. Any sample code.
  3. Go to Tools -> Python -> Analysis, set your Log Level to Trace, and share the logs.

Thanks for your understanding and assistance!