Skip to content
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

Cannot resolve the configuration path in settings.json #627

Closed
ArcticOc opened this issue Oct 7, 2024 · 15 comments
Closed

Cannot resolve the configuration path in settings.json #627

ArcticOc opened this issue Oct 7, 2024 · 15 comments

Comments

@ArcticOc
Copy link

ArcticOc commented Oct 7, 2024

Hi,

The ruff extension could not resolve the configuration path set in the settings.json suddenly.

"ruff.nativeServer": "on",
"ruff.configuration": "$HOME/.config/pyproject.toml",

During the initialization of ruff, the following error appeared:
Error while resolving settings from workspace /. Please refer to the logs for more details.

Here is the log.

2024-10-07 15:47:39.080 [info] Name: Ruff
2024-10-07 15:47:39.080 [info] Module: ruff
2024-10-07 15:47:39.080 [info] Python extension loading
2024-10-07 15:47:39.080 [info] Waiting for interpreter from python extension.
2024-10-07 15:47:39.080 [info] Python extension loaded
2024-10-07 15:47:39.080 [info] Using interpreter: /Users/craig/micromamba/envs/Research/bin/python
2024-10-07 15:47:39.150 [info] Using environment executable: /opt/homebrew/bin/ruff
2024-10-07 15:47:39.158 [info] Found Ruff 0.6.9 at /opt/homebrew/bin/ruff
2024-10-07 15:47:39.158 [info] Server run command: /opt/homebrew/bin/ruff server
2024-10-07 15:47:39.158 [info] Server: Start requested.
2024-10-07 15:47:40.447 [info] warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `System/Volumes/Data/Users/craig/micromamba/envs/Research/lib/python3.12/site-packages/pandas/pyproject.toml`:
  - 'ignore' -> 'lint.ignore'
  - 'select' -> 'lint.select'
  - 'typing-modules' -> 'lint.typing-modules'
  - 'unfixable' -> 'lint.unfixable'
  - 'per-file-ignores' -> 'lint.per-file-ignores'
warning: `PGH001` has been remapped to `S307`.

2024-10-07 15:47:40.512 [info] warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `Users/craig/micromamba/envs/Research/lib/python3.12/site-packages/pandas/pyproject.toml`:
  - 'ignore' -> 'lint.ignore'
  - 'select' -> 'lint.select'
  - 'typing-modules' -> 'lint.typing-modules'
  - 'unfixable' -> 'lint.unfixable'
  - 'per-file-ignores' -> 'lint.per-file-ignores'

Version

Ruff: 0.6.6 (v2024.50.0)
VSCode: 1.94

@dhruvmanila
Copy link
Member

Can you provide the logs using the following VS Code settings?

{
	"ruff.trace.server": "messages",
	"ruff.logLevel": "debug"
}

@dhruvmanila
Copy link
Member

During the initialization of ruff, the following error appeared: Error while resolving settings from workspace /. Please refer to the logs for more details.

Have you opened the editor in the system root directory? If so, then the extension would traverse the entire system to collect all the configuration that are present in the nested directories and it could happen that one or the other configuration file is invalid.

@ArcticOc
Copy link
Author

ArcticOc commented Oct 8, 2024

Can you provide the logs using the following VS Code settings?

{
	"ruff.trace.server": "messages",
	"ruff.logLevel": "debug"
}

I think I get it. When opening a single file instead of a folder, Ruff cannot find the workspace and can only use workspace /, which causes an error. But when opening a folder, there is no problem.

2024-10-08 17:19:07.605 [info] [Trace - 5:19:07 PM]    0.000051083s  WARN main ruff_server::server: No workspace(s) were provided during initialization. Using the current working directory as a default workspace...

2024-10-08 17:19:07.605 [info] [Trace - 5:19:07 PM]    0.000541417s  WARN main ruff_server::server: No workspace settings found for file:///

@ffisc
Copy link

ffisc commented Oct 8, 2024

Same issue here. Interestingly, I tried reverting to previous versions of the extension but the problem is also there.

@dhruvmanila
Copy link
Member

When opening a single file instead of a folder, Ruff cannot find the workspace and can only use workspace /, which causes an error. But when opening a folder, there is no problem.

