Giter VIP home page Giter VIP logo

forcedotcom / lightning-language-server Goto Github PK

View Code? Open in Web Editor NEW
30.0 17.0 48.0 9.57 MB

LWC and Aura Language Servers - shipped as part of the Salesforce VSCode Extensions

Home Page: https://forcedotcom.github.io/salesforcedx-vscode/

License: BSD 3-Clause "New" or "Revised" License

JavaScript 81.41% TypeScript 14.44% Shell 0.01% Makefile 0.01% CSS 0.15% HTML 3.04% Emacs Lisp 0.95%
aura lwc vscode language-server

lightning-language-server's Introduction

License
npm (scoped) npm (scoped) npm (scoped) Commitizen friendly

Lightning Language Servers

Mono repo for the LWC and Aura Language Services that are used in the Salesforce Extensions for VS Code.

Issues & Features

Open issues and feature requests on the Salesforce VSCode Extensions Repository.

Setup Development Environment

Pre-requisites

Follow the pre-requisites here: https://github.com/forcedotcom/salesforcedx-vscode/blob/develop/CONTRIBUTING.md

Clone this repository and Salesforce VSCode Extensions

git clone [email protected]:forcedotcom/lightning-language-server.git
git clone [email protected]:forcedotcom/salesforcedx-vscode.git

Note: These projects need to be cloned into the same parent directory

Setup lightning-language-server repository

cd lightning-language-server
yarn install
yarn link-lsp

Setup Salesforce VSCode Extensions repository

cd ../salesforcedx-vscode
npm install
npm run link-lsp
npm run compile

Open both repositories in a vscode workspace

Note: complete the install process before this step, or you may receive errors about "Property ‘objType’ does not exist on type ‘Node’." from the Tern Server. This is due to the node_modules being improperly installed at a level above the lightning-language-server. If this does happen to you, simply remove the extra node_modules directory.

cd ../lightning-language-server
code ./vscode-workspaces/multiroot-simple.code-workspace # or
code ./vscode-workspaces/multiroot-flat.code-workspace

The "simple" workspace will effectively show two main nodes in the Explorer, while "flat" will show each package separately.

Simple:

Flat:

Debugging with VSCode

Run 'Launch DX - Aura & LWC' from the VSCode debug view (its the last one in that long list).

Recompile on change

cd ../lightning-language-server
yarn watch
cd ../salesforcedx-vscode
npm run watch

Note: You need to restart vscode each time you make changes to the language server or the lightning vscode extensions. Easiest way to do this is to kill the vscode client and hit F5 to relaunch your debugger.

Publishing to NPM

When a commit is merged to main, we will automatically create the github release, and then publish the changes to npm using our Github Actions

On-Demand publish to NPM

Navigate to the Actions tab in the repository

  1. Under Workflows on the left side, select Manual Release.
  2. Select Run Workflow, and ensure the newest version is published to npm once the workflow completes.
  3. Any failures will notify the pdt release channel internally.

lightning-language-server's People

Contributors

bpbuch avatar cristicanizales avatar dependabot-preview[bot] avatar dependabot[bot] avatar divmain avatar esalman-sfdc avatar floralan avatar gbockus-sf avatar jag-j avatar jeffb-sfdc avatar kevinv11n avatar krisgraysfdc avatar lcampos avatar midzelis avatar mrmicahcooper avatar mysticflute avatar nrkruk avatar pmdartus avatar randi274 avatar ritamagrawal avatar rsalvador avatar rui-rayqiu avatar sfsholden avatar smacharla-git avatar smithgp avatar svc-idee-bot avatar svc-scm avatar tideteam-sf avatar vazexqi avatar wzcom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lightning-language-server's Issues

Viewing LWC code produces errors in `LWC Language Server` tab

Summary

Short summary of what is going on or to provide context.

Steps To Reproduce:

  1. Open a LWC js file (sometimes takes a couple of files)
  2. Switch to LWC Language Server output tab

Expected result

There are no errors if your component is composed correctly

Actual result

[Error - 11:16:49 AM] Request textDocument/definition failed.
  Message: Request textDocument/definition failed with message: Cannot read property 'find' of undefined
  Code: -32603 

Additional information

Salesforce Extension Version in VS Code: v52.13.0

SFDX CLI Version: sfdx-cli/7.116.2 darwin-x64 node-v14.17.5

OS and version: macOS Big Sur 11.6

The `eslint.nodePath` value in `.vscode/settings.json` does not get updated

