NilsJPWerner / autoDocstring

VSCode extension that generates docstrings for python files
MIT License
664 stars 161 forks source link

Remote server does not load custom file paths correctly! #291

Open McfhHolmes0 opened 3 days ago

McfhHolmes0 commented 3 days ago

Describe the bug

My daily development work is done by connecting to a remote server via Remote-ssh under Windows 10.

I defined a custom template and specified the path:

  "autoDocstring.customTemplatePath": "C:\\Users\\user\\.vscode\\custom-extensions-config\\njpwerner.autodocstring-templates\\google-custom.mustache",

This is set up to develop under Windows without any problems, but when I'm connecting to a remote server("Ubuntu 22.04.5 LTS"), I'm unable to find this .mustache template file. The error is following:

[ERROR 13:45:39.990] Error: ENOENT: no such file or directory, open '/user/Bob/projects/demo/C:\Users\McfhHolmes\.vscode\custom-extensions-config\njpwerner.autodocstring-templates\google-custom.mustache'
    at getCustomTemplate <autoDocstring>/out/docstring/get_template.js:17:34
    at AutoDocstring.getTemplate <autoDocstring>/out/generate_docstring.js:56:53
    at AutoDocstring.generateDocstringSnippet <autoDocstring>/out/generate_docstring.js:35:80
    at AutoDocstring.generateDocstring <autoDocstring>/out/generate_docstring.js:23:39
    at  <autoDocstring>/out/extension.js:16:3

One solution would be to place the template files under the project folder and use relative paths, but then a copy of the template file would have to be stored under each project folder. Is there any solution that will make it easy for me to develop either under windows or through remote connection to the server.

Versions:

McfhHolmes0 commented 1 day ago

This issue has been resolved!

The Vscode settings file is divided into local user configuration and remote server configuration. The remote server(Linux) configuration is usually located in ~/.vscode-server/data/Machine/settings.json.

The ~ here refers to your Linux home directory. For example, my linux username is bob, so my home directory is /home/bob. Then the path above means: /home/bob/.vscode-server/data/Machine/settings.json.

Note that if you are the root user, then your home directory is /root.

So you only need to set the custom configuration file path in this file. For example, my configuration file path is:/home/bob/.vscode-server/custom-extensions-config/njpwerner.autodocstring-templates/google-custom.mustache. I just need to set the path in the above mentioned remote server's setting.json file to add a line of configuration:

  "autoDocstring.customTemplatePath": "/home/bob/.vscode-server/custom-extensions-config/njpwerner.autodocstring-templates/google-custom.mustache",

Then the template file on the remote server will be loaded correctly. Note that the home directory /home/bob cannot be replaced by ~ here. Otherwise, the template path will not be recognized correctly!