Closed mvolkmann closed 4 years ago
If the extension started and markdown
is not in prettier.disabledLanguage
, it should format.
Please check developer console for errors.
I don't have any languages disabled for Prettier. Prettier is working when I save changes to .js and .ts files. When I save a .md file or run the "Format Document" command on a Markdown file, it doesn't do any formatting and I don't see any errors in the console. But I do get a popup that says "There is no formatter for 'markdown'-files installed".
That's really weird ... I think you run latest version (1.2.2)
js, ts, md (, ...) are registered in the exact same way.
Could you debug it?
https://github.com/prettier/prettier-vscode/blob/master/src/extension.ts#L119-L122
What does languageSelector
contain?
@CiGit I'm having the same issue.
VSCode: Version 1.21.1 prettier-vscode: 1.2.2
FWIW, I have Prettier installed globally via npm (going to try removing that next)
I'm also new to Visual Studio Code, so I might not be debugging this correctly. (ref: https://code.visualstudio.com/docs/extensions/developing-extensions#_developer-tools-console)
I edited the extension from my .vscode directory and put in the following console.log in the compiled js file:
const { languageSelector, rangeLanguageSelector } = selectors();
console.log(JSON.stringify(languageSelector, null, 2))
Results are below, let me know if there's something else I can try.
[
{
"language": "javascript",
"scheme": "untitled"
},
{
"language": "javascriptreact",
"scheme": "untitled"
},
{
"language": "typescript",
"scheme": "untitled"
},
{
"language": "typescriptreact",
"scheme": "untitled"
},
{
"language": "json",
"scheme": "untitled"
},
{
"language": "jsonc",
"scheme": "untitled"
},
{
"language": "css",
"scheme": "untitled"
},
{
"language": "postcss",
"scheme": "untitled"
},
{
"language": "less",
"scheme": "untitled"
},
{
"language": "scss",
"scheme": "untitled"
},
{
"language": "graphql",
"scheme": "untitled"
},
{
"language": "markdown",
"scheme": "untitled"
},
{
"language": "javascript",
"pattern": {
"base": "/Users/joe/.vscode/extensions/esbenp.prettier-vscode-1.2.2/out/src",
"pattern": "**"
}
},
{
"language": "javascriptreact",
"pattern": {
"base": "/Users/joe/.vscode/extensions/esbenp.prettier-vscode-1.2.2/out/src",
"pattern": "**"
}
},
{
"language": "typescript",
"pattern": {
"base": "/Users/joe/.vscode/extensions/esbenp.prettier-vscode-1.2.2/out/src",
"pattern": "**"
}
},
{
"language": "typescriptreact",
"pattern": {
"base": "/Users/joe/.vscode/extensions/esbenp.prettier-vscode-1.2.2/out/src",
"pattern": "**"
}
},
{
"language": "json",
"pattern": {
"base": "/Users/joe/.vscode/extensions/esbenp.prettier-vscode-1.2.2/out/src",
"pattern": "**"
}
},
{
"language": "jsonc",
"pattern": {
"base": "/Users/joe/.vscode/extensions/esbenp.prettier-vscode-1.2.2/out/src",
"pattern": "**"
}
},
{
"language": "css",
"pattern": {
"base": "/Users/joe/.vscode/extensions/esbenp.prettier-vscode-1.2.2/out/src",
"pattern": "**"
}
},
{
"language": "postcss",
"pattern": {
"base": "/Users/joe/.vscode/extensions/esbenp.prettier-vscode-1.2.2/out/src",
"pattern": "**"
}
},
{
"language": "less",
"pattern": {
"base": "/Users/joe/.vscode/extensions/esbenp.prettier-vscode-1.2.2/out/src",
"pattern": "**"
}
},
{
"language": "scss",
"pattern": {
"base": "/Users/joe/.vscode/extensions/esbenp.prettier-vscode-1.2.2/out/src",
"pattern": "**"
}
},
{
"language": "graphql",
"pattern": {
"base": "/Users/joe/.vscode/extensions/esbenp.prettier-vscode-1.2.2/out/src",
"pattern": "**"
}
},
{
"language": "markdown",
"pattern": {
"base": "/Users/joe/.vscode/extensions/esbenp.prettier-vscode-1.2.2/out/src",
"pattern": "**"
}
}
]```
@joemaller That's a possibility :)
You opened /Users/joe/.vscode/extensions/esbenp.prettier-vscode-1.2.2/out/src
. Do you have any issue formatting something in it?
markdown seems enabled:
{
"language": "markdown",
"pattern": {
"base": "/Users/joe/.vscode/extensions/esbenp.prettier-vscode-1.2.2/out/src",
"pattern": "**"
}
}
{
"language": "markdown",
"scheme": "untitled"
}
@CiGit I get the same "There is no formatter for 'markdown'-files installed." notice in the lower-right when trying to format Markdown files.
Also, uninstalling the global Prettier package didn't fix anything
Trying to rephrase my question.
Did you open /Users/joe/.vscode/extensions/esbenp.prettier-vscode-1.2.2/out/src
?
There is no markdown in it (shouldn't). Which file did you try to format ?
If you have a problem with a markdown file, can you share its absolute path and languageSelector
content (mostly about markdown) when you opened that file.
We do not use global prettier ;-)
Did you open /Users/joe/.vscode/extensions/esbenp.prettier-vscode-1.2.2/out/src ?
Yes. I modified this: /Users/joe/.vscode/extensions/esbenp.prettier-vscode-1.2.2/out/src/extension.js
But I removed and re-installed the plugin again. (not yet clear on how to work from cloned source.)
Now, after a few restarts and re-installs, it's all working and I can format Markdown files.
Is it possible something was stuck in a pre-existing window? At one point I had a markdown file that wouldn't format, then I dragged the file's tab into a new window and it did format there. Back in the original window formatting still failed. After closing all windows and restarting, (trying to recreate this) the files are formatting everywhere.
Just a followup, I'm still having intermittent failures, on Markdown and JS files. The failures seem very much connected to the window, so maybe it's an upstream issue.
Whenever I have a file that won't format (silent failure), I can create a new window and drag the file's tab into it, then the extension formats the file correctly. Drag it back to the original window, same failure.
@mvolkmann if you have a document that won't format, does it work if moved to a new window?
Not sure where to even start trying to debug that.
I'm on a Mac, frequently open VSCode to a project directory from the terminal with code .
I just noticed today that Prettier is successfully formatting my markdown files on a Windows machine, but not on a Mac. I have the "Prettier - Code Formatter" extension installed on both and the same User Settings for both. Not sure why it doesn't work on Mac.
"There is no formatter for 'markdown'-files installed" Same issus
This might be caused by the way we compute languages to take workspace folder into account.
How do you open theses markdown files? Relatively to folders you may have already opened in VSCode
@CiGit I often use code .
from the terminal. (Mac)
open the markdown file in the workspace
open the markdown file in the workspace
In this case, I don't see why it doesn't format. Anyone with this problem wanting to help debug?
Yeah, just tell me. how to do debug it.
https://github.com/prettier/prettier-vscode/blob/v1.2.2/src/extension.ts#L114 is where languageSelector
is computed. This is what enables formatting for languages
macOS Version 10.13.3 VSCode Version 1.22.1 Prettier Version 1.11.1
[
{ language: "javascript", scheme: "untitled" },
{ language: "javascriptreact", scheme: "untitled" },
{ language: "typescript", scheme: "untitled" },
{ language: "typescriptreact", scheme: "untitled" },
{ language: "json", scheme: "untitled" },
{ language: "jsonc", scheme: "untitled" },
{ language: "css", scheme: "untitled" },
{ language: "postcss", scheme: "untitled" },
{ language: "less", scheme: "untitled" },
{ language: "scss", scheme: "untitled" },
{ language: "graphql", scheme: "untitled" },
{ language: "markdown", scheme: "untitled" },
{
language: "javascript",
pattern: {
base: "/Users/zhangweijie/prettier-markdown-test",
pattern: "**"
}
},
{
language: "javascriptreact",
pattern: {
base: "/Users/zhangweijie/prettier-markdown-test",
pattern: "**"
}
},
{
language: "typescript",
pattern: {
base: "/Users/zhangweijie/prettier-markdown-test",
pattern: "**"
}
},
{
language: "typescriptreact",
pattern: {
base: "/Users/zhangweijie/prettier-markdown-test",
pattern: "**"
}
},
{
language: "json",
pattern: {
base: "/Users/zhangweijie/prettier-markdown-test",
pattern: "**"
}
},
{
language: "jsonc",
pattern: {
base: "/Users/zhangweijie/prettier-markdown-test",
pattern: "**"
}
},
{
language: "css",
pattern: {
base: "/Users/zhangweijie/prettier-markdown-test",
pattern: "**"
}
},
{
language: "postcss",
pattern: {
base: "/Users/zhangweijie/prettier-markdown-test",
pattern: "**"
}
},
{
language: "less",
pattern: {
base: "/Users/zhangweijie/prettier-markdown-test",
pattern: "**"
}
},
{
language: "scss",
pattern: {
base: "/Users/zhangweijie/prettier-markdown-test",
pattern: "**"
}
},
{
language: "graphql",
pattern: {
base: "/Users/zhangweijie/prettier-markdown-test",
pattern: "**"
}
},
{
language: "markdown",
pattern: {
base: "/Users/zhangweijie/prettier-markdown-test",
pattern: "**"
}
}
];
I suspect the issue is that it isn't picking up on the .md
file extension and changing the parser to "markdown". I get an error saying that # is an invalid character. I get the same thing if I run prettier from a terminal on a .md
file. However, it works if I include --parser markdown
.
can you make sure languageId correspond to "markdown" and not something else VSCode or any extension mapped your .md
files to ?
{
language: "markdown",
pattern: {
base: "/Users/zhangweijie/prettier-markdown-test",
pattern: "**"
}
}
this means any markdown
languageid in your prettier-markdown-test has prettier registered as formatter.
Still seeing this occasionally, and it's still tied to the host window. Everything works if I drag the problem tab to a new window.
I don't know how to view the VSCode window instance's properties.
Are you using the prettier.eslintIntegration
? If so, try to do the following:
"[markdown]": {
"prettier.eslintIntegration": false
},
@joemaller same things, I open the .md
file in host window, but open this file in new window, formate success.
I'm getting the same error. It was working a couple days ago, but then it just stopped. It says:
There is no document formatter for 'markdown'-files installed.
Edit: I re-installed prettier and everything works now.
Edit2: It's broken again. Re-installing didn't fix it. https://youtu.be/fxMr8RO5BAg?t=5
Edit3: It broke again, but later randomly worked without re-installing it.
same, bumb Version: 1.25.1 deb9 x64
Is prettier-vscode even supposed to work on other files than JavaScript/TypeScript/CSS? I know that Prettier in itself works on more languages, but what about this extension? The reason I am asking is that this extension's README.md says:
VS Code package to format your JavaScript / TypeScript / CSS using Prettier.
If it is supposed to work on all languages, should the README.md be updated? It's possible this should be a separate issue. But as of right now there is nothing in this extensions README.md that indicates it should work on markdown files.
@thernstig Ow right. That readme part is a little outdated. It is supposed to work on: lot of languageIds but not all. List computed here https://github.com/prettier/prettier-vscode/blob/v1.7.2/src/utils.ts#L35-L40
Hi,
I have checked out this repo I did some code tracing, regarding this issue and probably #275.
I think the problematic LOC is this one: https://github.com/prettier/prettier-vscode/blob/master/src/PrettierEditProvider.ts#L78
The inferred parser come first in the Object.assign
method and will be overwritten by prettierConfig
at the second arguments. So if I just have some Prettier config somewhere in VSCode settings or in a .prettierrc
, the parser
option will always be babylon
.
This is just my quick review so I'm not sure about the intention here, but swapping the arguments here seem to fix it effectively:
function mergeConfig(
hasPrettierConfig: boolean,
additionalConfig: Partial<PrettierConfig>,
prettierConfig: Partial<PrettierConfig>,
vscodeConfig: Partial<PrettierConfig>
) {
return hasPrettierConfig
? Object.assign(
- { parser: vscodeConfig.parser }, // always merge our inferred parser in
prettierConfig,
+ { parser: vscodeConfig.parser }, // always merge our inferred parser in
additionalConfig,
)
: Object.assign(vscodeConfig, prettierConfig, additionalConfig);
}
Still not formatting for me using windows. Nothing happens, no logs.
can you make sure languageId correspond to "markdown" and not something else VSCode or any extension mapped your
.md
files to ?{ language: "markdown", pattern: { base: "/Users/zhangweijie/prettier-markdown-test", pattern: "**" } }
this means any
markdown
languageid in your prettier-markdown-test has prettier registered as formatter.
Where are this meant to be inserted !?
"There is no formatter for 'markdown'-files installed" +1
A year since the Issue started.
Had the same issue, didn't work for me because I had "Markdown All in One" extension installed.
I ran "Format Document" and it told it has several formatters for Markdown and I need to choose one, so I chose Prettier.
It added this to my settings:
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
So now when I save Markdown files they are formatted with Prettier.
i've enabled the Pret. and "MAIO" and the Format Document worked, @alexilyaev , but adding this line to settings didn't help the selection formatting (it still shows the message), also, while the "FD" works, the markdown tables are not auto-formatted (as they should, following the Pret. doc.)
This should be resolved completely in version 3.0. The language resolution was changed and markdown files should be properly detected.
I get the bug with latest prettier-vscode (v3.11.0)
Tables auto-formatting doesn't work .
The formatting stopped to with the latest prettier-vscode (v3.11.0).
It works in windows, but not in vscode WSL mode. The error info is "no formatter is installed". And there is no error message in the prettier Console output. Looks like the prettier is no properly registered in WSL mode.
I just recently started having this issue on prettier 1.19 🤦♂ has there been any resolutions?
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Do I need to change a user setting to make it so "Format Document" on a Markdown file doesn't say "There is no formatter for 'markdown'-files installed"?