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

Open File Autorefresh doesn't work in WSL when file in local directory is modified through WSL executable and file is already open. #114878

Closed
Diego1149 opened this issue Jan 25, 2021 · 3 comments
Assignees

Comments

@Diego1149
Copy link

Diego1149 commented Jan 25, 2021

  • VSCode Version: 1.52.1
  • OS Version: Windows_NT x64 10.0.19041

Steps to Reproduce:

My workflow is simple I have 2 files open at the same time (one in the left and one in the right), the one in the left is a CPP file, I press F5 to build and run it, then I expect an output file (the one in the right) to be automatically updated with the results. However this doesn't work when I run the program in WSL and the output file is in the local directory instead of WSL. If the output file is inside of the WSL directory instead of my local directory it works fine.

image

  1. Configure WSL 2 (https://docs.microsoft.com/en-us/windows/wsl/install-win10), I'm using Ubuntu 20.04 LTS
  2. Open Ubuntu terminal and go to your local folder: cs /mnt/c/PathToYourFileInYourLocalComputer
    For example for mine: cd /mnt/c/Users/Diego1149/Documents/Programs
  3. Open VSCode from the Ubuntu terminal in my local folder: "code ."
  4. Setup environment as showed in previous picture (I'm in Source, press F5 and expect to see the results in output reflected as soon as the program is done running, but it doesn't auto refresh the file.

Setting up the environment should be very quick and simple:
Instal C/C++ extension.

Override ".vscode/tasks.json" file with the following:
{ "type": "shell", "label": "C/C++: g++ build active file", "command": "/usr/bin/g++", "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true } }

Override ".vscode/launch.json", with the following:
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "g++ - Build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": ["USE_IO_FILES"], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "C/C++: g++ build active file", "miDebuggerPath": "/usr/bin/gdb" } ] }

Create a folder inside of the main folder you opened (in my case Programs/Subfolder) and add 3 files:
Source.cpp
`#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define INF 1000000000
#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define FORC(cont, it)
for (decltype((cont).begin()) it = (cont).begin(); it != (cont).end(); it++)
#define pb push_back
#define _
if (argc == 2 && ((string)argv[1]) == "USE_IO_FILES")
freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout);

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector vi;
typedef vector vii;
typedef vector vvi;
typedef tree<int, // key
null_type, // value
less, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;
/*
How to use ordered_set:
ordered_set X;
X.insert(1);
X.find_by_order(1); // This gives an iterator.
X.order_of_key(-5); // Lower bound, 0 based position.
*/

int main(int argc, char *argv[]) {
_;
printf("Modify this string and press F5, output file should update automatically, but it doesn't.");
return 0;
}
`
in.txt (this can be left empty, just drag and drop it to the right of Source)
out.txt (this can be left empty, just drag and drop it to the right of Source and below in.txt)

Does this issue occur when all extensions are disabled?: I didn't try since I see WSL is an extension, however only extensions I have are: "Remote - WSL" and "C/C++"

Some more details: If I reopen the output file it has the right contents, also if I do "File: Revert File" on the output file the contents get updated. Also if I have the output file in the same window as Source and I click on it it gets updated to have the right contents, this seems to only happen if they are on different partitions of the screen.

@aeschli
Copy link
Contributor

aeschli commented Jan 25, 2021

duplicate of microsoft/vscode-remote-release#3959

@aeschli aeschli closed this as completed Jan 25, 2021
@Diego1149
Copy link
Author

Got closed as a duplicate; however, when I installed insiders version (1.54) with WSL extension 0.54.0 it still doesn't update automatically, I still need to alt+tab out and into it.

@aeschli
Copy link
Contributor

aeschli commented Apr 22, 2021

At the core of this are the missing file events in WSL from mounted drives. microsoft/WSL#4739
We tried to work around it in microsoft/vscode-remote-release#3959, but this causing performance issues.
We will wait for improvments in WSL.

Closing in favor of the WSL issue: microsoft/WSL#4739

@aeschli aeschli closed this as completed Apr 22, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jun 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants