emeraldwalk / vscode-runonsave

Visual Studio Code extension to run commands whenever a file is saved.
Apache License 2.0
182 stars 57 forks source link

File editor does't always refresh after command #88

Closed pruizFocusrite closed 1 month ago

pruizFocusrite commented 6 months ago

I use VSCode v1.89.1 and RunOnSave v0.2.0, with this minimal .vscode/settings.json:

{
    "emeraldwalk.runonsave": {
        "commands": [
            {
                "match": "\\.cpp$",
                "cmd": "clang-format -i ${file}"
            }
        ]
    }
}

I have the following file tree in VSCode:

.
|-- foo.cpp
|-- src
|   |-- bar.cpp
|   |-- main
|   |   -- foobar.cpp

Saving the top-level foo.cpp formats the file and, crucially, refreshes the open editor in thte GUI (as expected).

Saving any of the .cpp files in the sub-directories also formats the file but does not refresh the display. (Trying to save again brings up the dirty file conflict resolution popup). Bringing another file forefront in the GUI, and then the problematic file back again does refresh it from disk.

As a workaround, I also tried "cmd": "clang-format -i ${file}; code -r ${file}" but that made no difference.

bmingles commented 1 month ago

@pruizFocusrite the extension doesn’t actually do anything to refresh editors. Reason for this, is "run on save" is not necessarily focused on formatting and doesn't really have a way to know if / when a file should be refreshed. The fact that it refreshes in some cases would suggest some other formatter may be running that does refresh the editor in certain cases.

e.g. These vscode docs seem to indicate that clang-format on save is supported by the C/C++ vscode extension. https://code.visualstudio.com/docs/cpp/cpp-ide#_code-formatting .

I would expect extensions like this would refresh the editor as part of format on save functionality. You may want to make sure you don't have more than 1 extension attempting to format the file.