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

Saving and closing file can result in the file getting empty #50942

Closed
waitingsong opened this issue Jun 1, 2018 · 13 comments
Closed

Saving and closing file can result in the file getting empty #50942

waitingsong opened this issue Jun 1, 2018 · 13 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug candidate Issue identified as probable candidate for fixing in the next release important Issue identified as high-priority verified Verification succeeded
Milestone

Comments

@waitingsong
Copy link

Issue Type: Bug

I map shift+z+z to save and close active editor with vim plugin.
It works good with vs code version 1.20 ( VSCodeSetup-x64-1.20.1.exe), but got problem with latest version 1.23.1:

  1. open a .ts file containing some codes
  2. shortcut shift+z+z triggered
  3. active editor closed
  4. the file be zero byte

VS Code version: Code 1.23.1 (d0182c3, 2018-05-10T17:11:17.614Z)
OS version: Windows_NT x64 6.1.7601

System Info
Item Value
CPUs Intel(R) Core(TM) i5 CPU 760 @ 2.80GHz (4 x 2809)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: unavailable_software
video_decode: enabled
video_encode: enabled
vpx_decode: unavailable_software
webgl: enabled
webgl2: enabled
Memory (System) 15.97GB (5.34GB free)
Process Argv C:\Program Files\Microsoft VS Code\Code.exe D:\tt\tt\lib\index.ts
Screen Reader no
VM 67%
Extensions (2)
Extension Author (truncated) Version
vscode-language-pack-zh-hans MS- 1.23.5
vim vsc 0.12.0

config:

{
    "editor.fontSize": 18,
    "editor.wordWrap": "on",
    "telemetry.enableTelemetry": false,
    "telemetry.enableCrashReporter": false,
    "files.eol": "\n",
    "files.trimTrailingWhitespace": true,
    "vim.easymotion": false,
    "vim.incsearch": true,
    "vim.useSystemClipboard": true,
    "vim.useCtrlKeys": true,
    "vim.hlsearch": true,
    "vim.insertModeKeyBindings": [
        {
            "before": ["j","j"],
            "after": ["<Esc>"]
        }
    ],
    "vim.otherModesKeyBindingsNonRecursive": [
        {
            "before": ["<leader>","c", "c"],
            "after": ["g", "c"]
        },
        {
            "before":["<C-n>"],
            "after":[],
            "commands": [
                {
                    "command": ":nohl"
                }
            ]
        },
        {
            "before": [
                "Z",
                "Z"
            ],
            "after": [],
            "commands": [
                {
                    "command": "workbench.action.files.save",
                    "args": []
                },
                {
                    "command": "workbench.action.closeActiveEditor",
                    "args": []
                }
            ]
        },
        {
            "before": [
                "leader",
                "w"
            ],
            "after": [],
            "commands": [
                {
                    "command": "workbench.action.files.save",
                    "args": []
                }
            ]
        }
    ],
    "vim.leader": ",",
    "vim.handleKeys":{
        "<C-a>": false,
        "<C-f>": true,
		"<C-b>": true
    },
    "vim.textwidth": 160,
    "vim.history": 500,
    "workbench.colorTheme": "Visual Studio Dark",
    "typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
    "eslint.run": "onSave",
    "eslint.autoFixOnSave": true,
    "eslint.validate": [
        "javascript",
        "javascriptreact"
    ],
    "eslint.enable": true,
    "typescript.format.insertSpaceAfterTypeAssertion": true,
	  "typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,
    "editor.tabSize": 2,
    "[markdown]": {
      "files.trimTrailingWhitespace": false
    },
    "editor.renderIndentGuides": true,
    "tslint.autoFixOnSave": true,
    "editor.renderLineHighlight": "all"

}

@bpasero
Copy link
Member

bpasero commented Jun 1, 2018

@waitingsong can you clarify what kind of VIM extension you have installed?

@bpasero bpasero added the info-needed Issue requires more information from poster label Jun 1, 2018
@bpasero bpasero self-assigned this Jun 1, 2018
@waitingsong
Copy link
Author

waitingsong commented Jun 2, 2018

@bpasero
Copy link
Member