This is not exactly true. The client is responsible for providing the workspace, so in your case, the client wasn't able to find any workspace. This leads to Ruff using the current working directory as the default workspace which in your case seems to be the system root directory (/).

Can you provide the log messages after turning them on to diagnose the error notification that you received?

Same issue here. Interestingly, I tried reverting to previous versions of the extension but the problem is also there.

@ffisc Please provide any log messages if possible to help diagnose the issue.

@ArcticOc
Copy link
Author

ArcticOc commented Oct 8, 2024

This is not exactly true. The client is responsible for providing the workspace, so in your case, the client wasn't able to find any workspace. This leads to Ruff using the current working directory as the default workspace which in your case seems to be the system root directory (/).

However, when I open the folder containing the file, it finds the correct workspace and works fine.

Here is the entire log.

log
2024-10-08 17:19:07.404 [info] Name: Ruff
2024-10-08 17:19:07.404 [info] Module: ruff
2024-10-08 17:19:07.404 [info] Python extension loading
2024-10-08 17:19:07.404 [info] Waiting for interpreter from python extension.
2024-10-08 17:19:07.437 [info] Python extension loaded
2024-10-08 17:19:07.440 [info] Using interpreter: /Users/craig/micromamba/envs/Research/bin/python
2024-10-08 17:19:07.578 [info] Using environment executable: /opt/homebrew/bin/ruff
2024-10-08 17:19:07.589 [info] Found Ruff 0.6.9 at /opt/homebrew/bin/ruff
2024-10-08 17:19:07.589 [info] Server run command: /opt/homebrew/bin/ruff server
2024-10-08 17:19:07.589 [info] Server: Start requested.
2024-10-08 17:19:07.601 [info] [Trace - 5:19:07 PM] Sending request 'initialize - (0)'.
2024-10-08 17:19:07.602 [info] [Trace - 5:19:07 PM] Received response 'initialize - (0)' in 2ms.
2024-10-08 17:19:07.602 [info] [Trace - 5:19:07 PM] Sending notification 'initialized'.
2024-10-08 17:19:07.605 [info] [Trace - 5:19:07 PM] Sending notification 'textDocument/didOpen'.
2024-10-08 17:19:07.605 [info] [Trace - 5:19:07 PM] Sending request 'textDocument/diagnostic - (1)'.
2024-10-08 17:19:07.605 [info] [Trace - 5:19:07 PM]    0.000051083s  WARN main ruff_server::server: No workspace(s) were provided during initialization. Using the current working directory as a default workspace...

2024-10-08 17:19:07.605 [info] [Trace - 5:19:07 PM]    0.000541417s  WARN main ruff_server::server: No workspace settings found for file:///

2024-10-08 17:19:07.658 [info] [Trace - 5:19:07 PM]    0.055370083s DEBUG ThreadId(13) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /Volumes/Repo/Novel Utilities/.git

2024-10-08 17:19:07.663 [info] [Trace - 5:19:07 PM]    0.060454000s DEBUG ThreadId(13) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /Volumes/Repo/CV/.git

2024-10-08 17:19:07.680 [info] [Trace - 5:19:07 PM]    0.061193667s DEBUG ThreadId(09) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Volumes/Repo/Novel Utilities/.git

2024-10-08 17:19:07.680 [info] [Trace - 5:19:07 PM]    0.061716083s DEBUG ThreadId(09) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Volumes/Repo/CV/.git

2024-10-08 17:19:07.680 [info] [Trace - 5:19:07 PM]    0.064608292s DEBUG ThreadId(12) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /usr/share/httpd/build

2024-10-08 17:19:07.750 [info] [Trace - 5:19:07 PM]    0.146139625s DEBUG ThreadId(10) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /Applications/Slack.app/Contents/Resources/app.asar.unpacked/node_modules

2024-10-08 17:19:07.789 [info] [Trace - 5:19:07 PM]    0.146288667s DEBUG ThreadId(10) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /Applications/Slack.app/Contents/Resources/app.asar.unpacked/dist