Summary

The eslint.nodePath value in .vscode/settings.json does not get updated with the highest local version of eslint-tool. This is for core workspaces in ui-foo-components projects.

Most likely this is because the merging logic of the settings.json intentionally does not override existing values.

Steps To Reproduce:

  1. Do a full core build.
  2. Run the ESLint corecli command.
  3. Load VS Code with the root of the project at a specific project (e.g., ui-force-components).
  4. Check the value of eslint.nodePath.

Expected result

The eslint.nodePath value should point to the highest local version of eslint-tool on my local machine.

Actual result

The eslint.nodePath is never updated once initially set.

Additional information

VS Code Version: 1.57.1

SFDX CLI Version:

OS and version: Mac 10.14.6

Generated Apex and sobject typings missing

Summary

With a previous version of the language server typings for Apex code and sobjects were generated and placed into the .sfdx. folder. Those files are now missing. We were attempting to write our managed package with TypeScript, but those typings missing is a huge blow to our effort.

I was able to trace the missing jsconfig.json path mappings for #284 to a specific PR, but haven't yet been able to trace why these files are missing.

Can we restore this functionality?

Steps To Reproduce:

  1. Create a new project
  2. Add Apex code or custom objects
  3. Note that there are no longer typings for the Apex code or sobjects

Expected result

TS typings should be generated for Apex code as well as sobjects.

Actual result

TS typings are not present.

Additional information

See this screenshot from my .sfdx folder which was generated by a previous version of the sfdx CLI. I upgraded the CLI a while back and just now noticed that these files are no longer generated.
image

VS Code Version: 1.50.1

SFDX CLI Version: sfdx-cli/7.78.1-5a65d9dd2f darwin-x64 node-v12.18.3

OS and version: MacOS 10.15.7

jsconfig missing custom component mappings

Summary

Prior to #160 being merged, it appears that the language server updated jsconfig.json with the path mappings for all of the custom components. The jsconfig is now missing those path mappings.

https://github.com/forcedotcom/lightning-language-server/pull/160/files?file-filters%5B%5D=.ts#diff-4b7a3b1ab597038eec23858a6d9416228da45d15adfe986c56312708938403a1L32

The most apparent implication is that ctrl-click to open no longer works in editors like VSCode.

Steps To Reproduce:

  1. Create a new project
  2. Add some custom components
  3. Import one component from another
  4. Note that ctrl-click no longer works
  5. Note that jsconfig.json does not have the path mappings for the new components.

Expected result

jsconfig.json should have the correct path mappings to allow the editor and tools like TypeScript to be aware of the mappings.

Actual result

The mappings are not present.

Additional information

N/A

VS Code Version: 1.50.1

SFDX CLI Version: sfdx-cli/7.78.1-5a65d9dd2f darwin-x64 node-v12.18.3

OS and version: MacOS 10.15.7

Components with NavigationMixin aren't being parsed correctly to provide hover functionality

Summary

While troubleshooting an issue where hover was consistently throwing an error, it was discovered that the root cause was coming from components using a Navigation Mixin. Those components are not providing information as they should. The root cause appears to be that we're incorrectly saving the customComponents.json index, but I didn't get much further while troubleshooting because #time.

