Skip to content

Command 'python.analysis.restartLanguageServer' already exists #13441

New issue

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

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

Already on GitHub? Sign in to your account

Closed
HadenMoore opened this issue Aug 14, 2020 · 16 comments · Fixed by #18993
Closed

Command 'python.analysis.restartLanguageServer' already exists #13441

HadenMoore opened this issue Aug 14, 2020 · 16 comments · Fixed by #18993
Labels
area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. bug Issue identified by VS Code Team member as probable bug

Comments

@HadenMoore
Copy link

HadenMoore commented Aug 14, 2020

  • Issue Type: Bug
  • Extension Name: python
  • Extension Version: 2020.8.101144
  • OS Version: Darwin x64 19.6.0
  • VSCode version: 1.48.0
{
	"messages": [],
	"activationTimes": {
		"codeLoadingTime": 966,
		"activateCallTime": 367,
		"activateResolvedTime": 2853,
		"activationReason": {
			"startup": false,
			"extensionId": {
				"value": "ms-python.python",
				"_lower": "ms-python.python"
			},
			"activationEvent": "onLanguage:python"
		}
	},
	"runtimeErrors": [
		{
			"name": "Error",
			"message": "command 'python.analysis.restartLanguageServer' already exists"
		}
	]
}
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Aug 14, 2020
@HadenMoore HadenMoore changed the title Extension ⚠️ Extension Bug Aug 14, 2020
@yousefabuz17
Copy link

yousefabuz17 commented Aug 15, 2020

Python 2020.8.101144 has many bugs, downgrade it to the one below it and everything should be fine. I issued a bug where the terminal would not accept any keyboard inputs and took me so long to realize what happened and its because python has a very recent update and downgrading it worked.

@karthiknadig karthiknadig added triage bug Issue identified by VS Code Team member as probable bug labels Aug 17, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Aug 17, 2020
@kimadeline kimadeline changed the title Extension Bug Extension Bug: command 'python.analysis.restartLanguageServer' already exists Aug 17, 2020
@kimadeline
Copy link

Hi @HadenMoore, thank you for reaching out!

Does this behaviour happen consistently, and would @yousefabuz17 downgrading suggestion work as a workaround for now?

I couldn't reproduce your issue on macOS 10.15.6, VS Code 1.48.0 and the Python extension 2020.8.101144, what is the value of the python.languageServer setting in your user settings?

Thank you!

@leonhx
Copy link

leonhx commented Sep 23, 2020

Hi @kimadeline , I can constantly reproduce this issue: firstly add multiple folders to a workspace, open a file in one folder, then switch to a file from another folder(it is the key point), then an error occurs:

Error 2020-09-23 17:04:23: Failed to activate a workspace, Class name = v, completed in 254ms, has a falsy return value, Arg 1: <Uri:/Users/xxx/Developer/xxx>, Return Value: undefined [Error: command 'python.analysis.restartLanguageServer' already exists
	at _.registerCommand (/Users/xxx/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:674:270)
	at Object.registerCommand (/Users/xxx/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:977:119)
	at s.registerCommand (/Users/xxx/.vscode/extensions/ms-python.python-2020.8.109390/out/client/extension.js:54:495185)
	at new r (/Users/xxx/.vscode/extensions/ms-python.python-2020.8.109390/out/client/extension.js:54:178371)
	at Object.t.resolveInstance (/Users/xxx/.vscode/extensions/ms-python.python-2020.8.109390/out/client/extension.js:47:265970)
	at /Users/xxx/.vscode/extensions/ms-python.python-2020.8.109390/out/client/extension.js:47:265172
	at Array.map (<anonymous>)
	at Object.t.resolveInstance (/Users/xxx/.vscode/extensions/ms-python.python-2020.8.109390/out/client/extension.js:47:265740)
	at /Users/xxx/.vscode/extensions/ms-python.python-2020.8.109390/out/client/extension.js:47:265172
	at Object.t.resolve (/Users/xxx/.vscode/extensions/ms-python.python-2020.8.109390/out/client/extension.js:47:265439)
	at /Users/xxx/.vscode/extensions/ms-python.python-2020.8.109390/out/client/extension.js:47:256520
	at e._get (/Users/xxx/.vscode/extensions/ms-python.python-2020.8.109390/out/client/extension.js:47:256286)
	at e.getTagged (/Users/xxx/.vscode/extensions/ms-python.python-2020.8.109390/out/client/extension.js:47:255088)
	at e.getNamed (/Users/xxx/.vscode/extensions/ms-python.python-2020.8.109390/out/client/extension.js:47:255180)
	at a.get (/Users/xxx/.vscode/extensions/ms-python.python-2020.8.109390/out/client/extension.js:56:1055572)
	at C.createRefCountedServer (/Users/xxx/.vscode/extensions/ms-python.python-2020.8.109390/out/client/extension.js:47:303140)
	at async C.activate (/Users/xxx/.vscode/extensions/ms-python.python-2020.8.109390/out/client/extension.js:47:301001)
	at async Promise.all (index 4)
	at async v.activateWorkspace (/Users/xxx/.vscode/extensions/ms-python.python-2020.8.109390/out/client/extension.js:47:296083)]