2024-10-08 17:19:07.890 [info] [Trace - 5:19:07 PM]    0.212185625s DEBUG ThreadId(12) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /usr/share/vim/vim90/import/dist

2024-10-08 17:19:07.905 [info] [Trace - 5:19:07 PM]    0.213851708s DEBUG ThreadId(12) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /usr/share/vim/vim90/autoload/dist

2024-10-08 17:19:07.906 [info] [Trace - 5:19:07 PM]    0.215170583s DEBUG ThreadId(12) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /usr/share/vim/vim90/pack/dist

2024-10-08 17:19:07.908 [info] [Trace - 5:19:07 PM]    0.243216375s DEBUG ThreadId(07) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Applications/Slack.app/Contents/Resources/app.asar.unpacked/node_modules

2024-10-08 17:19:07.908 [info] [Trace - 5:19:07 PM]    0.243259083s DEBUG ThreadId(07) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Applications/Slack.app/Contents/Resources/app.asar.unpacked/dist

2024-10-08 17:19:07.908 [info] [Trace - 5:19:07 PM]    0.246850625s DEBUG ThreadId(13) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/venv

2024-10-08 17:19:07.910 [info] [Trace - 5:19:07 PM]    0.298163958s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/redhat.vscode-yaml-1.15.0/node_modules

2024-10-08 17:19:07.912 [info] [Trace - 5:19:07 PM]    0.298269208s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/redhat.vscode-yaml-1.15.0/dist

2024-10-08 17:19:07.922 [info] [Trace - 5:19:07 PM]    0.312313500s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/github.remotehub-0.64.0/dist

2024-10-08 17:19:07.930 [info] [Trace - 5:19:07 PM]    0.318190500s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ms-vscode.remote-explorer-0.4.3/build

2024-10-08 17:19:07.933 [info] [Trace - 5:19:07 PM]    0.321519917s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ms-vscode.remote-explorer-0.4.3/dist

2024-10-08 17:19:07.933 [info] [Trace - 5:19:07 PM]    0.323522542s DEBUG ThreadId(04) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/Research/Paper/.git

2024-10-08 17:19:07.936 [info] [Trace - 5:19:07 PM]    0.327700875s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ms-toolsai.vscode-jupyter-powertoys-0.1.1/build

2024-10-08 17:19:07.936 [info] [Trace - 5:19:07 PM]    0.332256417s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/brandonkirbyson.vscode-animations-2.0.4/dist

2024-10-08 17:19:07.940 [info] [Trace - 5:19:07 PM]    0.335455917s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/zhuangtongfa.material-theme-3.17.5/build

2024-10-08 17:19:07.941 [info] [Trace - 5:19:07 PM]    0.335854833s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/zhuangtongfa.material-theme-3.17.5/node_modules

2024-10-08 17:19:07.950 [info] [Trace - 5:19:07 PM]    0.340798917s DEBUG ThreadId(13) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages/pip/_internal/operations/build

2024-10-08 17:19:08.052 [info] [Trace - 5:19:08 PM]    0.448139708s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/bierner.markdown-preview-github-styles-2.1.0/build

2024-10-08 17:19:08.054 [info] [Trace - 5:19:08 PM]    0.450247625s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/bierner.markdown-preview-github-styles-2.1.0/dist

2024-10-08 17:19:08.065 [info] [Trace - 5:19:08 PM]    0.456169042s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/robertz.code-snapshot-0.2.1/node_modules

2024-10-08 17:19:08.087 [info] [Trace - 5:19:08 PM]    0.477712708s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ms-vscode.cpptools-1.21.6-darwin-arm64/dist

2024-10-08 17:19:08.088 [info] [Trace - 5:19:08 PM]    0.480263208s DEBUG ThreadId(09) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /Applications/Obsidian.app/Contents/Resources/app.asar.unpacked/node_modules

2024-10-08 17:19:08.089 [info] [Trace - 5:19:08 PM]    0.484746583s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ms-vscode-remote.remote-ssh-edit-0.87.0/build

2024-10-08 17:19:08.586 [info] [Trace - 5:19:08 PM]    0.501499917s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ms-toolsai.jupyter-2024.9.1-darwin-arm64/dist

