microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.05k stars 29.23k forks source link

Settings getting cleared when updating them using API #47763

Open tsalinger opened 6 years ago

tsalinger commented 6 years ago

Issue Type: Bug

  1. Create an extension with 'yo code' and paste in the code at the end of this issue
  2. Switch to a light theme.
  3. Activate the extension and CTRL+Tab multiple times to another open file in the project while the settings are being imported.
  4. Notice how the user settings are temporarily lost and the dark theme is used again, although the users settings still show the light theme.

Observations: The accessibilitySupport prompt popups shortly before it switches to the dark theme Sometimes only a restart of VS Code gets the light theme back.

settingslostwhileimporting

dark_theme_during_settings_import

'use strict';

import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {
    let disposable = vscode.commands.registerCommand('extension.importSettings', () => {
        const config: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration();
        Object.keys(settings).forEach(key => {
            config.update(key, settings[key], vscode.ConfigurationTarget.Global)
        })
    });

    context.subscriptions.push(disposable);
}

export function deactivate() {
}

var settings: { [s: string]: any; } = {
    "files.autoSave": "off",
    "editor.fontSize": 14,
    "editor.fontFamily": "Consolas, 'Courier New', monospace",
    "editor.tabSize": 4,
    "editor.renderWhitespace": "none",
    "editor.cursorStyle": "line",
    "editor.multiCursorModifier": "alt",
    "editor.insertSpaces": true,
    "editor.wordWrap": "off",
    "diffEditor.ignoreTrimWhitespace": true,
    "diffEditor.renderIndicators": true,
    "diffEditor.renderSideBySide": true,
    "editor.acceptSuggestionOnCommitCharacter": true,
    "editor.acceptSuggestionOnEnter": "on",
    "editor.autoClosingBrackets": true,
    "editor.autoIndent": true,
    "editor.codeLens": true,
    "editor.colorDecorators": true,
    "editor.cursorBlinking": "blink",
    "editor.cursorWidth": 0,
    "editor.detectIndentation": true,
    "editor.dragAndDrop": true,
    "editor.emptySelectionClipboard": true,
    "editor.find.autoFindInSelection": false,
    "editor.find.seedSearchStringFromSelection": true,
    "editor.folding": true,
    "editor.foldingStrategy": "auto",
    "editor.fontLigatures": false,
    "editor.fontWeight": "normal",
    "editor.formatOnPaste": false,
    "editor.formatOnSave": false,
    "editor.formatOnSaveTimeout": 750,
    "editor.formatOnType": false,
    "editor.glyphMargin": true,
    "editor.hideCursorInOverviewRuler": false,
    "editor.letterSpacing": 0,
    "editor.lightbulb.enabled": true,
    "editor.lineHeight": 0,
    "editor.lineNumbers": "on",
    "editor.links": true,
    "editor.matchBrackets": true,
    "editor.minimap.enabled": true,
    "editor.minimap.maxColumn": 120,
    "editor.minimap.renderCharacters": true,
    "editor.minimap.showSlider": "mouseover",
    "editor.minimap.side": "right",
    "editor.mouseWheelScrollSensitivity": 1,
    "editor.mouseWheelZoom": false,
    "editor.occurrencesHighlight": true,
    "editor.overviewRulerBorder": true,
    "editor.overviewRulerLanes": 3,
    "editor.parameterHints": true,
    "editor.quickSuggestionsDelay": 10,
    "editor.renderControlCharacters": false,
    "editor.renderIndentGuides": true,
    "editor.renderLineHighlight": "line",
    "editor.roundedSelection": true,
    "editor.rulers": [],
    "editor.scrollBeyondLastLine": true,
    "editor.selectionHighlight": true,
    "editor.showFoldingControls": "mouseover",
    "editor.smoothScrolling": false,
    "editor.snippetSuggestions": "inline",
    "editor.stablePeek": false,
    "editor.suggestFontSize": 0,
    "editor.suggestLineHeight": 0,
    "editor.suggestOnTriggerCharacters": true,
    "editor.suggestSelection": "recentlyUsed",
    "editor.tabCompletion": false,
    "editor.tokenColorCustomizations": {},
    "editor.trimAutoWhitespace": true,
    "editor.useTabStops": true,
    "editor.wordBasedSuggestions": true,
    "editor.wordSeparators": "`~!@#$%^&*()-=+[{]}\\|;:'\",.<>/?",
    "editor.wordWrapColumn": 80,
    "editor.wrappingIndent": "same",
    "javascript.format.enable": true,
    "javascript.format.insertSpaceAfterCommaDelimiter": true,
    "javascript.format.insertSpaceAfterConstructor": false,
    "javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": true,
    "javascript.format.insertSpaceAfterKeywordsInControlFlowStatements": true,
    "javascript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false,
    "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true,
    "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
    "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
    "javascript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
    "javascript.format.insertSpaceAfterSemicolonInForStatements": true,
    "javascript.format.insertSpaceBeforeAndAfterBinaryOperators": true,
    "javascript.format.insertSpaceBeforeFunctionParenthesis": false,
    "javascript.format.placeOpenBraceOnNewLineForControlBlocks": false,
    "javascript.format.placeOpenBraceOnNewLineForFunctions": false,
    "javascript.implicitProjectConfig.checkJs": false,
    "javascript.implicitProjectConfig.experimentalDecorators": false,
    "javascript.nameSuggestions": true,
    "javascript.referencesCodeLens.enabled": false,
    "javascript.suggestionActions.enabled": true,
    "javascript.validate.enable": true,
    "jsDocCompletion.enabled": true,
    "typescript.autoImportSuggestions.enabled": true,
    "typescript.check.npmIsInstalled": true,
    "typescript.disableAutomaticTypeAcquisition": false,
    "typescript.experimental.syntaxFolding": true,
    "typescript.format.enable": true,
    "typescript.format.insertSpaceAfterCommaDelimiter": true,
    "typescript.format.insertSpaceAfterConstructor": false,
    "typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": true,
    "typescript.format.insertSpaceAfterKeywordsInControlFlowStatements": true,
    "typescript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false,
    "typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true,
    "typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
    "typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
    "typescript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
    "typescript.format.insertSpaceAfterSemicolonInForStatements": true,
    "typescript.format.insertSpaceAfterTypeAssertion": false,
    "typescript.format.insertSpaceBeforeAndAfterBinaryOperators": true,
    "typescript.format.insertSpaceBeforeFunctionParenthesis": false,
    "typescript.format.placeOpenBraceOnNewLineForControlBlocks": false,
    "typescript.format.placeOpenBraceOnNewLineForFunctions": false,
    "typescript.implementationsCodeLens.enabled": false,
    "typescript.locale": null,
    "typescript.npm": null,
    "typescript.quickSuggestionsForPaths": true,
    "typescript.referencesCodeLens.enabled": false,
    "typescript.reportStyleChecksAsWarnings": true,
    "typescript.suggestionActions.enabled": true,
    "typescript.tsc.autoDetect": "on",
    "typescript.tsdk": null,
    "typescript.tsserver.log": "off",
    "typescript.tsserver.pluginPaths": [],
    "typescript.tsserver.trace": "off",
    "typescript.useCodeSnippetsOnMethodSuggest": false,
    "typescript.validate.enable": true
}