Version: 1.49.1
Commit: 58bb7b2331731bf72587010e943852e13e6fd3cf
Date: 2020-09-16T23:21:17.533Z (6 days ago)
Electron: 9.2.1
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Darwin x64 19.6.0
ms-python: v2020.8.109390

@kimadeline
Copy link

Hi @leonhx,

Do you have a sample repo I could use to reproduce the issue, because I did not experience this issue with the steps you outlined:

multiroot

What is what is the value of the python.languageServer setting in your user settings and your workspace? Could you also copy the logs of the Python output channel?

Thanks!

@leonhx
Copy link

leonhx commented Sep 28, 2020

@kimadeline , your GIF showed exactly what I meant. In my settings, "python.languageServer": "Microsoft". My workspace has no custom settings.

Here's a more specific reproduce procedure:

After the above steps finished, the logs from Python channel are:

User belongs to experiment group 'AlwaysDisplayTestExplorer - control'
User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'ShowExtensionSurveyPrompt - enabled'
User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'PtvsdWheels37 - experiment'
User belongs to experiment group 'UseTerminalToGetActivatedEnvVars - control'
User belongs to experiment group 'AA_testing - control'
User belongs to experiment group 'LocalZMQKernel - experiment'
User belongs to experiment group 'CollectLSRequestTiming - control'
User belongs to experiment group 'CollectNodeLSRequestTiming - experiment'
User belongs to experiment group 'EnableIPyWidgets - experiment'
User belongs to experiment group 'DeprecatePythonPath - experiment'
User belongs to experiment group 'RunByLine - control'
User belongs to experiment group 'CustomEditorSupport - control'
Error 2020-09-28 16:21:51: Failed to initialize source map support in extension
User belongs to experiment group 'pythonaacf'
> conda --version
> pyenv root
> python3.7 ~/.vscode/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3.6 ~/.vscode/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3 ~/.vscode/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python2 ~/.vscode/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python ~/.vscode/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python ~/.vscode/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> conda info --json
> conda info --json
> conda info --json
> conda env list
Error 2020-09-28 16:21:53: Failed to check if file needs to be fixed [EntryNotFound (FileSystemError): Unable to read file '/Users/xxxx/Developer/github.com/ENSFM/.vscode/settings.json' (EntryNotFound (FileSystemError): Error: ENOENT: no such file or directory, open '/Users/xxxx/Developer/github.com/ENSFM/.vscode/settings.json')
	at _handleError (/Users/xxxx/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:706:74)
	at runMicrotasks (<anonymous>)
	at processTicksAndRejections (internal/process/task_queues.js:94:5)
	at async y.readText (/Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:1:498595)
	at async p.doesFileNeedToBeFixed (/Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:56:960982)
	at async /Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:56:960109
	at async Promise.all (index 1)
	at async p.getFilesToBeFixed (/Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:56:960055)
	at async p.updateTestSettings (/Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:56:959682)] {
  code: 'FileNotFound',
  name: 'EntryNotFound (FileSystemError)'
}
> conda env list
Starting Microsoft Python language server.
Python interpreter path: /usr/local/anaconda3/envs/kaggle/bin/python
> /usr/local/anaconda3/envs/easytf_dev/bin/python ~/.vscode/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py -c "import jupyter"
> /usr/local/anaconda3/envs/easytf_dev/bin/python ~/.vscode/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py -c "import notebook"
> /usr/local/anaconda3/envs/easytf_dev/bin/python ~/.vscode/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py jupyter kernelspec --version
Starting Microsoft Python language server.
Error 2020-09-28 16:22:25: Failed to activate a workspace, Class name = y, completed in 230ms, has a falsy return value, Arg 1: <Uri:/Users/xxxx/Developer/github.com/facebook-DLRM>, Return Value: undefined [Error: command 'python.analysis.restartLanguageServer' already exists
	at _.registerCommand (/Users/xxxx/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:674:270)
	at Object.registerCommand (/Users/xxxx/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:977:119)
	at s.registerCommand (/Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:54:373547)
	at new r (/Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:54:51397)
	at Object.t.resolveInstance (/Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:47:266184)
	at /Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:47:265386
	at Array.map (<anonymous>)
	at Object.t.resolveInstance (/Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:47:265954)
	at /Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:47:265386
	at Object.t.resolve (/Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:47:265653)
	at /Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:47:256734
	at e._get (/Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:47:256500)
	at e.getTagged (/Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:47:255302)
	at e.getNamed (/Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:47:255394)
	at a.get (/Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:56:1063072)
	at C.createRefCountedServer (/Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:47:303871)
	at async C.activate (/Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:47:301732)
	at async Promise.all (index 4)
	at async y.activateWorkspace (/Users/xxxx/.vscode/extensions/ms-python.python-2020.9.111407/out/client/extension.js:47:296814)]