2024-10-08 17:19:08.603 [info] [Trace - 5:19:08 PM]    0.507281208s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/haaleo.timing-2.7.2/dist

2024-10-08 17:19:08.618 [info] [Trace - 5:19:08 PM]    0.509051958s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ms-python.vscode-pylance-2024.10.1/dist

2024-10-08 17:19:08.630 [info] [Trace - 5:19:08 PM]    0.512702875s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/formulahendry.code-runner-0.12.2/node_modules

2024-10-08 17:19:08.634 [info] [Trace - 5:19:08 PM]    0.520166583s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/eamodio.gitlens-15.6.0/dist

2024-10-08 17:19:08.638 [info] [Trace - 5:19:08 PM] Sending notification '$/setTrace'.
2024-10-08 17:19:08.638 [info] [Trace - 5:19:08 PM]    0.521200292s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/psioniq.psi-header-1.23.1/node_modules

2024-10-08 17:19:08.639 [info] [Trace - 5:19:08 PM]    0.523063208s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ms-vscode.hexeditor-1.10.0/node_modules

2024-10-08 17:19:08.639 [info] [Trace - 5:19:08 PM]    0.523137667s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ms-vscode.hexeditor-1.10.0/dist

2024-10-08 17:19:08.791 [info] [Trace - 5:19:08 PM]    0.527756792s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/github.copilot-1.236.0/dist

2024-10-08 17:19:08.792 [info] [Trace - 5:19:08 PM]    0.599551083s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ms-python.python-2024.16.0-darwin-arm64/python_files/lib/jedilsp/jedi/third_party/typeshed/stdlib/3/venv

2024-10-08 17:19:08.793 [info] [Trace - 5:19:08 PM]    0.674728375s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ms-python.python-2024.16.0-darwin-arm64/dist

2024-10-08 17:19:08.794 [info] [Trace - 5:19:08 PM]    0.676383375s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ms-python.python-2024.16.0-darwin-arm64/out/client/node_modules

2024-10-08 17:19:08.794 [info] [Trace - 5:19:08 PM]    0.679328292s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ms-toolsai.jupyter-renderers-1.0.19/out/node_modules

2024-10-08 17:19:08.794 [info] [Trace - 5:19:08 PM]    0.683586542s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/christian-kohler.path-intellisense-2.9.0/build

2024-10-08 17:19:08.795 [info] [Trace - 5:19:08 PM]    0.683830875s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/christian-kohler.path-intellisense-2.9.0/node_modules

2024-10-08 17:19:08.795 [info] [Trace - 5:19:08 PM]    0.694477292s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ms-vscode-remote.remote-ssh-0.115.0/build

2024-10-08 17:19:08.795 [info] [Trace - 5:19:08 PM]    0.705330542s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ivhernandez.vscode-plist-0.1.3/node_modules

2024-10-08 17:19:08.795 [info] [Trace - 5:19:08 PM]    0.706173458s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ivhernandez.vscode-plist-0.1.3/dist

