mdx-js / mdx-analyzer

MDX extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=unifiedjs.vscode-mdx
MIT License
330 stars 19 forks source link

all imports duplicate to the bottom on each save #407

Open onemen opened 6 months ago

onemen commented 6 months ago

Initial checklist

Affected packages and versions

vscode-mdx@1.8.0

Link to runnable example

No response

Steps to reproduce

Expected behavior

lol

Actual behavior

result: another copy of all the imports in the file are duplicated to the bottom of the file

Runtime

Node v20

Package manager

pnpm

OS

Windows

Build and bundle tools

Other (please specify in steps to reproduce)

remcohaszing commented 6 months ago

Thanks for reporting! I'm pretty sure what causes this, so I'll fix it soon. As a workaround you should disable editor.formatOnSave.

But to be sure, can you share an MDX document to reproduce this?

onemen commented 6 months ago

https://github.com/onemen/tabmixplus-docs/blob/main/src/content/docs/index.mdx

remcohaszing commented 6 months ago

I’m seeing different behaviour.

  1. Format Document With…MDX: Nothing happens.
  2. Format Document With…TypeScript and JavaScript Language Features: All lines are replaced with an empty line.
  3. Organize Imports → Imports are sorted

(1) is fine. (2) should really never happen. (3) works as expected. Disabling data.format for all mappings in the virtual code does not change this behaviour.

I’m going to need more info on this. What are your VSCode settings used for formatting?

onemen commented 6 months ago
this is my settings { "editor.formatOnPaste": true, "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode", "prettier.documentSelectors": ["**/*.astro"], "prettier.ignorePath": "./config/.prettierignore", "prettier.configPath": "./config/prettier.config.js", "prettier.requireConfig": true, "[astro]": { "editor.defaultFormatter": "astro-build.astro-vscode" }, "[markdown]": { "editor.rulers": [100], "editor.wordWrap": "wordWrapColumn", "editor.wordWrapColumn": 100 }, "[mdx]": { "files.trimTrailingWhitespace": false, "editor.rulers": [100], "editor.wordWrap": "wordWrapColumn", "editor.wordWrapColumn": 100 }, "[yaml]": { "editor.defaultFormatter": "redhat.vscode-yaml", "editor.formatOnPaste": false, "editor.autoIndent": "advanced" }, "javascript.format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces": true, "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true, "javascript.format.insertSpaceBeforeAndAfterBinaryOperators": true, "javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": true, "typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true, "typescript.format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces": true, "typescript.format.insertSpaceAfterKeywordsInControlFlowStatements": true, "typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": true, "typescript.format.insertSpaceBeforeAndAfterBinaryOperators": true, "editor.wordWrap": "on" }

event when i set

"[mdx]": {
    "editor.defaultFormatter": "unifiedjs.vscode-mdx",
    "files.trimTrailingWhitespace": false,
    "editor.rulers": [100],
    "editor.wordWrap": "wordWrapColumn",
    "editor.wordWrapColumn": 100
  },

the issue remains the same. when i revert back to version 1.7.3 there is no problem

this is how the bottom of the file look like after saving it with version 1.8.0

</CardGrid>import { Card, CardGrid, LinkCard } from '@astrojs/starlight/components'
import DonateButton from '@components/DonateButton.astro'
import { downloadLink, releasesLink } from '@utils/helper.mjs'

the 3 import lines where copy from the top of the file

remcohaszing commented 6 months ago

This is really helpful information, but I’m still not able to reproduce it with those settings.

I just released version 1.8.1. Can you check if that fixes the issue?

onemen commented 6 months ago

1.8.1 did not solve this issue.

I will try to start new folder with empty config and try to find the set of configuration and extension combination

I am on windows 11

onemen commented 6 months ago

The issue is probably some incompatibility with IntelliCode extension from Microsoft.

The problem solved as soon as I disabled IntelliCode

This issue only started on version 1.8.0, on version 1.7.3 using IntelliCode didn't cause any problem

remcohaszing commented 6 months ago

Even with the IntelliCode extension installed and activated, and the settings you posted I’m not seeing this issue.

github-actions[bot] commented 4 months ago

Hi! Thanks for taking the time to contribute! This has been marked by a maintainer as needing more info. It’s not clear yet whether this is an issue. Here are a couple tips:

Thanks, — bb

stdavis commented 4 months ago

I experienced this exact same issue and uninstalling the intellicode extension solved it.

alindl commented 1 month ago

I'm also having this issue and it's also connected to IntelliCode (v1.3.1) and editor.formatOnSave. Either disabling IntelliCode, mdx-analyzer (v1.8.9) or editor.formatOnSave is a workaround.

Here are my settings, but I removed some obvious things like color settings or Java Path:

{
  "[typescriptreact]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "material-ui-snippets.showNotesOnStartup": false,
  "material-ui-snippets.importPaths": "second level",
  "mui-snippets.importPaths": "second level",
  "mui-snippets.showNotesOnStartup": false,
  "npm.packageManager": "npm",
  "editor.tabCompletion": "on",
  "[jsonc]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[scss]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[typescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "jest.disabledWorkspaceFolders": [],
  "jestrunner.codeLens": ["run", "debug", "coverage"],
  "jest.autoRun": "off",
  "jest.showCoverageOnLoad": true,
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.organizeImports": "explicit"
  },
  "files.eol": "\n",
  "[json]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "editor.detectIndentation": false,
  "[sql]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "mtxr.sqltools"
  },
  "workbench.startupEditor": "none",
  "debug.autoExpandLazyVariables": false,
  "editor.linkedEditing": true,
}
aczw commented 1 month ago

Unfortunately, I'm having this issue with Astro's VS Code extension, v2.13.1. Turning it off solves the issue. I feel like maybe it's not Intellicode's fault, but something related to what extensions do in general? I'm on MDX extension v1.8.9.

Edit 1: Astro's extension claims to support auto-imports, which I suspect might be causing the issue here.

Edit 2: okay, found the issue. Turns out I had source.organizeImports: explicit in my editor.codeActionsOnSave in my settings.json, which duplicated imports. Removing it fixed it. Not sure why.