Environment:

Version: 1.49.2
Commit: e5e9e69aed6e1984f7499b7af85b3d05f9a6883a
Date: 2020-09-24T16:23:52.277Z
Electron: 9.2.1
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Darwin x64 19.6.0
ms-python: v2020.9.111407

@kimadeline
Copy link

Thank you for the clarification and the repro steps @leonhx!

"python.languageServer": "Microsoft" was the missing piece, I could repro the issue with this setting, but not when using Pylance, which is a new and more performant language server we recently introduced (blog post).

You can download it from the marketplace and install it alongside the core Python extension. Because our team's development efforts have shifted to support the new language server, we'd encourage you to try it out.

@jakebailey In which repo do you want this issue to live? This is an MPLS-related bug, but the issue is with command registration, which happens in the extension.

@kimadeline kimadeline added area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. needs PR and removed info-needed Issue requires more information from poster investigating We are looking into the cause of the issue labels Sep 28, 2020
@jakebailey
Copy link
Member

jakebailey commented Sep 28, 2020

Here. The entire implementation of this command is in the core extension. These commands are unknown to any LS directly, as the core extension manages the entire lifetime of the LS. #12952

The command gets registered in the LS manager. There should only be one of those at as time depending on the LS setting choice. I'm not sure how it's possible without some violation of the injection system.

@kimadeline
Copy link

Yeah, I don't know how that happens either. Maybe something to do with multi-root workspaces and being called for each workspace?

In any case, it doesn't happen when using Pylance.

@kimadeline kimadeline changed the title Extension Bug: command 'python.analysis.restartLanguageServer' already exists Command 'python.analysis.restartLanguageServer' already exists when using MPLS Sep 28, 2020
@rchiodo
Copy link

rchiodo commented Nov 13, 2020

We get this on our smoke tests now.

https://github.com/microsoft/vscode-jupyter/runs/1398220329?check_suite_focus=true

It seems like it would happen when switching language servers if you don't restart.

@jakebailey
Copy link
Member

My patch that added this adds the command disposal, but it's likely that it's not actually getting disposed for some reason. Maybe it needs to be shoved down further so that it can only be available when the LS is running.

@kimadeline kimadeline removed their assignment Nov 16, 2020
@joyceerhl
Copy link

In the meantime maybe we could work around this in the commandRegistry by ensuring we call registerCommand once for each command? i.e. the commandRegistry would cache commands that it's already registered.

@jakebailey
Copy link
Member

The problem would be if the old command is referencing a dead LS client, and therefore does nothing. I suppose that this is rare though where you need to change a setting (and are already in a bad state) and reload, so maybe it's not a huge problem.

@joyceerhl
Copy link

joyceerhl commented Nov 18, 2020

Followed the repro steps above (set language server to 'Microsoft', cloned the two repos, opened a Python file from each). It seems like what's happening is the following:

  • ILanguageServerManager is not added as a singleton to the service container
  • When the user opens the second folder, a new instance of the ILanguageServerManager is created
  • This causes the constructor to be called twice
  • The command gets registered twice

I debugged this locally and can verify that the constructor was called twice, and that's likely the source of the duplicate command registrations. Can the ILanguageServerManager be made a singleton? If a new one really needs to be created per folder in a workspace, the command may need to be registered elsewhere.

@jakebailey
Copy link
Member

It can't be a singleton due to multi-root (one MPLS per root), but that's been broken for a while. The individual LS is what needs to be restarted, so having more than one technically breaks that down because you have to ask "which LS to restart". It's likely my implementation was too simple and needed to go and restart every running LS or something, and register the command elsewhere.

@joyceerhl
Copy link

needed to go and restart every running LS or something, and register the command elsewhere.

Yeah that makes sense, or maybe figure out which LS to restart based on the active root. In any case this error isn't fatal for our smoke tests so we don't urgently need a fix.

@mfdeveloper
Copy link

+1 @kimadeline solution about use Pylance works!! But, I think that "python.languageServer": "Microsoft" should work as well, right?

@karthiknadig karthiknadig changed the title Command 'python.analysis.restartLanguageServer' already exists when using MPLS Command 'python.analysis.restartLanguageServer' already exists Apr 29, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants