microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.5k stars 28.65k forks source link

Array examples make it look like you need to include brackets #227604

Open nickeldan opened 1 week ago

nickeldan commented 1 week ago

I'm using VSCode 1.92.2 and version v2024.2.0 of the Black Formatter extension. My operating system is macOS (Sonoma 14.6.1). I'm working in a venv virtual environment of Python 3.8.18. I've confirmed that black is installed in my virtual environment.

I noticed that black wasn't being run whenever I saved my files. Looking into, the logs, I saw

2024-09-04 11:24:17.764 [info] [Trace - 11:24:17 AM] Sending request 'textDocument/formatting - (1)'.
2024-09-04 11:24:17.793 [info] [Trace - 11:24:17 AM] Received notification 'window/logMessage'.
2024-09-04 11:24:17.793 [info] ["/Users/user/environments/myproject/bin/black"] -l 110 --preview --stdin-filename /Users/user/Projects/myproject/tests/client/client.py -
2024-09-04 11:24:17.793 [info] [Trace - 11:24:17 AM] Received notification 'window/logMessage'.
2024-09-04 11:24:17.793 [info] CWD Server: /Users/user/Projects/myproject
2024-09-04 11:24:17.796 [info] Failed to handle request 1 textDocument/formatting DocumentFormattingParams(text_document=TextDocumentIdentifier(uri='file:///Users/user/Projects/myprojecttests/client/client.py'), options=FormattingOptions(tab_size=4, insert_spaces=True, trim_trailing_whitespace=None, insert_final_newline=None, trim_final_newlines=None), work_done_token=None)
Traceback (most recent call last):
  File "/Users/user/.vscode/extensions/ms-python.black-formatter-2024.2.0/bundled/libs/pygls/protocol/json_rpc.py", line 266, in _handle_request
    self._execute_request(msg_id, handler, params)
  File "/Users/user/.vscode/extensions/ms-python.black-formatter-2024.2.0/bundled/libs/pygls/protocol/json_rpc.py", line 188, in _execute_request
    self._send_response(msg_id, handler(params))
  File "/Users/user/.vscode/extensions/ms-python.black-formatter-2024.2.0/bundled/tool/lsp_server.py", line 109, in formatting
    return _formatting_helper(document)
  File "/Users/user/.vscode/extensions/ms-python.black-formatter-2024.2.0/bundled/tool/lsp_server.py", line 176, in _formatting_helper
    result = _run_tool_on_document(document, use_stdin=True, extra_args=extra_args)
  File "/Users/user/.vscode/extensions/ms-python.black-formatter-2024.2.0/bundled/tool/lsp_server.py", line 496, in _run_tool_on_document
    result = utils.run_path(
  File "/Users/user/.vscode/extensions/ms-python.black-formatter-2024.2.0/bundled/tool/lsp_utils.py", line 181, in run_path
    with subprocess.Popen(
  File "/Users/user/.pyenv/versions/3.8.18/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Users/user/.pyenv/versions/3.8.18/lib/python3.8/subprocess.py", line 1720, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '["black"]'

Following the instructions in the extension's settings, I had set the black-formatter path to ["black"]:

Screenshot 2024-09-04 at 11 35 54 AM

I tried making the path absolute (["/Users/user/environments/myproject/bin/black"]) but got the same error. Finally, I removed the brackets and the quotes (black) and it worked.

karthiknadig commented 1 week ago

This is expected, you should not be including brackets with the path. The examples show how it should look like in the settings.json.

Moving this to VS Code to improve how this looks to users. This is example contribution for settings in package json.

karthiknadig commented 5 days ago

@aiday-mar This is a settings rendering issue. Can this be assigned to someone who owns that?

aiday-mar commented 5 days ago

Hi yes thanks @karthiknadig I'll have a look at the working areas md file. I think @sandy081 owns the settings? Assigning to you, let me know if you don't own this code.

sandy081 commented 5 days ago

@rzhao271 owns the settings editor, moving it to him.

rzhao271 commented 4 days ago

This issue seems specific to the fact that the examples in the setting's description are for users modifying a settings.json file directly. I'd rather not change the behaviour of the Settings editor to automatically adjust literal ["textHere"] entries to textHere.   @karthiknadig I'm thinking that we can either remove the examples for conciseness or add a separate set of examples for Settings editor users.

karthiknadig commented 3 days ago

For array and object types maybe, we can remove the examples for editor users.