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

[LSP] Format request failed, no matching language servers. #306

Closed
nevertoday opened this issue Oct 27, 2022 · 43 comments
Closed

[LSP] Format request failed, no matching language servers. #306

nevertoday opened this issue Oct 27, 2022 · 43 comments

Comments

@nevertoday
Copy link

我反复安装多次了, 其他貌似都欧克, 但这个总提示, 也无法 在保存的时候,格式化代码, 请问 how to fixed this .
thks .

@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Oct 27, 2022

What filetype are u editting? Does it have a corresponding lsp?
If u have installed the corresponding lsp, please check :LspInfo to check if the lsp is activated.

@nevertoday
Copy link
Author

I just edit shell files and html files with .html and .sh extension files .

@CharlesChiuGit
Copy link
Collaborator

So bashls and efm are both running, which is a good sign.
What version of nvim and os are u currently running?

@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Oct 27, 2022

Nvim 0.8.0 looks fine.
Also please delete the help page. Help pages are suppost to help figure things out, not something u should post.

@nevertoday
Copy link
Author

so so so strange 。。。

@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Oct 27, 2022

What kind of sh file are u editing? bashrc or XXX.sh?

@nevertoday
Copy link
Author

XXX.sh

@nevertoday
Copy link
Author

and 1.html

@CharlesChiuGit
Copy link
Collaborator

Can close and re-open the same file and try to save again?
Sometimes it's the lsp haven't fully started, I myself sometimes go the same error too. Re-open the files and the error should go away.

my error:
image

@nevertoday
Copy link
Author

Can close and re-open the same file
I have try this dozens times

@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Oct 27, 2022

I believe it's an upstream issue, maybe we need to wait for bash-lsp or related plugins to update.

@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Oct 27, 2022

@nevertoday so did u have the similar error like mine in the sceenshot?

@nevertoday
Copy link
Author

Spawning language server with cmd: efm-langserver failed. The language server is either not installed, missing from PATH, or not executable.

@nevertoday
Copy link
Author

image

@CharlesChiuGit
Copy link
Collaborator

Have you tried :LspStart when u meet similar error? I can format my shell scripts after running :LspStart when encounter such error.

@nevertoday
Copy link
Author

image

@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Oct 27, 2022

For html files, you have to install the lsp manually.
As u can see in this

for _, server in ipairs(mason_lsp.get_installed_servers()) do
and this section
nvim_lsp.html.setup({
cmd = { "html-languageserver", "--stdio" },
filetypes = { "html" },
init_options = {
configurationSection = { "html", "css", "javascript" },
embeddedLanguages = { css = true, javascript = true },
},
settings = {},
single_file_support = true,
flags = { debounce_text_changes = 500 },
capabilities = capabilities,
on_attach = custom_attach,
})

Html lsp are not install automatically, install it via:

npm i -g vscode-langservers-extracted

ref: https://github.com/hrsh7th/vscode-langservers-extracted

@CharlesChiuGit
Copy link
Collaborator

Also u might need to change the html's config. Please take this as refernce.

@nevertoday
Copy link
Author

After this npm i -g vscode-langservers-extracted

same error appear

image

@nevertoday
Copy link
Author

macos system version 13.0

@CharlesChiuGit
Copy link
Collaborator

Hmmm, weird...
I'm not a html coder, so i can't test it for you. But in

html = { formatter = prettier },

efm is supposed to use prettier to format the html code.

Sorry i can't help u further...

@nevertoday
Copy link
Author

i can use = g to format all code

@nevertoday
Copy link
Author

xxx.sh file same error message

@nevertoday
Copy link
Author

image

markdown files same error

@nevertoday
Copy link
Author

image

image

@CharlesChiuGit
Copy link
Collaborator

Maybe wait for the repo author to help u

@nevertoday
Copy link
Author

image

@Jint-lzxy
Copy link
Collaborator

Jint-lzxy commented Oct 27, 2022

@nevertoday Formatting support for shell and markdown files is provided by prettier. Have you used a package manager (e.g. brew install prettier) or Mason to install the prettier executable itself? efm works well on my machine running MacOS 12.6.

After installing prettier using Mason, you will see:

Mason

Detail:

html = { formatter = prettier },

markdown = { formatter = prettier },

@Jint-lzxy
Copy link
Collaborator

Looks like the problem has been resolved. Feel free to reopen it if you encounter other related issues 👍

@nevertoday
Copy link
Author

Mason

u mean i should change lsp to Mason ??

@CharlesChiuGit
Copy link
Collaborator

Mason and lsp are not the same thing, please do some research first.

@Jint-lzxy
Copy link
Collaborator

Mason

u mean i should change lsp to Mason ??

The short answer is:
You should use Mason to install the corresponding code formatter. In this case, prettier.

Long answer:
Mason is not a language server. The working principle behind this is Mason is a package manager written for Neovim (similar to Homebrew), while efm is a General Purpose Language Server (lsp), which only runs the executable files that the user has installed. In order to format the code, you need to install the corresponding program for efm to use, and in this case, prettier. You may use any global package manager like brew install prettier or Mason to install the formatter.

Does this sound a bit clearer?

@nevertoday
Copy link
Author

thanks all handsome and pretty

I finally decide use lunarvim

@nevertoday
Copy link
Author

I really don't know how to fix this , too hard to get the right way .

@ayamir
Copy link
Owner

ayamir commented Oct 27, 2022

image
You just need to install lsp server like what I wrote in wiki.
If you want to format html file on save, you need to make sure prettier can be found in your PATH. You can execute :MasonInstall prettier in nvim to install it easily.
And all problems will be solved.

@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Oct 27, 2022

@nevertoday I once tried Lunarvim, but it also has it's own issue. One day u will still need to know how to fix bugs like this.
The donw side of a highly pre-config nvimdot is that u can't be sure about wether the bug is from lunarvim, plugins or nvim itself.

@nevertoday
Copy link
Author

brew install efm-langserver

after install this, all things work fine.

maybe this is the right answer.

@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Oct 27, 2022

Seems like it's stated in the wiki

For efm-langserver, you need to install itself and format/lint tools manually.

or

:MasonInstall efm

@nevertoday
Copy link
Author

:MasonInstall efm

failed :

go failed with exit code - and signal -. go is not executable

@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Oct 27, 2022

In mason.nvim's requirements

Note that mason.nvim will regularly shell out to external package managers, such as cargo and npm. Depending on your personal usage, some of these will also need to be installed. Refer to :checkhealth mason for a full list.

And efm-lsp is written in go, so u need to install go if u want to use mason to install go stuffs.

@nevertoday
Copy link
Author

npm config set perfix ~/.local

this works for me

then markdown no error appear anymore .

@CharlesChiuGit
Copy link
Collaborator

CharlesChiuGit commented Oct 27, 2022

good, as u mentioned earlier.
u manually install efm via brew, which will also works.

@nevertoday
Copy link
Author

thank u so much , and I have many bulk edit skill need to learn.
long time use vscode , now come back to vim , exceting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants