• Stars
    star
    1,199
  • Rank 39,044 (Top 0.8 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 5 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The Svelte Language Server, and official extensions which use it

Cybernetically enhanced web apps: Svelte npm version license

IDE docs and troubleshooting

What is Svelte Language Tools?

Svelte Language Tools contains a library implementing the Language Server Protocol (LSP). LSP powers the VSCode extension, which is also hosted in this repository. Additionally, LSP is capable of powering plugins for numerous other IDEs.

A .svelte file would look something like this:

<script>
    let count = 1;

    // the `$:` means 're-run whenever these values change'
    $: doubled = count * 2;
    $: quadrupled = doubled * 2;

    function handleClick() {
        count += 1;
    }
</script>

<button on:click="{handleClick}">Count: {count}</button>

<p>{count} * 2 = {doubled}</p>
<p>{doubled} * 2 = {quadrupled}</p>

Which is a mix of HTMLx and vanilla JavaScript (but with additional runtime behavior coming from the svelte compiler).

This repo contains the tools which provide editor integrations for Svelte files like this.

Packages

This repo uses pnpm workspaces, which TLDR means if you want to run a commands in each project then you can either cd to that directory and run the command, or use pnpm -r [command].

For example pnpm -r test.

svelte-language-server

The language server for Svelte. Built from UnwrittenFun/svelte-language-server and heavily inspired by Vetur to become the official language server for the language.

svelte-check

A command line tool to check your svelte files for type errors, unused css, and more. Built from Vetur's VTI.

svelte-vscode

The official vscode extension for Svelte. Built from UnwrittenFun/svelte-vscode to become the official vscode extension for the language.

svelte2tsx

Converts a .svelte file into a legal TypeScript file. Built from halfnelson/svelte2tsx to provide the auto-complete and import mapping inside the language server.

Want to see how it's transformed? Check out this REPL

Development

High Level Overview

flowchart LR
    %% IDEs
    VSC[IDE: VSCode + Svelte for VS Code extension]
    click VSC "https://github.com/sveltejs/language-tools/tree/master/packages/svelte-vscode" "Svelte for VSCode extension"
    %% Tools
    CLI[CLI: svelte-check]
    click CLI "https://github.com/sveltejs/language-tools/tree/master/packages/svelte-check" "A command line tool to get diagnostics for Svelte code"
    %% Svelte - Extensions
    VSC_TSSP[typescript-svelte-plugin]
    click VSC_TSSP "https://github.com/sveltejs/language-tools/tree/master/packages/typescript-plugin" "A TypeScript plugin for Svelte intellisense"
    %% Svelte - Packages
    SVELTE_LANGUAGE_SERVER["svelte-language-server"]
    SVELTE_COMPILER_SERVICE["svelte2tsx"]
    TS_SERVICE["TS/JS intellisense using TypeScript language service"]
    SVELTE_SERVICE["Svelte intellisense using Svelte compiler"]
    click SVELTE_LANGUAGE_SERVER "https://github.com/sveltejs/language-tools/tree/master/packages/language-server" "A language server adhering to the LSP"
    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"
    click TS_SERVICE "https://github.com/sveltejs/language-tools/tree/master/packages/language-server/src/plugins/typescript"
    click SVELTE_SERVICE "https://github.com/sveltejs/language-tools/tree/master/packages/language-server/src/plugins/svelte"
    %% External Packages
    HTML_SERVICE[HTML intellisense using vscode-html-languageservice]
    CSS_SERVICE[CSS intellisense using vscode-css-languageservice]
    VSC_TS[vscode-typescript-language-features]
    click HTML_SERVICE "https://github.com/microsoft/vscode-html-languageservice"
    click CSS_SERVICE "https://github.com/microsoft/vscode-css-languageservice"
    click VSC_TS "https://github.com/microsoft/vscode/tree/main/extensions/typescript-language-features"
    subgraph EMBEDDED_SERVICES[Embedded Language Services]
      direction LR
      TS_SERVICE
      SVELTE_SERVICE
      HTML_SERVICE
      CSS_SERVICE
    end
    VSC -- Language Server Protocol --> SVELTE_LANGUAGE_SERVER
    CLI -- Only using diagnostics feature --> SVELTE_LANGUAGE_SERVER
    VSC -- includes --> VSC_TS
    VSC_TS -- loads --> VSC_TSSP
    VSC_TSSP -- uses --> SVELTE_COMPILER_SERVICE
    TS_SERVICE -- uses --> SVELTE_COMPILER_SERVICE
    SVELTE_LANGUAGE_SERVER -- bundles --> EMBEDDED_SERVICES

More information about the internals can be found HERE.

Setup

Pull requests are encouraged and always welcome. Pick an issue and help us out!

To install and work on these tools locally:

Make sure to uninstall the extension from the marketplace to not have it clash with the local one.

git clone https://github.com/sveltejs/language-tools.git svelte-language-tools
cd svelte-language-tools
pnpm install
pnpm bootstrap

Do not use npm to install the dependencies, as the specific package versions in pnpm-lock.yaml are used to build and test Svelte.

To build all of the tools, run:

pnpm build

The tools are written in TypeScript, but don't let that put you off β€” it's basically just JavaScript with type annotations. You'll pick it up in no time. If you're using an editor other than Visual Studio Code you may need to install a plugin in order to get syntax highlighting and code hints etc.

Making Changes

There are two ways to work on this project: either by working against an existing project or entirely through tests.

Running the Dev Language Server Against Your App

To run the developer version of both the language server and the VSCode extension:

  • open the root of this repo in VSCode
  • Go to the debugging panel
  • Make sure "Run VSCode Extension" is selected, and hit run

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. If you don't use pure Javascript and CSS, but languages like Typescript or SCSS, your project will need a Svelte preprocessor setup. When you make changes to the extension or language server you can use the command "Reload Window" in the VSCode command palette to see your changes. When you make changes to svelte2tsx, you first need to run pnpm build within its folder.

Running Tests

You might think that as a language server, you'd need to handle a lot of back and forth between APIs, but actually it's mostly high-level JavaScript objects which are passed to the npm module vscode-languageserver.

This means it's easy to write tests for your changes:

pnpm test

For tricker issues, you can run the tests with a debugger in VSCode by setting a breakpoint (or adding debugger in the code) and launching the task: "Run tests with debugger".

Supporting Svelte

Svelte is an MIT-licensed open source project with its ongoing development made possible entirely by the support of awesome volunteers. If you'd like to support their efforts, please consider:

Funds donated via Open Collective will be used for compensating expenses related to Svelte's development such as hosting costs. If sufficient donations are received, funds may also be used to support Svelte's development more directly.

License

MIT

Credits

  • James Birtles for creating the foundation which this language server, and the extensions are built on
  • Vue's Vetur language server which heavily inspires this project
  • halfnelson for creating svelte2tsx
  • jasonlyu123 for his ongoing work in all areas of the language-tools

More Repositories

1

svelte

Cybernetically enhanced web apps
JavaScript
77,898
star
2

kit

web development, streamlined
JavaScript
18,346
star
3

sapper

The next small thing in web development, powered by Svelte
TypeScript
7,007
star
4

realworld

SvelteKit implementation of the RealWorld app
Svelte
2,212
star
5

template

Template for building basic applications with Svelte
JavaScript
1,743
star
6

svelte-preprocess

A ✨ magical ✨ Svelte preprocessor with sensible defaults and support for: PostCSS, SCSS, Less, Stylus, Coffeescript, TypeScript, Pug and much more.
TypeScript
1,743
star
7

svelte-devtools

A browser extension to inspect Svelte application by extending your browser devtools capabilities
Svelte
1,457
star
8

vite-plugin-svelte

Svelte plugin for http://vitejs.dev/
JavaScript
838
star
9

prettier-plugin-svelte

Format your svelte components using prettier.
TypeScript
726
star
10

sapper-template

Starter template for Sapper apps
JavaScript
703
star
11

svelte-virtual-list

A virtual list component for Svelte apps
JavaScript
673
star
12

integrations

Ways to incorporate Svelte into your stack
632
star
13

gl

A (very experimental) project to bring WebGL to Svelte
JavaScript
603
star
14

svelte-loader

Webpack loader for svelte components.
JavaScript
596
star
15

community-legacy

Svelte community meetups, packages, resources, recipes, showcase websites, and more
Svelte
563
star
16

component-template

A base for building shareable Svelte components
JavaScript
554
star
17

learn.svelte.dev

A soup-to-nuts interactive tutorial on how to build apps with Svelte
Svelte
522
star
18

rollup-plugin-svelte

Compile Svelte components with Rollup
JavaScript
500
star
19

eslint-plugin-svelte3

An ESLint plugin for Svelte v3 components.
JavaScript
372
star
20

svelte-scroller

A <Scroller> component for Svelte apps
Svelte
345
star
21

template-webpack

Template for building basic Svelte applications with webpack
JavaScript
303
star
22

sites

Monorepo for the sites in the Svelte ecosystem
Svelte
291
star
23

eslint-plugin-svelte

ESLint plugin for Svelte using AST
TypeScript
287
star
24

svelte-repl

The <Repl> component used on the Svelte website
Svelte
274
star
25

rfcs

RFCs for changes to Svelte
273
star
26

sapper-studio

An electron app for building Sapper projects
HTML
220
star
27

v2.svelte.dev

The Svelte v2 website
HTML
209
star
28

svelte-hmr

HMR commons for Svelte 3
JavaScript
202
star
29

site-kit

Svelte
196
star
30

hn.svelte.dev

Hacker News clone built with Svelte and Sapper
Svelte
164
star
31

svelte-todomvc

TodoMVC implemented in Svelte
Svelte
139
star
32

svelte-subdivide

A component for building Blender-style layouts in Svelte apps
JavaScript
130
star
33

svelte-cli

Command line interface for Svelte
JavaScript
104
star
34

svelte-eslint-parser

Svelte parser for ESLint
TypeScript
92
star
35

gestures

Svelte actions for cross-platform gesture detection
TypeScript
89
star
36

svelte-hackernews

WIP Hacker News clone written in Svelte
JavaScript
78
star
37

svelte-custom-elements

Turn Svelte components into web components
JavaScript
49
star
38

svelte-extras

Extra methods for Svelte components
JavaScript
43
star
39

sapper-template-rollup

Starter Rollup template for Sapper apps
JavaScript
40
star
40

kit-template-default

The default SvelteKit template, generated with create-svelte
Svelte
36
star
41

svelte-upgrade

Upgrade your Svelte templates for version 2
JavaScript
36
star
42

examples

A collection of Svelte(Kit) examples
35
star
43

branding

Logos etc for Svelte and related projects
35
star
44

hn.svelte.technology

Hacker News, built with Sapper
HTML
35
star
45

svelte-transitions

Officially supported transition plugins for Svelte
JavaScript
33
star
46

sapper-template-webpack

Starter webpack template for Sapper apps
JavaScript
32
star
47

discord-bot

TypeScript
32
star
48

svelte-atom

Syntax, diagnostics, and other smarts for Svelte in Atom
JavaScript
30
star
49

community

28
star
50

svelte-dbmonster

Svelte implementation of DBMonster
JavaScript
27
star
51

template-custom-element

Template for building basic applications with Svelte and custom elements
HTML
21
star
52

generate-ssr

Server-side rendering for Svelte
JavaScript
21
star
53

kit-sandbox

A sandbox for maintainers
JavaScript
18
star
54

template-store

Demonstrating the use of svelte/store
JavaScript
17
star
55

svelte-transitions-draw

Draw transition plugin for Svelte
JavaScript
16
star
56

api.svelte.dev

The API worker source for https://api.svelte.dev
TypeScript
14
star
57

sapper-legacy.svelte.dev

Old docs site for Sapper
HTML
13
star
58

action-deploy-docs

github action for the svelte org to deploy documentation to the svelte api
TypeScript
12
star
59

svelte-bench

Benchmarks for Svelte
JavaScript
10
star
60

sveltegram

Sapper/Svelte remix of nextgram
JavaScript
8
star
61

svelte-transitions-fade

Fade transition plugin for Svelte
JavaScript
8
star
62

assets

Large static files used on the Svelte website
7
star
63

svelte-transitions-slide

Slide transition plugin for Svelte
JavaScript
5
star
64

svelte-transitions-fly

Fly transition plugin for Svelte
JavaScript
4
star
65

redirects

Redirect old Svelte websites to their shiny new equivalents
JavaScript
3
star