Conversation
Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>
get_cwd() to resolve all file-related VS Code variables
|
Originated from #260 (comment) (@rchiodo) |
| If no document is available, falls back to the workspace root. | ||
|
|
||
| Examples of supported patterns: ``${fileDirname}``, ``${fileDirname}/subdir``. | ||
| Resolves the following VS Code file-related variable substitutions when |
There was a problem hiding this comment.
Should there be a unit test for all of these?
There was a problem hiding this comment.
@copilot Generate unit tests to check that the replacements actually work. Remember this repo is a bootstrapper, so try to keep it simple and straight to the point.
There was a problem hiding this comment.
Added 17 unit tests in src/test/python_tests/test_get_cwd.py (commit 0e48096). A conftest.py stubs out the heavy LSP dependencies so lsp_server can be imported in a plain pytest run. The tests cover every variable (${file}, ${fileBasename}, ${fileBasenameNoExtension}, ${fileExtname}, ${fileDirname}, ${fileDirnameBasename}, ${relativeFile}, ${relativeFileDirname}, ${fileWorkspaceFolder}), composite patterns, fallback-to-workspace-root when no document is available, and unchanged passthrough for plain paths.
Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>
Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>
get_cwd() to resolve all file-related VS Code variablesget_cwd() variable substitution
get_cwd() variable substitutionget_cwd() variable substitution
Applies changes from: - microsoft/vscode-python-tools-extension-template#262 (get_cwd variable substitution) - microsoft/vscode-python-tools-extension-template#260 (cwd setting - lsp_server.py portion) Updates get_cwd() in bundled/tool/lsp_server.py to support all VS Code file-related variable substitutions: ${file}, ${fileBasename}, ${fileBasenameNoExtension}, ${fileExtname}, ${fileDirname}, ${fileDirnameBasename}, ${relativeFile}, ${relativeFileDirname}, ${fileWorkspaceFolder}. Replaces the previous equality-based checks with substring replacement, allowing variables to be embedded inside longer paths (e.g. ${fileDirname}/subdir). Preserves the mypy-specific ${nearestConfig} behaviour. Fixes the dmypy (no-document) path to correctly return a plain cwd value rather than always falling back to workspaceFS. Adds src/test/python_tests/test_get_cwd.py with unit tests covering all variables, composite patterns, no-document fallbacks, and the mypy-specific ${nearestConfig} option. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Applies changes from upstream template PRs: - microsoft/vscode-python-tools-extension-template#260 (cwd setting - already applied) - microsoft/vscode-python-tools-extension-template#262 (get_cwd variable substitution) Expands get_cwd() to resolve nine VS Code file-related variables: ${file}, ${fileBasename}, ${fileBasenameNoExtension}, ${fileExtname}, ${fileDirname}, ${fileDirnameBasename}, ${relativeFile}, ${relativeFileDirname}, ${fileWorkspaceFolder}. Adds 17 unit tests covering every variable, composite patterns, multi-variable strings, and no-document fallback behaviour. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sync changes from upstream template PRs: - microsoft/vscode-python-tools-extension-template#260 (Add configurable cwd setting) - microsoft/vscode-python-tools-extension-template#262 (get_cwd() variable substitution) Expands get_cwd() to support 9 VS Code file-related variable substitutions: ${file}, ${fileBasename}, ${fileBasenameNoExtension}, ${fileExtname}, ${fileDirname}, ${fileDirnameBasename}, ${relativeFile}, ${relativeFileDirname}, ${fileWorkspaceFolder}. Also adds unit tests for get_cwd() helper. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ution
- Add `${namespace}.cwd` to checkIfConfigurationChanged in settings.ts
(from microsoft/vscode-python-tools-extension-template#260)
- Update get_cwd() in lsp_server.py to support full VS Code variable
substitution (9 file-related variables) instead of exact-match only
(from microsoft/vscode-python-tools-extension-template#262)
- Add unit tests for get_cwd() helper (test_get_cwd.py)
(from microsoft/vscode-python-tools-extension-template#262)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…le substitution Syncs changes from: - microsoft/vscode-python-tools-extension-template#260 (Add configurable cwd setting) - microsoft/vscode-python-tools-extension-template#262 (get_cwd() variable substitution) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Sync get_cwd() variable substitution from template Applies changes from: - microsoft/vscode-python-tools-extension-template#262 (get_cwd variable substitution) - microsoft/vscode-python-tools-extension-template#260 (cwd setting - lsp_server.py portion) Updates get_cwd() in bundled/tool/lsp_server.py to support all VS Code file-related variable substitutions: ${file}, ${fileBasename}, ${fileBasenameNoExtension}, ${fileExtname}, ${fileDirname}, ${fileDirnameBasename}, ${relativeFile}, ${relativeFileDirname}, ${fileWorkspaceFolder}. Replaces the previous equality-based checks with substring replacement, allowing variables to be embedded inside longer paths (e.g. ${fileDirname}/subdir). Preserves the mypy-specific ${nearestConfig} behaviour. Fixes the dmypy (no-document) path to correctly return a plain cwd value rather than always falling back to workspaceFS. Adds src/test/python_tests/test_get_cwd.py with unit tests covering all variables, composite patterns, no-document fallbacks, and the mypy-specific ${nearestConfig} option. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix _MockLS stub missing window_log_message and LogMessageParams in test_get_cwd.py (#445) * Initial plan * Fix _MockLS missing window_log_message and LogMessageParams kwargs in test_get_cwd.py Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com> * Fix linting issues in test_get_cwd.py (flake8 E302, black formatting) Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com> --------- Co-authored-by: GitHub Copilot <copilot@github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
get_cwd()gained support for nine VS Code file-related variables but had no tests. Adds 17 focused unit tests covering every variable, composite patterns, multi-variable strings, and no-document fallback behaviour.Changes
src/test/python_tests/test_get_cwd.py— new self-contained test file; includes a_setup_mocks()helper that stubs out the bundled LSP dependencies (pygls,lsprotocol,lsp_jsonrpc,lsp_utils) at module level solsp_servercan be imported without the full VS Code extension environment. Noconftest.pyneeded.Original prompt
This pull request was created from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.