VS Code version: Code - Insiders 1.23.0-insider (fe9d9532ea6264152c144bd2ba3a6db2cd1732e3, 2018-04-12T05:17:00.120Z) OS version: Windows_NT x64 10.0.16299

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-4600U CPU @ 2.10GHz (4 x 2694)| |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: disabled_software
video_decode: enabled
video_encode: enabled
vpx_decode: unavailable_software
webgl: enabled
webgl2: enabled| |Memory (System)|7.88GB (3.95GB free)| |Process Argv|C:\Program Files\Microsoft VS Code Insiders\Code - Insiders.exe| |Screen Reader|yes| |VM|0%|
Extensions (13) Extension|Author (truncated)|Version ---|---|--- vscode-css-formatter|aes|1.0.1 numbered-bookmarks|ale|0.11.1 regex|chr|0.1.0 vscode-eslint|dba|1.4.8 gitlens|eam|8.2.1 tslint|eg2|1.0.28 vsc-material-theme|Equ|1.5.1 python|ms-|2018.3.1 debugger-for-chrome|msj|4.3.0 gitlink|qez|0.4.2 ayu|tea|0.14.0 vscode-todo-highlight|way|0.5.12 markdown-pdf|yza|0.1.8 (3 theme extensions excluded)
sandy081 commented 6 years ago

@tsalinger I am not able to reproduce this on insiders also when running from dev. Can you please try disabling extensions?

tsalinger commented 6 years ago

@sandy081 I can still reproduce this in the latest insiders with all extensions disabled. Maybe the key is to have the following user settings to start from:

{
    "editor.accessibilitySupport": "off",
    "files.autoSave": "onWindowChange",
    "workbench.colorTheme": "Default Light+",
}

Also make sure to use "files.autoSave": "onWindowChange" in the settings arrray.

The bug seems to appear less frequently when the VS Code window is not maximized.

sandy081 commented 6 years ago

@tsalinger No luck. May be I will sit with you tomorrow and look into it on your machine

usernamehw commented 6 years ago

I've seen a somewhat similar issue. On a laptop it switches to the default dark theme (for about 10ms) and then back at random (cannot reproduce reliably).

There is a comment on a linked issue:

During the import process the settings might be reverted to an empty object for an instant. This leads to a flickering from a light theme to the default dark theme and back. Additionally, the 'screen-reader optimized' message box might be visible for an instant.

Does that mean that the reason of this flickering is some extension or a problem with settings file or API?

sandy081 commented 6 years ago

@usernamehw We investigated on this issue and found out that this is happening because of non-atomic nature of write and read. If a setting is being written into the file and the file is being read at the same time, read is returning empty contents. This can happen when multiple updates are happening.

bcroq commented 3 years ago

I just lost my user settings a few seconds after starting code :disappointed:

VS Code version: 1.51.0 upgraded 4 days ago OS version: Ubuntu 20.04

jaredcwhite commented 3 years ago

I've seen this multiple times now via background software updates. Grabbing my settings.json from backup for the third time… :'(

(yes I should probably turn on Settings Sync, but IMHO that's not an adequate solution to this problem…)

sandy081 commented 3 years ago

Noted, I have added some fixes recently which might prevent this. Can you please try with our recent insiders and see if you see this issue yet?