Louis' Blog

All about software development for the web

Support TypeScript with Vue SFC in Sublime Text

I recently discovered it’s possible to use language servers to enable typescript linting in Vue Single File Components using Sublime Text. This always worked out of the box with .js files, but never for .vue files. The purpose of this post is to document the steps I took to get everything working.

First, you’re going to need to install Sublime Text, and install the LSP plugin.

Then, install vue-language-server:

npm install -g vue-language-server

To enable vue language server in Sublime Text, go to Preferences -> Package Settings -> LSP -> Settings. In the LSP.sublime-settings – User, enter the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{
"clients":
{
"vue-ls":
{
"command":
[
"vls"
],
"enabled": true,
"languageId": "vue",
"scopes":
[
"text.html.vue"
],
"syntaxes":
[
"Packages/Vue Syntax Highlight/Vue Component.sublime-syntax"
],
"initializationOptions": {
"config": {
"vetur": {
"useWorkspaceDependencies": false,
"completion": {
"autoImport": false,
"useScaffoldSnippets": true,
"tagCasing": "kebab"
},
"grammar": {
"customBlocks": {
"docs": "md",
"i18n": "json"
}
},
"validation": {
"template": true,
"style": true,
"script": true
},
"format": {
"enable": true,
"options": {
"tabSize": 2,
"useTabs": false
},
"defaultFormatter": {
"css": "prettier",
"postcss": "prettier",
"scss": "prettier",
"less": "prettier",
"stylus": "prettier",
"js": "prettier",
"ts": "prettier"
},
"defaultFormatterOptions": {
"js-beautify-html": {
"wrap_attributes": "force-expand-multiline"
},
"prettyhtml": {
"printWidth": 100,
"singleQuote": false,
"wrapAttributes": false,
"sortAttributes": false
}
},
"styleInitialIndent": false,
"scriptInitialIndent": false,
},
"trace": {
"server": "off"
},
"experimental": {
"templateInterpolationService": true
}
},
"html": {
"suggest": true
}
}
}
}
}
}

Vue Language Server expects certain configurations to be present, so you have to specify initializationOptions. The above are the default values.

You may need to change the command value to the full path of your vls executable, if you did not install it to a location that is available from your $PATH.

To get the value for syntaxes, open a .vue file and in the SublimeText console, run: view.settings().get('syntax')

You may need to setup the language server, to do that, in Sublime Text, press Ctrl+P, then type LSP. From the list, select “LSP: Setup Language Server” and press Enter.

Setup Language Server

Now you can have auto complete suggestions of the template:

Autocomplete suggestions in template

Definitions of Vue attributes:

Vue attribute definitions

TypeScript error checking:

TypeScript error checking TypeScript errors summary in console