Steps To Reproduce:

  1. Remove the code fix from #491.
  2. Activate the extensions in debug mode.
  3. Hover over a value in an HTML class, using a repo like the ebikes-lwc that uses NavigationMixin.
  4. See the error pop up in VS Code.
  5. Throw some debugger statements into lwc-data-provider.ts at the t.classMembers.forEach(cm => { line.
  6. Walk through until you get to a component like a NavigationMixin, that will be empty and have no data (will also throw the error).

Expected result

Components with Navigation Mixin should provide information like attribute and properties available.

Actual result

There was no className information available, causing an error downstream and not being included as helpful information.

Additional information

Example component not using NavigationMixin:
Screen Shot 2022-03-23 at 4 17 57 PM

Example component using NavigationMixin:

Screen Shot 2022-03-23 at 4 18 54 PM

LWC Autocomplete for component names in test files should use dashes

Is your feature request related to a problem? Please describe.
In Jest files, to create an element you need to use the dashed name, not the component bundle name to create the element. The component bundle name is being provided, and it creates a compile error when autocomplete is used.

Describe the solution you'd like
When creating an element to test in a Jest file, we're providing an autocomplete with the lwcTypingsName, but this doesn't provide the dashed name that is semantically correct.

Describe alternatives you've considered
You can easily modify it once you've autocompleted. But it would be better if you didn't have to!

Additional context
From the LWC documentation: "Camel case component folder names map to kebab-case in markup.". Note the callout that underscores are also legal.

Here is the correctly formatted name with the list of incorrect autocompletes that we provide:
LWC Retry Weirdness

In the markup, the correct syntax would be: c-account-map -> currently works fine, is completed by the htmlCompletion from the VS Code HTML Language Service.
When importing a component (in regular JS file or the test), the correct syntax to import a method from another component would be: import { doSomething } from 'c/accountMap'; -> our current autocomplete is correct here.
When creating an element to test, the correct syntax would be: c-account-map .

@api get recordId and @api set recordId detected in class declaration. Only one of the two needs to be decorated with @api.

Summary

Short summary of what is going on or to provide context.

Steps To Reproduce:

  1. This is step 1.
  2. This is step 2. All steps should start with '1.'

Expected result

No Error from ESLint is shown

Actual result

@api get recordId and @api set recordId detected in class declaration. Only one of the two needs to be decorated with @api.

Additional information

Here is an example of LWC component and error producing code snippet down below
https://webcomponents.dev/edit/4TuiynUFc1ccniIlgo2L

import { LightningElement, api } from 'lwc';

export default class Testsdfsdf extends LightningElement {
    @api get b() {}
    @api set a(value) { }
    get a() {}
}

If at any place in the project you have @api get in the component then adding @api set will give you an error

VS Code Version: 1.62

SFDX CLI Version: sfdx-cli/7.127.0 darwin-x64 node-v16.13.0

OS and version: macOs Catalina 10.15.7

Add support for Lightning Web Components Open Source

Is your feature request related to a problem? Please describe.
Currently LWC OSS is not supported in the language server. This reduces the developer experience when working with that technology outside of Salesforce Platform.

Describe the solution you'd like
Support for LWC OSS should be implemented.

Describe alternatives you've considered
None

LWC Language Server errors on load when config.blt is not present

Summary

Salesforce VS Code Extensions fail to load due to the following error when a config.blt file is not present on the local machine. I just set up a new laptop with corecli and it looks like config.blt is no longer a required file for a core workspace.

We should accommodate this scenario by parsing an alternative config file when config.blt is not present.

[Error: ENOENT: no such file or directory, open '/Users/<user>/blt/config.blt'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/Users/<user>/blt/config.blt'
}
[Error - 3:57:12 PM] Connection to server got closed. Server will not be restarted.

I also see the following error popup in VS Code on load:

 The LWC Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted.

Steps To Reproduce:

  1. Set up core following the latest internal doc (do not use any BLT commands that would init a config.blt file).
  2. Install the VS Code Extension Pack from the public marketplace.
  3. Restart VS Code.

Expected result

VS Code loads without error.

Actual result

The errors above are present.

Additional information

I see the parsing of config.blt done here with no error handling or fallback. We should find an alternative file to read if this line fails:

const configBltContent = await fs.readFile(path.join(this.workspaceRoots[0], relativeBltDir, 'config.blt'), 'utf8');

VS Code Version: 1.67.0 (Universal)

SFDX CLI Version:

OS and version: macOS Monterey 12.3.1

Test

Summary

Short summary of what is going on or to provide context.

Steps To Reproduce:

  1. This is step 1.
  2. This is step 2. All steps should start with '1.'

Expected result

Describe what should have happened.

Actual result

Describe what actually happened instead.

Additional information

Feel free to attach a screenshot.

VS Code Version:

SFDX CLI Version:

OS and version:

Error when using <objects><object>SOBJECT_NAME</object></objects> inside a <targetConfig>

Summary

I just configured a LWC to work with an Object and I got this error. The configuration is fine and it is deployable to a Salesforce org. It is just the vscode extension that complains about it.

image

Below you can see the valid lwc xml config

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>52.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__RecordPage</target>
    </targets>
    <targetConfigs>
        <targetConfig targets="lightning__RecordPage">
            <property label="Height" name="height" type="String" default="500px" description="Adjust this value to change the Height. If you clean this value, it defaults to 100%."/>
            <property label="Width" name="width" type="String" default="" description="Adjust this value to change the component's Width. If you clean this value, it defaults to 100%."/>
            <objects>
                <object>WorkOrder</object>
            </objects>
        </targetConfig>
    </targetConfigs>
    
</LightningComponentBundle>

This is the error message when hovering over the indicated error:

Invalid element name:
 - objects

One of the following is expected:
 - property
 - propertyType
 - supportedFormFactors

Error indicated by:
 {http://soap.sforce.com/2006/04/metadata}
with code:xml(cvc-complex-type.2.4.a)
Limits the component to a set of one or more objects. If you don’t use this tag set, the component supports all supported objects. This tag set works only inside a parent targetConfig that’s configured for lightning__RecordPage. Specify the objects tag set only once inside a targetConfig set. Supports the object subtag

Steps To Reproduce:

  1. Configure a "targetConfig" with an "Object", like the one below:
<targetConfigs>
        <targetConfig targets="lightning__RecordPage">
            <property label="Height" name="height" type="String" default="500px" description="Adjust this value to change the Height. If you clean this value, it defaults to 100%."/>
            <property label="Width" name="width" type="String" default="" description="Adjust this value to change the component's Width. If you clean this value, it defaults to 100%."/>
            <objects>
                <object>WorkOrder</object>
            </objects>
        </targetConfig>
    </targetConfigs>

Expected result

This error message should not appear

Actual result

There is a wrong error message appearing when configuring a LWC to work with an Object.

Additional information

image

SFDX CLI Version: sfdx-cli/7.94.3-a4e7c7955b win32-x64 node-v14.15.4

OS and version: windows 10

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating jest in /yarn.lock:
Couldn't find package "@sinonjs/fake-timers@^6.0.1" required by "@jest/fake-timers@^26.2.0" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Mixed mode workspaces should be supported, or workspace detection improved

Is your feature request related to a problem? Please describe.

As a core developer, it's very easy for me to create a mixed mode workspace and hit actively unsupported behavior as noted in lightning-lsp-common/src/shared.ts. When I do these behaviors, the LWC extension doesn't load and I don't get its benefits.

  • When I include a test/func or test/unit project in my partial build.
  • When I include a submodule in my partial build, like the common logging one. (exact name redacted in this public issue tracker)

My workspace (and every core dev's workspaces) is generated based on local partial build config, so it's easy to hit one of these traps.

Describe the solution you'd like

Enhance the detection in shared.ts to return WorkspaceType.CORE_PARTIAL appropriately for workspaces generated by our internal build tools. I think this would be a really simple change actually. The workspace detection just needs to look up 1-5 parent directories for a "workspace-user.xml" instead of lookup up just a single parent directory.

Describe alternatives you've considered

While developing PR #558, I strategically deleted parts of my generated code-workspace file, and then launched VSCode with only valid project roots.

We could also update the code that generates the workspaces. But I don't think that's correct because then I couldn't use VS Code to edit the common logging code, for example.

Additional context

Internal thread with discussion of #558.

Linter should ignore `__tests__` folder when invoking `@lwc/metadata`

Summary

Users are reporting (salesforce/sfdx-lwc-jest#350) that import { createElement } from 'lwc' is showing a red squiggly in VS Code even though this is not considered a lint error anywhere else in the system (e.g. when running eslint on the command line or publishing via SFDX).

Our team looked into this, and we believe the solution is the following:

  • The compiler ignores files that are in __tests__ folder and hence the linting rules do not apply. That explains why they are not facing any issues when saving the component.
  • The fix would be to make language server mimic the same and ignore tests folder when invoking @lwc/metadata.

Steps To Reproduce:

  1. Add import { createElement } from 'lwc' to a __tests__ (Jest) test in an SFDX project.

Expected result

No red squiggly should appear.

Actual result

A red squiggly appears.

Additional information

Please see salesforce/sfdx-lwc-jest#350 for the original bug report.

VS Code Version: Unknown

SFDX CLI Version: Unknown

OS and version: Unknown

messageService.d.ts file contains incorrect default parameter values for subscribe method

Summary

The TS definition file for lightning/messageService provides type information for the lightning/messageService. The subscribe function within that file indicates that subscriberOptions is a required parameter. According to the documentation subscriberOptions is an optional parameter.

Steps To Reproduce:

  1. Launch a SFDX project in VSCode with the Salesforce Extension Pack (I'm using ebikes here)
  2. Set the checkJS option to true in the "compilerOptions" object and add "../../../../.sfdx/typings/**/*.d.ts" to the "include" array in the jsconfig.json
    image
  3. Navigate to a file that has a subscribe() function from lightning/messageService (productTileList.js in ebikes)
  4. Mouse over the subscribe function, scroll down within the and view the message that indicates a 4th parameter is expected
    image

Expected result

  1. No message should be displayed. The subscriberOptions parameter is optional according to the documentation.
    https://developer.salesforce.com/docs/component-library/bundle/lightning-message-service/documentation
    image

Actual result

  1. A linting message is displayed expecting a 4th parameter
    2023-02-22_19h04_41

Additional information

Salesforce Extension Version in VS Code: v57.2.1

SFDX CLI Version: 7.188.1-4a4bb9c

OS and version: Windows 10 19044.2486

Test string util classes

Hey team,

I noticed that the coverage for this project is quite low, so I've written a few tests to boost it a little bit. Hopefully this helps a little, but if it complicates things then feel free to close this issue and my PR.

I have written tests for string-util.ts in the aura server and strings.ts in lightning lsp common.

Thanks!

An error comes up when you try to use the new template directives

Summary

An error comes up when you try to use the new template directives
Screenshot 2023-02-21 at 12 57 48

Steps To Reproduce:

  1. Install last version of VS Code extensions
  2. Update dev dependencies to last versions
"devDependencies": {
    "@lwc/eslint-plugin-lwc": "^1.6.2",
    "@prettier/plugin-xml": "^2.2.0",
    "@sa11y/jest": "^4.1.1",
    "@salesforce/eslint-config-lwc": "^3.4.0",
    "@salesforce/eslint-plugin-lightning": "^1.0.0",
    "@salesforce/sfdx-lwc-jest": "^1.3.0",
    "eslint": "^8.34.0",
    "eslint-plugin-import": "^2.27.5",
    "eslint-plugin-jest": "^27.2.1",
    "husky": "^8.0.3",
    "lint-staged": "^13.1.2",
    "prettier": "^2.8.4",
    "prettier-plugin-apex": "^1.12.0"
  },
  1. Write a component on a Salesforce project that uses

Expected result

No warning

Actual result

Screenshot 2023-02-21 at 12 57 48

Additional information

Feel free to attach a screenshot.

VS Code Version:

SFDX CLI Version:

OS and version:

Cache usage results in unit test failures on windows.

Summary

A compile issue is encountered when the cache is used for GHA workflows on windows. See this run for an example of it failing. I suspect this is due to lerna and local linking in the monorepo not playing nice with the caching of the top level node_modules.

Steps To Reproduce:

  1. Run the unit tests in GHA repeatedly.

Expected result

should pass & compile on 2nd run.

Actual result

Fails to compile on run 2+

Additional information

The workaround for this is to delete the windows cache from the main GHA screen and rerun the workflow.

Message: Request textDocument/definition failed with message: Cannot destructure property 'delimiter' of '(intermediate value)(intermediate value)(intermediate value)' as it is undefined.

LWC Langauge Server:
[Error - 2:15:54 PM] Request textDocument/definition failed.
Message: Request textDocument/definition failed with message: Cannot destructure property 'delimiter' of '(intermediate value)(intermediate value)(intermediate value)' as it is undefined.
Code: -32603

Getting this error when hovering over Aura component js files.

sfdx version:
sfdx-cli/7.81.0-7b953c80d1 darwin-x64 node-v12.18.3

Implement markup warning messages for `lighting` / `lightening`

Is your feature request related to a problem? Please describe.
it happens often to developers [or at least me] that they write the word lightning wrong, like <lighting-card>. This then leads to a bad experience as it's sometimes really hard to find out why for example local development is throwing an error or when trying to use hover-over help for a base component and it doesn't show up.

Describe the solution you'd like
If tags like <lighting-xxx> or <lightening-xxx> are used within a LWC an error should be raised by the language server.

Describe alternatives you've considered
Focus on not mis-spelling things, but that doesn't help the broader developer audience. 😉

With some guidance I'm happy to contribute that feature. 🤘🏼

Make LWC & Aura language servers available as executables

Is your feature request related to a problem? Please describe.
I've been looking into integrating Neovim's lsp client with lwc language server. Neovim's lsp client uses stdio to communicate with language servers. In my understanding this requires that the language server can be started with a terminal command.

Describe the solution you'd like
Add executable files for lwc and aura language servers. Which would be installed automatically when installing the language servers using npm. This is also the way other language servers written in TypeScript work. This would allow any editor with a lsp client to integrate with aura and lwc language servers, not just neovim

Describe alternatives you've considered
I do not think there are any alternative ways to to this.

Additional context
I've created a PR that should implement the required changes.
Neovim LSP docs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.