Skip to content

Add "Default" LS setting, which picks between Jedi/Pylance - #16155

Merged
Jake Bailey (jakebailey) merged 8 commits into
microsoft:mainfrom
jakebailey:new-default-ls-setting
May 5, 2021
Merged

Add "Default" LS setting, which picks between Jedi/Pylance#16155
Jake Bailey (jakebailey) merged 8 commits into
microsoft:mainfrom
jakebailey:new-default-ls-setting

Conversation

@jakebailey

@jakebailey Jake Bailey (jakebailey) commented May 5, 2021

Copy link
Copy Markdown
Member

Resending #16139.

For #16157.

Adds a new "Default" setting, which implies Pylance when Pylance installed, otherwise uses jedi (plus/minus the LSP experiment).

For https://github.com/microsoft/vscode-python-internalbacklog/issues/176.

@karrtikr Kartik Raj (karrtikr) left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check my comments here #16139 (review). Also, shouldn't we add a news entry?

@jakebailey

Copy link
Copy Markdown
Member Author

Yes, getting there... :)

@jakebailey

Copy link
Copy Markdown
Member Author

I still need to check a few things:

  • Deal with python 2
  • Make sure that the "install pylance detection" thing works

Comment thread src/client/activation/activationService.ts
const serverType = configurationService.getSettings(this.resource).languageServer;
if (serverType === LanguageServerType.Node) {
return 'shared-ls';
return LanguageServerType.Node;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key is compared against the server type in some conditions (bad!), but this will at least make things not break in those cases.

Comment thread src/client/activation/activationService.ts
@jakebailey
Jake Bailey (jakebailey) merged commit c41bfb3 into microsoft:main May 5, 2021
@jakebailey
Jake Bailey (jakebailey) deleted the new-default-ls-setting branch May 5, 2021 21:58
@kamilturek

Copy link
Copy Markdown

Jake Bailey (@jakebailey) I feel really bad about the idea of forcing Python 2 developers to use Jedi engine. Is there any chance to leave out this?

@jakebailey

Copy link
Copy Markdown
Member Author

See #16204, but Pylance wasn't really intended to work with Python 2 in the first place.

@kamilturek

Copy link
Copy Markdown

It would be perfect to bring your idea to life. Until this point, Pylance gave me really great experience with Python 2.

@tschaub

Copy link
Copy Markdown

I know this isn't the right place for support, but I'm curious if there is a way to tell what language server is being used when "Default" is selected. I have struggled with and reconfigured VS Code's language server for python for a while, and I'm not sure if some other existing configuration I have is making it so "Default" resolves to Pylance, Jedi, or something else.

@jakebailey

Copy link
Copy Markdown
Member Author

The "Python" logs print a message for the chosen language server, like:

Starting Pylance language server

Or

Starting Jedi language support

Or similar. Additionally, the "Python Language Server" output window will have logs specific to the language server chosen, or not exist at all (because "Jedi" is technically not a language server).

@tschaub

Tim Schaub (tschaub) commented May 11, 2021

Copy link
Copy Markdown

Thanks. Seeing "Starting Jedi Python language engine." Now trying to figure out why...

Update: I found that I had to add "python.jediEnabled": false to my settings. There was previously no property here related to Jedi, but it continued to be loaded by default until I added this setting. After restarting with "python.jediEnabled": false, I get Pylance by default.

I also notice in my logs "User belongs to experiment group 'pythonJediLSP'" - not sure if this is causing issues, and I can't see a place where I would be opted in to this experiment.

@jakebailey

Copy link
Copy Markdown
Member Author

Update: I found that I had to add "python.jediEnabled": false to my settings. There was previously no property here related to Jedi, but it continued to be loaded by default until I added this setting. After restarting with "python.jediEnabled": false, I get Pylance by default.

What version of the Python extension are you using? That setting hasn't been used anywhere in months.

@tschaub

Tim Schaub (tschaub) commented May 14, 2021

Copy link
Copy Markdown

What version of the Python extension are you using? That setting hasn't been used anywhere in months.

Id: ms-python.python
Version: 2021.5.842923320

Id: ms-python.vscode-pylance
Version: 2021.5.2

It looks like setting "python.jediEnabled": false wasn't a permanent fix. Here's the most recent log:

User belongs to experiment group 'pythonaa'
User belongs to experiment group 'pythonJediLSP'
User belongs to experiment group 'pythonDiscoveryModuleWithoutWatcher'
User belongs to experiment group 'pythonTensorboardExperiment'
User belongs to experiment group 'PythonPyTorchProfiler'
User belongs to experiment group 'ShowExtensionSurveyPrompt - control'
User belongs to experiment group 'CollectLSRequestTiming - control'
User belongs to experiment group 'CollectNodeLSRequestTiming - experiment'
User belongs to experiment group 'DeprecatePythonPath - control'
> pyenv root
> python3.7 ~/.vscode-server/extensions/ms-python.python-2021.5.842923320/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> conda --version
> python3.6 ~/.vscode-server/extensions/ms-python.python-2021.5.842923320/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3 ~/.vscode-server/extensions/ms-python.python-2021.5.842923320/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python2 ~/.vscode-server/extensions/ms-python.python-2021.5.842923320/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python ~/.vscode-server/extensions/ms-python.python-2021.5.842923320/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> /usr/bin/python ~/.vscode-server/extensions/ms-python.python-2021.5.842923320/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> conda info --json
Python interpreter path: /usr/bin/python
> pyenv root
Starting Jedi Python language engine.
> conda --version
Error 2021-05-14 21:58:56: Failed to check if file needs to be fixed [EntryNotFound (FileSystemError): Unable to read file 'vscode-remote://dev-container+2f55736572732f747363686175622f70726f6a656374732f63657374656d/root/.config/Code/User/settings.json' (Error: Unable to resolve non-existing file 'vscode-remote://dev-container+2f55736572732f747363686175622f70726f6a656374732f63657374656d/root/.config/Code/User/settings.json')
	at _handleError (/vscode/vscode-server/bin/x64/054a9295330880ed74ceaedda236253b4f39a335/out/vs/server/remoteExtensionHostProcess.js:87:156171)
	at async y.readText (/root/.vscode-server/extensions/ms-python.python-2021.5.842923320/out/client/extension.js:9:344717)
	at async p.doesFileNeedToBeFixed (/root/.vscode-server/extensions/ms-python.python-2021.5.842923320/out/client/extension.js:59:581560)
	at async /root/.vscode-server/extensions/ms-python.python-2021.5.842923320/out/client/extension.js:59:580687
	at async Promise.all (index 0)
	at async p.getFilesToBeFixed (/root/.vscode-server/extensions/ms-python.python-2021.5.842923320/out/client/extension.js:59:580633)
	at async p.updateTestSettings (/root/.vscode-server/extensions/ms-python.python-2021.5.842923320/out/client/extension.js:59:580260)] {
  code: 'FileNotFound'
}
Error 2021-05-14 21:58:56: Failed to check if file needs to be fixed [EntryNotFound (FileSystemError): Unable to read file 'vscode-remote://dev-container+2f55736572732f747363686175622f70726f6a656374732f63657374656d/cestem/.vscode/settings.json' (Error: Unable to resolve non-existing file 'vscode-remote://dev-container+2f55736572732f747363686175622f70726f6a656374732f63657374656d/cestem/.vscode/settings.json')
	at _handleError (/vscode/vscode-server/bin/x64/054a9295330880ed74ceaedda236253b4f39a335/out/vs/server/remoteExtensionHostProcess.js:87:156171)
	at async y.readText (/root/.vscode-server/extensions/ms-python.python-2021.5.842923320/out/client/extension.js:9:344717)
	at async p.doesFileNeedToBeFixed (/root/.vscode-server/extensions/ms-python.python-2021.5.842923320/out/client/extension.js:59:581560)
	at async /root/.vscode-server/extensions/ms-python.python-2021.5.842923320/out/client/extension.js:59:580687
	at async Promise.all (index 1)
	at async p.getFilesToBeFixed (/root/.vscode-server/extensions/ms-python.python-2021.5.842923320/out/client/extension.js:59:580633)
	at async p.updateTestSettings (/root/.vscode-server/extensions/ms-python.python-2021.5.842923320/out/client/extension.js:59:580260)] {
  code: 'FileNotFound'
}
> /usr/bin/python ~/.vscode-server/extensions/ms-python.python-2021.5.842923320/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /cestem -s --cache-clear
cwd: /cestem
> /usr/bin/python ~/.vscode-server/extensions/ms-python.python-2021.5.842923320/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /cestem -s --cache-clear
cwd: /cestem

Looks like I'm back to Jedi.

I'm using the Remote - Containers extension with the following devcontainer.json:

// For format details, see https://aka.ms/vscode-remote/devcontainer.json
{
	"name": "Example",
	"image": "example.com/image:local",
	"workspaceMount": "source=${localWorkspaceFolder},target=/cestem,type=bind,consistency=cached",
	"workspaceFolder": "/cestem",
	"settings": {
		"python.pythonPath": "/usr/bin/python",
		"python.testing.pytestArgs": [],
		"python.testing.unittestEnabled": false,
		"python.testing.nosetestsEnabled": false,
		"python.testing.pytestEnabled": true,
		"python.linting.flake8Enabled": false,
		"python.linting.pylintEnabled": true,
		"python.linting.pylintUseMinimalCheckers": false,
		"python.formatting.provider": "black",
		"python.jediEnabled": false,
		"files.autoSave": "afterDelay"
	},
	"extensions": [
		"ms-python.python"
	]
}

@jakebailey

Jake Bailey (jakebailey) commented May 14, 2021

Copy link
Copy Markdown
Member Author

If /usr/bin/python (what you've configured pythonPath to) is Python 2, then we'll fall back to using Jedi, as Pylance doesn't explicitly support Python 2. You can set your language server setting to Pylance explicitly to override this behavior, though. Can you try that?

@kimadeline

Copy link
Copy Markdown

If you want to opt out of the JediLSP experiment, add the following to your settings.json:

"python.experiments.optOutFrom": [
        "pythonJediLSP"
    ],

@tschaub

Copy link
Copy Markdown

When I change the Python language server to Pylance, I see that Pylance is started instead of Jedi.

/usr/bin/python is 3.8.5 in the container but is 2.7.16 on my host system. I wonder if the extension is checking the version on my host system instead of in the container.

@jakebailey

Copy link
Copy Markdown
Member Author

That I'm unsure of and would be worth a new issue (this is just a PR, after all). AFAIK, dev containers should run their extensions internally. Otherwise, I'm sure there are loads of discrepancies all over the board...

@tschaub

Copy link
Copy Markdown

I'll open a dedicated issue about it - thanks for your thoughts here.

It looks to me like this could be about the Remote – Containers extension not properly identifying the correct Python interpreter.

I notice that sometimes when I open VS Code in the container the Python version is incorrectly identified:
image

After I Python: Select Interpreter and then click the "Refresh interpreter list" button, I see that it correctly identifies /usr/bin/python as 3.8.5.

Thanks for letting me drag this off topic. Will work up a new issue at some point.

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

Labels

skip package*.json package.json and package-lock.json don't both need updating

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants