Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Support for Yarn PnP #3169

Closed
ramblehead opened this issue Oct 23, 2021 · 1 comment
Closed

Support for Yarn PnP #3169

ramblehead opened this issue Oct 23, 2021 · 1 comment

Comments

@ramblehead
Copy link

ramblehead commented Oct 23, 2021

I have been playing with Yarn PnP support in tide-mode for a while:
ananthakumaran/tide#388

Recently, I have been trying lsp-mode with typescript in an attempt to unify my "Emacs IDE" configurations - as I am already using lsp mode with C++ (clangd).

Most my typescript repositories are Yarn 3 (recently upgraded from Yarn 2). The issues lsp-mode has when it comes to Yarn PnP support (zip'ed packages) are similar to tide-mode:

  • Yarn PnP virtual paths are not resolved in xref jumps and in eldoc hints.
  • tide-mode (Emacs really) is trying to open files in archives using TRAMP mode which is not perfect with archives handling (in my experience at least).

I wrote a small package that patches tide-mode to solve the above-mentioned issues. It was recently modified to work with lsp-mode:
https://github.com/ramblehead/.emacs.d/blob/master/lisp/yarn-pnp.el

yarn-pnp.el package can be loaded after or before tide or lsp as the following:

(require 'yarn-pnp)

(yarn-pnp-tide-enable) ; for tide
;; or
(yarn-pnp-lsp-enable) ; for lsp

I am not publishing this package as it relies on advice-add hacks and it may break if advised upstream functions change. Those hacks solve two Yarn PnP issues - resolving yarn virtual paths and opening zip package files with arc-mode instead of default tramp.

I am not sure if solving Yarn-PnP -- specific issues should be done in tide or lsp code. To me it seems a bit out-of-scope for those projects. Yarn-PnP virtual files schema has changed recently when upgrading from version 2 to version 3 and required corresponding changes in Emacs - it might change again. Also, some users may still prefer tramp instead of arc-mode (or something else). Should we instead add hooks into tide, lsp and eglot that can be used by other packages such as yarn-pnp.el to:

  • filter xref paths (in case if they are virtual);
  • open files (in case if they are inside archives);
  • filter eldoc messages (is case if they contain virtual path as a substring)?

If such hooks can be added, then yarn-pnp.el can be refactored into a stable yarn pnp solution instead of relying on advice-add.

P. S. The following is my reference Yarn 3 (modified initial next.js app) repository that can be used to test and debug yarn-pnp.el:
https://gitlab.com/ogorod/next-app-rh

@yyoncho
Copy link
Member

yyoncho commented Oct 27, 2021

Some language servers provide virtual paths and then they provide a method to retrieve the actual content. For example, java language server returns files in jar archives. Also, the clients can return so-called path transformers path->uri-fn and path->uri-fn which can be used for handling such cases. I don't mind adding such handlers client side but generally, the logic for extracting the file content from the zip should reside in the server to be shared across the clients.

@emacs-lsp emacs-lsp locked and limited conversation to collaborators Oct 27, 2021
@yyoncho yyoncho closed this as completed Oct 27, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants