vscode.py
vscode.py copied to clipboard
Get current open file/project
Is there a way through the extension to get the filename and path to the currently open file or project in the editor? Something like pathlib.Path.cwd
doesn't work if the user navigates to a different project within VSCode
I believe there's ActiveTextEditor.document
to get the currently opened text document
Currently, the Python script you write has the default file path set to the home directory. In #25 I mentioned I have created a fox for this, and I plan on opening a PR for it. Maybe @CodeWithSwastik can comment on this. My approach to implementing this is to grab the vscode workspace directory in JavaScript and pass it in as an input argument to the Python script. From there, the Python script sets the working directory to the vscode workspace directory.
active_text_editor = await ctx.window.active_text_editor
file_name = active_text_editor.document.fileName