-
Notifications
You must be signed in to change notification settings - Fork 36
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
Client Black Formatter: connection to server is erroring. #280
Comments
@Il-Colombo Can you try running this from a terminal and see what is happening? If there is any issue you should see an error, otherwise it will be blank and waiting. You should be able to terminate it with |
It does not give an error and I can terminate it with ctrl+c |
Do you see anything in debug console in developer tools Help > Toggle Developer Tools ? That setting is a hidden setting, so it will look dimmed in the editor. But in the logs Output > Black Formatter, there should be few more details if the server could start up to a point where something could be extracted from the error. |
Here is the output of the console: 2023-07-31 21:26:13.784 [info] Server run command: c:\Users\utente\AppData\Local\Programs\Python\Python311\python.exe c:\Users\utente.vscode\extensions\ms-python.black-formatter-2023.4.1\bundled\tool\lsp_server.py 2023-07-31 21:26:13.784 [info] [Error - 9:26:13 PM] Client Black Formatter: connection to server is erroring. Shutting down server. |
@Il-Colombo Can you try |
My suspicion is that it is trying to load something from the environment that is incompatible, and is causing a failure that is getting not captured correctly. I am hoping running the server with this setting |
nope, still the same problem |
This is unfortunate, I don't have enough information here to diagnose. Can you share your environment details?
/cc @dbaeumer Is there any way to know why this error occurs |
Version 3.11.64 |
@Il-Colombo Where did you install the python from? The version seems weird, the latest version from python.org is 3.11.4: https://www.python.org/downloads/release/python-3114/ |
sorry mine is 3.11.4 (64 bit) |
chcp -> 437
|
@Il-Colombo I needed the output from Extension Host. From Output > Extension Host. |
@dbaeumer I have a seen a few reports of this type of issue. In some cases, for whatever reason, spawning the process manually and handing the stdio streams to LSP client works better than having LSP client launch it. Looking at the LSP client code I don't see what is going wrong, it seems to launch it normally as one would using node spawn. Is there any way we can extract details on why the stream is erroring? Like did the process exit, if so what was the exit code, or something was written to the stream that it should not have, etc. |
@karthiknadig this most of the time happens if the process can be started and then an exception occurs in the server process before it reached the code reading messages (in node for example a require statement fails). I currently don't print this to the LOG but I should. I opened microsoft/vscode-languageserver-node#1313 Feel free to provide a PR. Code will go into https:/microsoft/vscode-languageserver-node/blob/f2ff7d55464a1f58f978cb6635bd8865f050553c/client/src/node/main.ts#L1 |
@lyndseyjw A solution you can try is to point the Here is what I recommend you try: |
hi @karthiknadig ! Adding both |
I have tried everything in this thread and nothing seems to work. This has really disrupted my workflow. |
@dcgudeman You can pin the As for using this extension, If you have tried the suggestion here #280 (comment) then you need to check if any of the packages installed in the interpreter chosen to run the black server are writing to stdout. Avoid installing packages into the system python, as it can break normal operation of not only some of your projects but can break some system processes as well. |
That did fix my formatting issue but isort is still not working. Overall I am concerned with how this extension is proceeding. I don't think I have an unusual setup. Just using poetry to manage dependencies and activate the python sell to run code locally. I think these changes require a lot more QA. I spent multiple hours trying to figure out what broke. At this point I don't know how I will be productive in a python environment while using vscode. These changes have made the experience completely unbearable. |
@dcgudeman The issue stems from how VSCode and python communicate. We are working on an alternate mode of communication that does not rely on stdout. Some packages do the wrong thing of writing to You can apply the same fix to isort extension as well. There is another alternative. You can use Ruff extension, apply this fix to it once, and ruff can do import sorting similar to isort, formatting similar to black, and it implements multiple linters (pylint, flake8, pycodestyle, pydocstyle, etc). It is written in rust so it is incredibly fast. |
@karthiknadig what is the status of this issue? Has a version been released with a fix? |
A possible reason is that, you choose an environment that is not compatible with black formatter, such as pydoc3.10 or so |
I am not able to make the black formatter start! I switched between different versions, I modified the values of the preferred formatters in the settings, I specified the path of the interpreter but nothing seems to work.
I am currently using Python 3.11.64, VS code tells me that Black Formatter cannot format Python files. The Black formatter output console tells me:
2023-07-31 18:07:53.849 [info] Interpreter from setting black-formatter.interpreter: C:\Users\user\AppData\Local\Programs\Python\Python311\python.exe
2023-07-31 18:07:53.849 [info] Interpreter from setting black-formatter.interpreter: C:\Users\user\AppData\Local\Programs\Python\Python311\python.exe
2023-07-31 18:07:53.849 [info] Server run command: C:\Users\user\AppData\Local\Programs\Python\Python311\python.exe c:\Users\user.vscode\extensions\ms-python.black-formatter-2023.4.1\bundled\tool\lsp_server.py
2023-07-31 18:07:53.849 [info] Server: Start requested.
2023-07-31 18:07:53.850 [info] [Error - 6:07:53 PM] Client Black Formatter: connection to server is erroring. Shutting down server.
2023-07-31 18:07:53.850 [info] [Error - 6:07:53 PM] Stopping server failed
2023-07-31 18:07:53.850 [info] Error: Client is not running and can't be stopped. It's current state is: starting
Is there anything else I can do ?
The text was updated successfully, but these errors were encountered: