0

Today, when I tried to save my file, the code was completely scrambled. I've been using this file for a couple weeks now and this has never happened before. Does anyone know what's going on here?

Here's the before: image of clean code

Here's the after: an image of messy, confusing code code

And it's not just the look, but also the code. It's full of errors.

I've also added code chunks:

BEFORE:

    async function listEmails() {
            let response;
            try {
                response = await gapi.client.gmail.users.messages.list({
                    'userId': 'me',
                });
            } catch (err) {
                document.getElementById('content').innerText = err.message;
                return;
            }
            const emails = response.result.messages;
            if (!emails || emails.length == 0) {
                document.getElementById('content').innerText = 'No emails found.';
                console.log('No emails found.');
                return;
            }
            // Flatten to string to display
            const output = emails.reduce(
                (str, email) => `${str}${email.name}\n`,
                'Emails:\n');
            document.getElementById('content').innerText = output;
        }

AFTER:

    async f        Emails() {
            let response;
            try {
            response = await gapi.client.gmail.users.messages.list({
                'userId': 'm                            } catch (err) {
                document.getElementById                t = err.message;             ret             }
                     = response.result.messages;
            if (!emails || email            
               um        ntById('content').innerText = 'No emails                      console.log('No emails f                     return;
            }
            // Flatten to string to                 const output = emails.reduce(             (str, e        st        me}\n`,
                'Emails:              document.getElementById(            Text = output;
        }
16
  • Please ensure that the code is posted in text format, and not as a screenshot. Commented Aug 12, 2024 at 19:17
  • 1
    @toyotaSupra you can only understand the problem in the current posted form. Commented Aug 12, 2024 at 19:19
  • 2
    perhaps you have an extension that doesn't work quite properly? Try cmd+shift+p and do Save without formatting. If that saves the file without scrambling the content, you can check here to see how to fix it stackoverflow.com/questions/39494277/… Commented Aug 12, 2024 at 19:22
  • Have you made any changes to your VSCode settings recently? Also, have you made any upgrades to the VSCode application? Commented Aug 12, 2024 at 19:25
  • 2
    Added code chunks. Commented Aug 12, 2024 at 19:29

1 Answer 1

0

I solved the problem by going into my settings.json, which looked like this:

{
  "workbench.colorTheme": "Default Dark Modern",
  "security.workspace.trust.untrustedFiles": "open",
  "terminal.integrated.inheritEnv": false,
  "liveServer.settings.donotShowInfoMsg": true,
  "editor.minimap.enabled": false,
  "python.defaultInterpreterPath": "/Users/priyapatel/anaconda3/bin/python",
  "terminal.integrated.enableMultiLinePasteWarning": false,
  "github.copilot.editor.enableAutoCompletions": true,
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnType": true,
  "editor.formatOnSaveMode": "modificationsIfAvailable",
  "liveServer.settings.showOnStatusbar": true,
  "[html]": {
    "editor.defaultFormatter": "vscode.html-language-features"
  }
}

And I got rid of the last line, so that the document now looks like this:

{
  "workbench.colorTheme": "Default Dark Modern",
  "security.workspace.trust.untrustedFiles": "open",
  "terminal.integrated.inheritEnv": false,
  "liveServer.settings.donotShowInfoMsg": true,
  "editor.minimap.enabled": false,
  "python.defaultInterpreterPath": "/Users/priyapatel/anaconda3/bin/python",
  "terminal.integrated.enableMultiLinePasteWarning": false,
  "github.copilot.editor.enableAutoCompletions": true,
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnType": true,
  "editor.formatOnSaveMode": "modificationsIfAvailable",
  "liveServer.settings.showOnStatusbar": true
}

Solved the problem for me.

Sign up to request clarification or add additional context in comments.

3 Comments

I think the actual reason is that the formatter is set to the wrong one.
Can you clarify what you mean?
The formatter is set to the HTML one, but you're using it to format JS code. That may be the reason that the code is all messed up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.