bpasero commented Jun 2, 2018

@xconverge @jpoon any hints what this command does in your extension that could cause this?

@xconverge
Copy link
Contributor

It might be a good idea to disable all plugins, then enable just VSCodeVim. I also see ESlint in the settings which does something onSave... Maybe The vim remap is saving and closing while the eslint extension is doing something in between those 2 commands

@waitingsong
Copy link
Author

waitingsong commented Jun 2, 2018

i have disabled all other plugins except
vscode-language-pack-zh-hans and vim.
have tried under empty folder without package.json, eslint.json, tslint.json ,node_module ...etc, only create one file index.ts, still zero after shift zz.

its no problem with vsc version 1.20, but problem with 1.23.1

@xconverge
Copy link
Contributor

Ok I can reproduce this as well, I am not really sure where the bug resides but I have a workaround for you...

        {
            "before": [
                "Z",
                "Z"
            ],
            "after": [],
            "commands": [
                {
                    "command": ":wq",
                    "args": []
                },
            ]
        },

This at least performs the desired action somewhat atomically so there is no issue (even though the underlying commands being done here are the same as what you have in your remapping, there is a time delay between them in :wq). In the vim extension, we are still calling the commands with an await, but I wonder if VSCode is returning instantly when a save is called, yet not actually being performed until the buffer is already cleared thus resulting in saving a cleared buffer?

Not sure what you want to do here @bpasero

@bpasero bpasero added this to the June 2018 milestone Jun 3, 2018
@bpasero bpasero added bug Issue identified by VS Code Team member as probable bug and removed info-needed Issue requires more information from poster labels Jun 3, 2018
@waitingsong
Copy link
Author

@xconverge it works. thanks a lot

@bpasero bpasero changed the title file closed to zero byte with vim plugin and latest vsc version Saving and closing file can result in the file getting empty Jun 4, 2018
@bpasero bpasero added important Issue identified as high-priority candidate Issue identified as probable candidate for fixing in the next release labels Jun 4, 2018
@bpasero bpasero modified the milestones: June 2018, May 2018 Jun 4, 2018
@bpasero bpasero closed this as completed in 50e08be Jun 4, 2018
@bpasero
Copy link
Member

bpasero commented Jun 4, 2018

The issue here was that:

  • a file is not dirty
  • a file is being saved (e.g. through a command or Ctrl+S)
  • a save participant is running (asynchronously, potentially long running)
  • a file is closed without waiting for the save to be finished
  • the save participant comes back and now wants to save the file
  • the file's underlying model has been disposed meanwhile and will now return an empty string as content
  • we store an empty string as contents to the file

The fix is now to not save the file if the underlying model has been disposed meanwhile. In other words, it is not possible to save a (non-dirty) file and close it right after without waiting for the save to finish.

This was only an issue when the file was not dirty, because if the file is dirty, we prompt the user before closing the file to either save or revert it.

@xconverge
Copy link
Contributor

This was a cool example of how responsive you (the vscode devs) have been with this product. Thanks a lot! A cool example of OSS as well with an efficient issue comment section! (Until this comment ;) )

@chrmarti chrmarti added the verified Verification succeeded label Jun 5, 2018
@chrmarti
Copy link
Contributor

chrmarti commented Jun 5, 2018

Verified I could reproduce without the fix and it no longer reproduces with the fix.

@dynajoe
Copy link

dynajoe commented Jun 8, 2018

What version is the fix in? I’ve had this problem many times on prior and current version (as of 6/8/18) of vscode.

@chrmarti
Copy link
Contributor

chrmarti commented Jun 8, 2018

@joeandaverde This fix is in 1.24.0 and yesterday's insiders build. If you are on these or newer builds, could you open a new bug report?

@dynajoe
Copy link

dynajoe commented Jun 11, 2018

I saw this issue in 1.24.0 and 1.23.1

I thought it was an issue with Prettier. Unfortunately, I am unable to reproduce.

prettier/prettier-vscode#489

@vscodebot vscodebot bot locked and limited conversation to collaborators Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug candidate Issue identified as probable candidate for fixing in the next release important Issue identified as high-priority verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

5 participants