|
| 1 | +# Contributing to Svelte Language Tools |
| 2 | + |
| 3 | +Svelte Language Tools provides IDE support for Svelte files through the Language Server Protocol (LSP). It powers the [VSCode extension](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) and enables Svelte support in [numerous other IDEs](https://microsoft.github.io/language-server-protocol/implementors/tools/). |
| 4 | + |
| 5 | +The [Open Source Guides](https://opensource.guide/) website has a collection of resources for individuals, communities, and companies. These resources help people who want to learn how to run and contribute to open source projects. Contributors and people new to open source alike will find the following guides especially useful: |
| 6 | + |
| 7 | +- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) |
| 8 | +- [Building Welcoming Communities](https://opensource.guide/building-community/) |
| 9 | + |
| 10 | +## Get involved |
| 11 | + |
| 12 | +There are many ways to contribute to Svelte Language Tools, and many of them do not involve writing any code. Here's a few ideas to get started: |
| 13 | + |
| 14 | +- Simply start using Svelte Language Tools in your IDE. Does everything work as expected? If not, we're always looking for improvements. Let us know by [opening an issue](#reporting-new-issues). |
| 15 | +- Look through the [open issues](https://github.com/sveltejs/language-tools/issues). A good starting point would be issues tagged [good first issue](https://github.com/sveltejs/language-tools/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22). Provide workarounds, ask for clarification, or suggest labels. Help triage issues. |
| 16 | +- If you find an issue you would like to fix, [open a pull request](#pull-requests). |
| 17 | +- Read through our [documentation](https://github.com/sveltejs/language-tools/tree/master/docs). If you find anything that is confusing or can be improved, you can make edits by opening a pull request. |
| 18 | +- Take a look at the [features requested](https://github.com/sveltejs/language-tools/labels/enhancement) by others in the community and consider opening a pull request if you see something you want to work on. |
| 19 | + |
| 20 | +Contributions are very welcome. If you think you need help planning your contribution, please reach out to us on [Discord](https://svelte.dev/chat) and let us know you are looking for a bit of help. |
| 21 | + |
| 22 | +## Development |
| 23 | + |
| 24 | +This is a monorepo managed with [`pnpm workspaces`](https://pnpm.io/workspaces/). Install pnpm globally with: |
| 25 | + |
| 26 | +```sh |
| 27 | +npm i -g pnpm |
| 28 | +``` |
| 29 | + |
| 30 | +Clone the repository and install dependencies: |
| 31 | + |
| 32 | +```sh |
| 33 | +git clone [email protected]:sveltejs/language-tools.git |
| 34 | +cd language-tools |
| 35 | +pnpm install |
| 36 | +pnpm bootstrap |
| 37 | +``` |
| 38 | + |
| 39 | +### Building |
| 40 | + |
| 41 | +To build all packages: |
| 42 | + |
| 43 | +```sh |
| 44 | +pnpm build |
| 45 | +``` |
| 46 | + |
| 47 | +To watch for changes: |
| 48 | + |
| 49 | +```sh |
| 50 | +pnpm watch |
| 51 | +``` |
| 52 | + |
| 53 | +### Code structure |
| 54 | + |
| 55 | +#### Packages |
| 56 | + |
| 57 | +- [`packages/language-server`](packages/language-server) - The language server for Svelte. |
| 58 | +- [`packages/svelte-vscode`](packages/svelte-vscode) - The official VSCode extension for Svelte |
| 59 | +- [`packages/svelte2tsx`](packages/svelte2tsx) - Converts `.svelte` files into legal TypeScript/JSX. Want to see how it's transformed? [Check out this REPL](https://embed.plnkr.co/plunk/JPye9tlsqwMrWHGv?show=preview&autoCloseSidebar) |
| 60 | +- [`packages/svelte-check`](packages/svelte-check) - CLI tool for type checking and diagnostics |
| 61 | + |
| 62 | +#### Key entry points |
| 63 | + |
| 64 | +- `packages/language-server/src/server.ts` - Language server entry point |
| 65 | +- `packages/language-server/src/plugins/` - Language service plugins (TypeScript, Svelte, CSS, HTML) |
| 66 | +- `packages/svelte2tsx/src/svelte2tsx/index.ts` - Svelte to TSX transformation |
| 67 | +- `packages/svelte-vscode/src/extension.ts` - VSCode extension entry point |
| 68 | + |
| 69 | +#### High Level Overview |
| 70 | + |
| 71 | +```mermaid |
| 72 | +flowchart LR |
| 73 | + %% IDEs |
| 74 | + VSC[IDE: VSCode + Svelte for VS Code extension] |
| 75 | + click VSC "https://github.com/sveltejs/language-tools/tree/master/packages/svelte-vscode" "Svelte for VSCode extension" |
| 76 | + %% Tools |
| 77 | + CLI[CLI: svelte-check] |
| 78 | + click CLI "https://github.com/sveltejs/language-tools/tree/master/packages/svelte-check" "A command line tool to get diagnostics for Svelte code" |
| 79 | + %% Svelte - Extensions |
| 80 | + VSC_TSSP[typescript-svelte-plugin] |
| 81 | + click VSC_TSSP "https://github.com/sveltejs/language-tools/tree/master/packages/typescript-plugin" "A TypeScript plugin for Svelte intellisense" |
| 82 | + %% Svelte - Packages |
| 83 | + SVELTE_LANGUAGE_SERVER["svelte-language-server"] |
| 84 | + SVELTE_COMPILER_SERVICE["svelte2tsx"] |
| 85 | + TS_SERVICE["TS/JS intellisense using TypeScript language service"] |
| 86 | + SVELTE_SERVICE["Svelte intellisense using Svelte compiler"] |
| 87 | + click SVELTE_LANGUAGE_SERVER "https://github.com/sveltejs/language-tools/tree/master/packages/language-server" "A language server adhering to the LSP" |
| 88 | + click SVELTE_COMPILER_SERVICE "https://github.com/sveltejs/language-tools/tree/master/packages/language-server/src/plugins/svelte" "Transforms Svelte code into JSX/TSX code" |
| 89 | + click TS_SERVICE "https://github.com/sveltejs/language-tools/tree/master/packages/language-server/src/plugins/typescript" |
| 90 | + click SVELTE_SERVICE "https://github.com/sveltejs/language-tools/tree/master/packages/language-server/src/plugins/svelte" |
| 91 | + %% External Packages |
| 92 | + HTML_SERVICE[HTML intellisense using vscode-html-languageservice] |
| 93 | + CSS_SERVICE[CSS intellisense using vscode-css-languageservice] |
| 94 | + VSC_TS[vscode-typescript-language-features] |
| 95 | + click HTML_SERVICE "https://github.com/microsoft/vscode-html-languageservice" |
| 96 | + click CSS_SERVICE "https://github.com/microsoft/vscode-css-languageservice" |
| 97 | + click VSC_TS "https://github.com/microsoft/vscode/tree/main/extensions/typescript-language-features" |
| 98 | + subgraph EMBEDDED_SERVICES[Embedded Language Services] |
| 99 | + direction LR |
| 100 | + TS_SERVICE |
| 101 | + SVELTE_SERVICE |
| 102 | + HTML_SERVICE |
| 103 | + CSS_SERVICE |
| 104 | + end |
| 105 | + VSC -- Language Server Protocol --> SVELTE_LANGUAGE_SERVER |
| 106 | + CLI -- Only using diagnostics feature --> SVELTE_LANGUAGE_SERVER |
| 107 | + VSC -- includes --> VSC_TS |
| 108 | + VSC_TS -- loads --> VSC_TSSP |
| 109 | + VSC_TSSP -- uses --> SVELTE_COMPILER_SERVICE |
| 110 | + TS_SERVICE -- uses --> SVELTE_COMPILER_SERVICE |
| 111 | + SVELTE_LANGUAGE_SERVER -- bundles --> EMBEDDED_SERVICES |
| 112 | +``` |
| 113 | + |
| 114 | +More information about the internals can be found [HERE](./docs/internal/overview.md). |
| 115 | + |
| 116 | +### Running tests |
| 117 | + |
| 118 | +Run tests for all packages: |
| 119 | + |
| 120 | +```sh |
| 121 | +pnpm test |
| 122 | +``` |
| 123 | + |
| 124 | +Run tests for a specific package: |
| 125 | + |
| 126 | +```sh |
| 127 | +cd packages/[package-name] |
| 128 | +pnpm test |
| 129 | +``` |
| 130 | + |
| 131 | +### Testing in VSCode |
| 132 | + |
| 133 | +To test your changes in VSCode: |
| 134 | + |
| 135 | +1. Open the repository in VSCode |
| 136 | +2. Go to the debug panel (Ctrl+Shift+D / Cmd+Shift+D) |
| 137 | +3. Select "Run VSCode Extension" from the dropdown |
| 138 | +4. Press F5 to launch a new VSCode instance with your changes |
| 139 | + |
| 140 | +This launches a new VSCode window and a watcher for your changes. In this dev window you can choose an existing Svelte project to work against. When you make changes to `svelte-vscode` use the command "Reload Window" in the VSCode command palette to see your changes. When you make changes to `language-server` use the command "Svelte: Restart Language Server". When you make changes to `svelte2tsx`, you first need to run `pnpm build` within its folder, then restart the language server. When you make changes to`typescript-plugin`, you need to first run `pnpm build` within its folder and then use the command "TypeScript: Restart Server". |
| 141 | + |
| 142 | +#### Testing in other editors |
| 143 | + |
| 144 | +For other editors, you'll need to build the language server and configure your editor to use the local build. See the documentation for your specific editor. |
| 145 | + |
| 146 | +### Linking local changes |
| 147 | + |
| 148 | +To test certain local changes in a Svelte project, you might want to use [pnpm `overrides`](https://pnpm.io/package_json#pnpmoverrides) in your project's `package.json`: |
| 149 | + |
| 150 | +```jsonc |
| 151 | +{ |
| 152 | + "pnpm": { |
| 153 | + "overrides": { |
| 154 | + // Test changes to svelte-check: |
| 155 | + "svelte-check": "link:../path/to/language-tools/packages/svelte-check", |
| 156 | + // You only need this if you're testing the changes with an editor other than VS Code: |
| 157 | + "svelte-language-server": "link:../path/to/language-tools/packages/language-server" |
| 158 | + } |
| 159 | + } |
| 160 | +} |
| 161 | +``` |
| 162 | + |
| 163 | +## Pull requests |
| 164 | + |
| 165 | +Small pull requests are much easier to review and more likely to get merged. Make sure the PR does only one thing, otherwise please split it. |
| 166 | + |
| 167 | +Please make sure the following is done when submitting a pull request: |
| 168 | + |
| 169 | +1. Fork [the repository](https://github.com/sveltejs/language-tools) and create your branch from `master`. |
| 170 | +2. Describe your test plan in your pull request description. Make sure to test your changes. |
| 171 | +3. Make sure your code lints (`pnpm lint`). |
| 172 | +4. Make sure your tests pass (`pnpm test`). |
| 173 | +5. Make sure your code is properly formatted (`pnpm format`). |
| 174 | + |
| 175 | +If you're only fixing a bug, it's fine to submit a pull request right away but we still recommend that you file an issue detailing what you're fixing. This is helpful in case we don't accept that specific fix but want to keep track of the issue. |
| 176 | + |
| 177 | +All pull requests should be opened against the `master` branch. |
| 178 | + |
| 179 | +## License |
| 180 | + |
| 181 | +By contributing to Svelte Language Tools, you agree that your contributions will be licensed under its [MIT license](LICENSE). |
| 182 | + |
| 183 | +## Questions? |
| 184 | + |
| 185 | +Join us in the [Svelte Discord](https://svelte.dev/chat) and post your question. |
0 commit comments