redhat-developer / vscode-xml

Editing XML in Visual Studio Code made easy
Eclipse Public License 2.0
260 stars 80 forks source link

Formatter fails on file in a Docker container #758

Open spektre1 opened 2 years ago

spektre1 commented 2 years ago

I'm working on a microservices app that's spread across a lot of containers, so I use the Docker tools to access files inside the container. If I open an XML file that's canonicalized, so not pretty formatted, and attempt to use the XML document formatter via CTRL+SHIFT+P > "Format Document", I get the response in a modal dialog: "There is no formatter for 'xml' files installed."

If I copy and paste the content of the file and then save it locally to my desktop, the formatter functions as expected. The language of the file is being accurately detected as XML and is an XML extension in the toolbar and the tab title.

rgrunber commented 2 years ago

Can you confirm that the XML Language Server process (org.eclipse.lemminx.XMLServerLauncher or lemminx-${platform}, where ${platform} is one of linux, win32, osx-x86_64) starts up and stays up as a process for the container file ? Another thing you could try is set xml.trace.server to verbose and look at the XML Support output to see if there's anything failing there when you try to open the container file. See https://github.com/redhat-developer/vscode-xml/blob/main/docs/Troubleshooting.md#no-support-on-xml-file for further details.

@angelozerr It's strange that formatting works with a local file, but not one in the container. Perhaps something about the file path is not handled correctly ?

I'm able to reproduce this behaviour only if I completely disable the LemMinX language server (kill it until it fails to start) or modify the language server at https://github.com/eclipse/lemminx/blob/39eefb7a3721bfd6d37ea3fbd83dad227e28d8c3/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/capabilities/XMLCapabilityManager.java#L215-L223 to not emit the formatting capabilities.

angelozerr commented 2 years ago

Is it just formatting which is not working or all features like completion, diagnostics etc?

if you have an invalid xml, have you some error displayed in the editor?

angelozerr commented 2 years ago

@spektre1 could you give us more information please.

datho7561 commented 2 years ago

I managed to get it working using the following steps:

  1. Run a container (I ran with podman run -it fedora:latest /bin/bash)
  2. Use the 'Connect to running container' feature from VS Code. This will open a new window.
  3. Install vscode-xml into the container (eg. repeat the regular extension installation process in the new window)
  4. Validation and formatting should work

This isn't great, since it means that you have two copies of the extension installed (one on the system, one on the container), but it does allow you to format documents in the container.

To get it to work in Alpine Linux-based containers, you will need to install java 8 or later on the container, since the binary startup fails. I think the binary doesn't work, because the Linux binary build of lemminx links to glibc (which Alpine doesn't have).

cirolosapio commented 4 months ago

if is an alpine based container maybe #1015 is related