2024-10-08 17:19:08.795 [info] [Trace - 5:19:08 PM]    0.711564250s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `extend-exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/charliermarsh.ruff-2024.50.0-darwin-arm64/bundled/libs

2024-10-08 17:19:08.796 [info] [Trace - 5:19:08 PM]    0.711624292s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/charliermarsh.ruff-2024.50.0-darwin-arm64/dist

2024-10-08 17:19:08.796 [info] [Trace - 5:19:08 PM]    0.715589167s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/jock.svg-1.5.4/client/out/codicons/dist

2024-10-08 17:19:08.796 [info] [Trace - 5:19:08 PM]    0.720285958s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/usernamehw.errorlens-3.20.0/dist

2024-10-08 17:19:08.796 [info] [Trace - 5:19:08 PM]    0.721747500s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/be5invis.vscode-custom-css-7.3.1/node_modules

2024-10-08 17:19:08.796 [info] [Trace - 5:19:08 PM]    0.723867417s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/alefragnani.bookmarks-13.5.0/dist

2024-10-08 17:19:08.796 [info] [Trace - 5:19:08 PM]    0.728372875s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/saoudrizwan.claude-dev-1.9.7/webview-ui/build

2024-10-08 17:19:08.797 [info] [Trace - 5:19:08 PM]    0.728575583s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/saoudrizwan.claude-dev-1.9.7/node_modules

2024-10-08 17:19:08.797 [info] [Trace - 5:19:08 PM]    0.728729375s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/saoudrizwan.claude-dev-1.9.7/dist

2024-10-08 17:19:08.798 [info] [Trace - 5:19:08 PM]    0.731381708s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ms-vscode-remote.remote-wsl-0.88.4/dist

2024-10-08 17:19:08.798 [info] [Trace - 5:19:08 PM]    0.733181458s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/mhutchie.git-graph-1.30.0/node_modules

2024-10-08 17:19:08.798 [info] [Trace - 5:19:08 PM]    0.735168250s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ms-toolsai.jupyter-keymap-1.1.2/build

2024-10-08 17:19:08.798 [info] [Trace - 5:19:08 PM]    0.811995833s DEBUG ThreadId(08) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /Applications/Termius.app/Contents/Resources/app.asar.unpacked/node_modules

2024-10-08 17:19:08.798 [info] [Trace - 5:19:08 PM]    0.920150125s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/valentjn.vscode-ltex-13.1.0/dist

2024-10-08 17:19:08.798 [info] [Trace - 5:19:08 PM]    0.921680875s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ms-vscode.remote-repositories-0.42.0/dist

2024-10-08 17:19:08.798 [info] [Trace - 5:19:08 PM]    0.924769042s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/mechatroner.rainbow-csv-3.12.0/dist

2024-10-08 17:19:08.798 [info] [Trace - 5:19:08 PM]    0.942403375s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/ms-python.debugpy-2024.10.0-darwin-arm64/dist

2024-10-08 17:19:08.798 [info] [Trace - 5:19:08 PM]    0.983308500s DEBUG ThreadId(08) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /Applications/TeX/TeX Live Utility.app/Contents/Frameworks/Python.framework/Versions/3.9/lib/python3.9/venv

2024-10-08 17:19:08.798 [info] [Trace - 5:19:08 PM]    0.984234875s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/james-yu.latex-workshop-10.5.0/node_modules

2024-10-08 17:19:08.798 [info] [Trace - 5:19:08 PM]    1.016070333s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/github.copilot-chat-0.21.0/dist

2024-10-08 17:19:08.798 [info] [Trace - 5:19:08 PM]    1.017714208s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/.vscode/extensions/chouzz.vscode-better-align-1.4.2/dist

2024-10-08 17:19:08.798 [info] [Trace - 5:19:08 PM]    1.104754833s DEBUG ThreadId(08) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /Applications/TeX/TeX Live Utility.app/Contents/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_internal/operations/build

2024-10-08 17:19:08.798 [info] [Trace - 5:19:08 PM]    1.152612417s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/micromamba/envs/Research/share/zoneinfo/build

2024-10-08 17:19:08.798 [info] [Trace - 5:19:08 PM]    1.183919667s DEBUG ThreadId(05) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /System/Volumes/Data/Users/craig/micromamba/envs/Research/lib/python3.12/venv

2024-10-08 17:19:08.810 [info] warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `System/Volumes/Data/Users/craig/micromamba/envs/Research/lib/python3.12/site-packages/pandas/pyproject.toml`:
  - 'ignore' -> 'lint.ignore'
  - 'select' -> 'lint.select'
  - 'typing-modules' -> 'lint.typing-modules'
  - 'unfixable' -> 'lint.unfixable'
  - 'per-file-ignores' -> 'lint.per-file-ignores'

2024-10-08 17:19:08.811 [info] warning: `PGH001` has been remapped to `S307`.

@dhruvmanila
Copy link
Member

dhruvmanila commented Oct 8, 2024

However, when I open the folder containing the file, it finds the correct workspace and works fine.

I think that is an expected behavior.

Thanks for providing the logs although I don't see any error messages in it. As mentioned, I think you were opening the editor in the system root directory which means it would take some time to load the extension completely because it tries to index the entire root directory. I'm really curious to know why the error is occurring although I'm mostly sure that one of the config on your system is invalid :)

@MichaReiser
Copy link
Member

I can reproduce this behavior.

  • Close all VS code instances
  • Navigate to a file in finder
  • Open the python file with VS Code

Ruff ends up indexing the entire root partition. This is unlikely what the user wanted. I don't have a good suggestion on what the extension should do in this case. What are other extensions doing in this case?

@dhruvmanila
Copy link
Member

And that file is in the root directory, right? This is related to astral-sh/ruff#11366 then. One solution would be to not index the workspace if there's none provided aka using the server for single file. Any nested configs shouldn't affect the output for this specific file.

@MichaReiser
Copy link
Member

No. The file is in a subdirectory of my home directory

@ffisc
Copy link

ffisc commented Oct 9, 2024

@ffisc Please provide any log messages if possible to help diagnose the issue.

Sure, here:

2024-10-09 13:01:55.788 [info] Name: Ruff
2024-10-09 13:01:55.788 [info] Module: ruff
2024-10-09 13:01:55.788 [info] Python extension loading
2024-10-09 13:01:55.788 [info] Waiting for interpreter from python extension.
2024-10-09 13:01:56.175 [info] Python extension loaded
2024-10-09 13:01:56.190 [info] Using interpreter: /Users/ffi/dev/benchmarks/foo/bar/.venv/bin/python
2024-10-09 13:01:56.206 [info] Using bundled executable: /Users/ff/.vscode-insiders/extensions/charliermarsh.ruff-2024.50.0-darwin-arm64/bundled/libs/bin/ruff
2024-10-09 13:01:56.318 [info] Resolved 'ruff.nativeServer: auto' to use the native server
2024-10-09 13:01:56.321 [info] Found Ruff 0.6.6 at /Users/ff/.vscode-insiders/extensions/charliermarsh.ruff-2024.50.0-darwin-arm64/bundled/libs/bin/ruff
2024-10-09 13:01:56.321 [info] Server run command: /Users/ff/.vscode-insiders/extensions/charliermarsh.ruff-2024.50.0-darwin-arm64/bundled/libs/bin/ruff server
2024-10-09 13:01:56.322 [info] Server: Start requested.

@dhruvmanila
Copy link
Member

Ruff ends up indexing the entire root partition. This is unlikely what the user wanted. I don't have a good suggestion on what the extension should do in this case. What are other extensions doing in this case?

Yeah, it seems that the client doesn't provide any workspace path during initialization and thus Ruff uses the current working directory but that turns out to be the root path (/) which I guess is happening because VS Code was opened using a file directly.

@dhruvmanila
Copy link
Member

So, there must be some config file that's invalid as per the ruff executable that's chosen to run the server. I can see some error messages for the logs on my system.

@dhruvmanila
Copy link
Member

What are other extensions doing in this case?

I'll need to look into what other language servers are doing but one potential solution is #627 (comment). We would avoid traversing into the current working directory if the server is running in single-file mode. A single-file mode is basically when there's no workspace provided by the client. So, the indexer would still climb up as well as look into the current working directory for any config but it won't traverse it.

@dhruvmanila
Copy link
Member

I'm moving this discussion over to astral-sh/ruff#11366 as that's basically the root cause for it.

dhruvmanila added a commit to astral-sh/ruff that referenced this issue Oct 18, 2024
## Summary

This PR updates the language server to avoid indexing the workspace for
single-file mode.

**What's a single-file mode?**

When a user opens the file directly in an editor, and not the folder
that represents the workspace, the editor usually can't determine the
workspace root. This means that during initializing the server, the
`workspaceFolders` field will be empty / nil.

Now, in this case, the server defaults to using the current working
directory which is a reasonable default assuming that the directory
would point to the one where this open file is present. This would allow
the server to index the directory itself for any config file, if
present.

It turns out that in VS Code the current working directory in the above
scenario is the system root directory `/` and so the server will try to
index the entire root directory which would take a lot of time. This is
the issue as described in
astral-sh/ruff-vscode#627. To reproduce, refer
astral-sh/ruff-vscode#627 (comment).

This PR updates the indexer to avoid traversing the workspace to read
any config file that might be present. The first commit
(8dd2a31)
refactors the initialization and introduces two structs `Workspaces` and
`Workspace`. The latter struct includes a field to determine whether
it's the default workspace. The second commit
(61fc39b)
utilizes this field to avoid traversing.

Closes: #11366

## Editor behavior

This is to document the behavior as seen in different editors. The test
scenario used has the following directory tree structure:
```
.
├── nested
│   ├── nested.py
│   └── pyproject.toml
└── test.py
```

where, the contents of the files are:

**test.py**
```py
import os
```

**nested/nested.py**
```py
import os
import math
```

**nested/pyproject.toml**
```toml
[tool.ruff.lint]
select = ["I"]
```

Steps:
1. Open `test.py` directly in the editor
2. Validate that it raises the `F401` violation
3. Open `nested/nested.py` in the same editor instance
4. This file would raise only `I001` if the `nested/pyproject.toml` was
indexed

### VS Code

When (1) is done from above, the current working directory is `/` which
means the server will try to index the entire system to build up the
settings index. This will include the `nested/pyproject.toml` file as
well. This leads to bad user experience because the user would need to
wait for minutes for the server to finish indexing.

This PR avoids that by not traversing the workspace directory in
single-file mode. But, in VS Code, this means that per (4), the file
wouldn't raise `I001` but only raise two `F401` violations because the
`nested/pyproject.toml` was never resolved.

One solution here would be to fix this in the extension itself where we
would detect this scenario and pass in the workspace directory that is
the one containing this open file in (1) above.

### Neovim

**tl;dr** it works as expected because the client considers the presence
of certain files (depending on the server) as the root of the workspace.
For Ruff, they are `pyproject.toml`, `ruff.toml`, and `.ruff.toml`. This
means that the client notifies us as the user moves between single-file
mode and workspace mode.

#13770 (comment)

### Helix

Same as Neovim, additional context in
#13770 (comment)

### Sublime Text

**tl;dr** It works similar to VS Code except that the current working
directory of the current process is different and thus the config file
is never read. So, the behavior remains unchanged with this PR.

#13770 (comment)

### Zed

Zed seems to be starting a separate language server instance for each
file when the editor is running in a single-file mode even though all
files have been opened in a single editor instance.

(Separated the logs into sections separated by a single blank line
indicating 3 different server instances that the editor started for 3
files.)

```
   0.000053375s  INFO main ruff_server::server: No workspace settings found for file:///Users/dhruv/projects/ruff-temp, using default settings
   0.009448792s  INFO main ruff_server::session::index: Registering workspace: /Users/dhruv/projects/ruff-temp
   0.009906334s DEBUG ruff:main ruff_server::resolve: Included path via `include`: /Users/dhruv/projects/ruff-temp/test.py
   0.011775917s  INFO ruff:main ruff_server::server: Configuration file watcher successfully registered

   0.000060583s  INFO main ruff_server::server: No workspace settings found for file:///Users/dhruv/projects/ruff-temp/nested, using default settings
   0.010387125s  INFO main ruff_server::session::index: Registering workspace: /Users/dhruv/projects/ruff-temp/nested
   0.011061875s DEBUG ruff:main ruff_server::resolve: Included path via `include`: /Users/dhruv/projects/ruff-temp/nested/nested.py
   0.011545208s  INFO ruff:main ruff_server::server: Configuration file watcher successfully registered

   0.000059125s  INFO main ruff_server::server: No workspace settings found for file:///Users/dhruv/projects/ruff-temp/nested, using default settings
   0.010857583s  INFO main ruff_server::session::index: Registering workspace: /Users/dhruv/projects/ruff-temp/nested
   0.011428958s DEBUG ruff:main ruff_server::resolve: Included path via `include`: /Users/dhruv/projects/ruff-temp/nested/other.py
   0.011893792s  INFO ruff:main ruff_server::server: Configuration file watcher successfully registered
```

## Test Plan

When using the `ruff` server from this PR, we see that the server starts
quickly as seen in the logs. Next, when I switch to the release binary,
it starts indexing the root directory.

For more details, refer to the "Editor Behavior" section above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants