-
Notifications
You must be signed in to change notification settings - Fork 48
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
feat: transition to @lwc/metadata for LWC JS introspection #570
feat: transition to @lwc/metadata for LWC JS introspection #570
Conversation
Thanks for the contribution! Before we can merge this, we need @divmain to sign the Salesforce Inc. Contributor License Agreement. |
6774ac6
to
3430ef1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This monorepo has a top-level yarn.lock
that conflicted with this package-local package-lock.json
. Since the sibling packages do not have their own package-lock.json
, I discerned that its existence here was probably unintentional.
9b89ccb
to
fc924be
Compare
fc924be
to
cca6784
Compare
cca6784
to
044b8fb
Compare
packages/lwc-language-server/src/javascript/__tests__/type-mapping.test.ts
Show resolved
Hide resolved
const metadata = transformerResult.metadata as Metadata; | ||
patchComments(metadata); | ||
return { metadata, diagnostics: [] }; | ||
transformSync(source, fileName, transformOptions); | ||
} catch (err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some compilation errors will only appear upon an attempted compilation. These are generally restricted to non-syntax errors, such as the fact that boolean public properties cannot be true by default (otherwise, how would the parent component disable the flag?).
So, we transform first using the up-to-date compiler to ensure no compilation issues exist. If it succeeds, we collect metadata about the component in the code below.
540d394
to
58fbbc3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me 🙂 And I know all the hard work to get to this 🥳
I also tested the usual features were working as expected, like:
- go to definition (html) ✅
- go to definition (javascript) ✅
- autocompletion ✅
- info on hover ✅
So I would say 🚢
Co-authored-by: Cristina Cañizales <113132642+CristiCanizales@users.noreply.github.com>
What does this PR do?
This PR removes the
lwc-language-server
dependency on an ancient version of the LWC compiler. Now,@lwc/metadata
is leveraged to provide intelligence on LWC JavaScript in the IDE.Initially, the plan was to entirely swap out the data structures underlying a lot of the logic in the language server. Instead of relying on the very old
Metadata
type, all logic would be updated to instead rely on new metadata types exposed by@lwc/metadata
. However, the changes necessary to make this clean swap proved to be extremely invasive. Continuing down that path would have required a de facto rewrite, with all the inevitable subtle incompatibilities and bugs that come with such an endeavor.As an alternative, we chose to provide a mapping of
@lwc/metadata
to the old metadata data structure, including all of its idiosyncrasies. This approach comes with some benefits:lwc-language-server
to stay up-to-date with future releases of LWC, with the possibility that small changes to the mapping might be rarely requiredAs a follow-up I'll work to configure our CI to run your test suite whenever we update
@lwc/metadata
. If successful, the LWC team will be alerted whenever we make breaking changes to your code. In such an event, we would either 1) avoid the break or 2) proactively inform you of the change.What issues does this PR fix or reference?
@W-13045347@