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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 BUG: Language server not starting properly in non-VSCode editors if prettier or the prettier plugin are missing #838

Closed
ChristianIvicevic opened this issue Mar 21, 2024 · 1 comment
Labels
needs response Need a response from the original author

Comments

@ChristianIvicevic
Copy link

ChristianIvicevic commented Mar 21, 2024

Describe the Bug

Hey everyone,

this is Christian from the WebStorm team at JetBrains and we have been working on integrating the Astro LS for our most recent version but noticed an unexpected issue close to release that we'd like to raise with you in order to discuss whether you would consider fixing it on your end before we build some unconventional workarounds.

During the startup of the language server it attempts to load prettier and the prettier plugin for the purposes of initializing the Volar services:

prettier = importPrettier(workspaceUri.fsPath);
prettierPluginPath = getPrettierPluginPath(workspaceUri.fsPath);
if (!prettier || !prettierPluginPath) {
connection.sendNotification(ShowMessageNotification.type, {
message:
"Couldn't load `prettier` or `prettier-plugin-astro`. Formatting will not work. Please make sure those two packages are installed into your project.",
type: MessageType.Warning,
});
}
return prettier;

However, if no instance of prettier was found then the upstream volar-service-prettier will throw an error and prevent the Astro LS from starting at all. While it is true that this is fixed once the user installs those two peer dependencies (prettier and the plugin) explicitly into their project, this is not necessary when using VSCode. The readme does mention this, but I had the assumption this formatting is optional and not required.

Seemingly, the VSCode Astro plugin is silently (and unconventionally) installing the LS into the node_modules together with prettier and the plugin and thus the LS is able to pick up those dependencies. I came to this conclusion after creating a fresh Astro project that caused the LS to fail in WebStorm and noticed that opening it once in VSCode and then again in WebStorm causes no more issues until I noticed that the node_modules folder has been changed.

I would like to propose to make the detection and inclusion of the prettier service more robust and optional, i.e. making the following function call be handled more gracefully or the implementation check whether the dependencies exist in the first place before attempting to initialize the Volar service. Calling the create function from volar-service-prettier with no instance causes the failure to start.

I'm open for discussions and willing to contribute the necessary changes to handle this use-case more gracefully than before if there are no objections.

Steps to Reproduce

  1. npm init astro
  2. Open the project outside of VSCode in any editor/IDE that supports the language server, but hasn't prettier or prettier-plugin-astro installed
  3. The LS is not starting at all
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Mar 21, 2024
@Princesseuh Princesseuh added needs response Need a response from the original author and removed needs triage Issue needs to be triaged labels Mar 21, 2024
@ChristianIvicevic
Copy link
Author

After a quick conversation with @Princesseuh we noticed that this issue has been fixed last week as part of upstream changes that were done in volarjs/services#84 and then pulled in via #823. The problems are no longer occurring in newer versions of the LS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs response Need a response from the original author
Projects
None yet
Development

No branches or pull requests

2 participants