Skip to content

Commit 46baed8

Browse files
authored
Migrate to vue language server 2.x (#127)
1 parent d4da953 commit 46baed8

16 files changed

+830
-1224
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 SublimeLSP
3+
Copyright (c) 2024 SublimeLSP
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

LSP-volar.sublime-commands

Lines changed: 0 additions & 18 deletions
This file was deleted.

LSP-vue.sublime-commands

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"caption": "Preferences: LSP-vue Settings",
4+
"command": "edit_settings",
5+
"args": {
6+
"base_file": "${packages}/LSP-vue/LSP-vue.sublime-settings",
7+
"default": "// Settings in here override those in \"LSP-vue/LSP-vue.sublime-settings\"\n\n{\n\t$0\n}\n"
8+
}
9+
},
10+
]

LSP-volar.sublime-settings renamed to LSP-vue.sublime-settings

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
11
{
22
"initializationOptions": {
3-
// List any additional file extensions that should be processed as Vue files.
4-
"additionalExtensions": [],
5-
// Path to volar.config.js.
6-
"configFilePath": "./volar.config.js",
7-
// Diagnostic update model. (1 - Push, 2 - Pull)
8-
"diagnosticModel": 2,
9-
// Enable this option if you want to get complete CompletionList in language client.
10-
// (Disable for better performance)
11-
"fullCompletionList": false,
12-
// Maximum file size for Vue Server to load. (default: 20MB)
13-
"maxFileSize": 20971520,
14-
// Defines which auto-complete popup trigger characters that Volar defines are allowed.
15-
// By default all Volar trigger characters are disabled as ST does a better job.
16-
"ignoreTriggerCharacters": [],
17-
"json.customBlockSchemaUrls": {},
18-
// Reverse priority for tsconfig pickup.
19-
"reverseConfigFilePriority": false,
20-
// Specify the `typescript.tsdk` to tsserverlibrary.js.
21-
// If not specified LSP-volar will use the typescript from the workspace if it exist,
22-
// else the typescript bundled with LSP-volar will be used.
23-
// "typescript.tsdk": "/path/to/tsserverlibrary.js",
3+
// DON'T use this option until known issues are ironed out - https://github.com/sublimelsp/LSP-vue/issues/130.
4+
// When `true`, the Vue Language Server handles the CSS/HTML sections and partially the SCRIPT section but for
5+
// the JS/TS-specific functionality it relies on the `LSP-typescript` server with `@vue/typescript-plugin` TS
6+
// plugin enabled. When set to `false`, the Vue Language Server handles everything itself.
7+
"vue.hybridMode": false,
248
},
259
"settings": {
2610
// Preferred tag name case.
@@ -37,30 +21,22 @@
3721
// - "kebab": :kebab-case="..."
3822
// - "pascal": :camelCase="..."
3923
"vue.complete.casing.props": "autoKebab",
40-
// Normalize import name for auto import. ("myCompVue" -> "MyComp")
41-
"vue.features.complete.normalizeComponentImportName": true,
24+
// Auto add `const props = ` before `defineProps` when selecting the completion item `props`, `emit` and `slots`.
25+
"vue.complete.defineAssignment": true,
26+
// Show inlay hints for destructured props.
27+
"vue.inlayHints.destructuredProps": false,
4228
// Show inlay hints for missing required props.
4329
"vue.inlayHints.missingProps": false,
4430
// Show inlay hints for event argument in inline handlers.
4531
"vue.inlayHints.inlineHandlerLeading": false,
4632
// Show inlay hints for component options wrapper for type support.
47-
"vue.inlayHints.optionsWrapper": true,
33+
"vue.inlayHints.optionsWrapper": false,
34+
// Show inlay hints for v-bind shorthand.
35+
"vue.inlayHints.vBindShorthand": false,
4836
// Whether to have initial indent.
49-
"volar.format.initialIndent": {
50-
"css": false,
51-
"html": true,
52-
"jade": false,
53-
"javascript": false,
54-
"javascriptreact": false,
55-
"json": false,
56-
"json5": false,
57-
"jsonc": false,
58-
"less": false,
59-
"sass": false,
60-
"scss": false,
61-
"typescript": false,
62-
"typescriptreact": false,
63-
},
37+
"vue.format.template.initialIndent": true,
38+
"vue.format.style.initialIndent": false,
39+
"vue.format.script.initialIndent": false,
6440
// javascript inlay hint
6541
"javascript.inlayHints.enumMemberValues.enabled": false,
6642
"javascript.inlayHints.functionLikeReturnTypes.enabled": false,

Main.sublime-menu

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"id": "lsp-servers",
1717
"children": [
1818
{
19-
"caption": "LSP-volar",
19+
"caption": "LSP-vue",
2020
"command": "edit_settings",
2121
"args": {
22-
"base_file": "${packages}/LSP-volar/LSP-volar.sublime-settings",
23-
"default": "// Settings in here override those in \"LSP-volar/LSP-volar.sublime-settings\"\n\n{\n\t$0\n}\n"
22+
"base_file": "${packages}/LSP-vue/LSP-vue.sublime-settings",
23+
"default": "// Settings in here override those in \"LSP-vue/LSP-vue.sublime-settings\"\n\n{\n\t$0\n}\n"
2424
}
2525
}
2626
]

README.md

Lines changed: 5 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# LSP-volar
1+
# LSP-vue
22

3-
This is a helper package that automatically installs and updates the [Volar Language Server](https://github.com/johnsoncodehk/volar) for you.
3+
This is a helper package that automatically installs and updates the [Vue Language Server (formerly Volar)](https://github.com/vuejs/language-tools) for you.
44

55
## Table of Contents
66
- [Installation](#installation)
@@ -11,77 +11,12 @@ This is a helper package that automatically installs and updates the [Volar Lang
1111

1212
### Installation
1313

14-
* Install [LSP](https://packagecontrol.io/packages/LSP), [Vue Syntax Highlight](https://packagecontrol.io/packages/Vue%20Syntax%20Highlight) and [LSP-volar](https://packagecontrol.io/packages/LSP-volar) from Package Control.
14+
* Install [LSP](https://packagecontrol.io/packages/LSP), [Vue Syntax Highlight](https://packagecontrol.io/packages/Vue%20Syntax%20Highlight) and [LSP-vue](https://packagecontrol.io/packages/LSP-vue) from Package Control.
1515
* Restart Sublime.
1616

1717
### Configuration
1818

19-
Open the configuration file using Command Palette with `Preferences: LSP-volar Settings` command or opening it from the Sublime menu (`Preferences > Package Settings > LSP > Servers > LSP-volar`).
20-
21-
### Enable for non-Vue files
22-
23-
Allow LSP-volar to start in `*.ts | *.tsx | *.js | *.jsx` files.
24-
25-
> **Warning**
26-
> Don't use this unless you really have a specific reason. It provides worse experience than `LSP-typescript` in `.js/.ts` files due to not receiving diagnostic updates on modifying related files. Also it's missing some features of `LSP-typescript`.
27-
> See related issue: https://github.com/vuejs/language-tools/issues/3229
28-
29-
#### Per project:
30-
31-
Create a sublime project file with the following contents:
32-
33-
```js
34-
{
35-
"folders":
36-
[
37-
{
38-
"path": "."
39-
}
40-
],
41-
"settings": {
42-
"LSP": {
43-
"LSP-volar": {
44-
"selector": "text.html.vue | source.ts | source.tsx | source.js | source.jsx"
45-
},
46-
"LSP-typescript": {
47-
"enabled": false
48-
}
49-
}
50-
}
51-
}
52-
```
53-
54-
#### Globally:
55-
56-
From the Command Palette select `Preferences: LSP-volar Settings` and paste the following:
57-
58-
```js
59-
// Settings in here override those in "LSP-volar/LSP-volar.sublime-settings"
60-
61-
{
62-
"selector": "text.html.vue | source.ts | source.tsx | source.js | source.jsx"
63-
}
64-
```
65-
66-
> NOTE: When enabling LSP-volar for non-Vue files, it is advisable to disable the `LSP-typescript` package to avoid showing duplicate results.
67-
68-
### Commands
69-
70-
Package provides a few commands in the Command Palette that can be useful for debugging Volar issues.
71-
72-
#### `LSP-volar (Debug): Show Virtual Files`
73-
74-
Shows a tree view of all internal virtual files associated with the currently opened `vue` file and allows for seeing their contents.
75-
76-
#### `LSP-volar (Debug): Write Virtual Files`
77-
78-
Writes all internal virtual files to disk. The files will be created alongside the original `vue` files that Volar has loaded internally. This can also include `vue` files within `node_modules`. Those files can be useful in figuring out why there are type issues in `vue` files that maybe are due to a Volar bug.
79-
80-
> **Note**
81-
> Type-checking those genearated `.ts` files using `LSP-typescript` is not equivalent to what `LSP-volar` does as Volar does some internal Vue type augmentations that `LSP-typescript` does not do. To get a more relevant type checking when inspecting those files it's recommended to disable `LSP-typescript` and enable `LSP-volar` for TS files instead. Check [Enable for non-Vue files](#enable-for-non-vue-files) section.
82-
83-
> **Note**
84-
> If there are many `vue` files in the project then a lot of files can be created by this command and those could be a bit tiresome to clean up later. In a git-tracked project you might want to use `git clean -fx` to remove all untracked files. Just make sure you don't have any useful untracked files.
19+
Open the configuration file using Command Palette with `Preferences: LSP-vue Settings` command or opening it from the Sublime menu (`Preferences > Package Settings > LSP > Servers > LSP-vue`).
8520

8621
### Inlay hints
8722

@@ -97,7 +32,7 @@ To enable inlay hints:
9732
}
9833
```
9934

100-
2. Modify the following settings through `Preferences: LSP-volar Settings`:
35+
2. Modify the following settings through `Preferences: LSP-vue Settings`:
10136

10237
```js
10338
{
@@ -123,8 +58,3 @@ To enable inlay hints:
12358
```
12459

12560
> NOTE: Inlay hints require TypeScript 4.4+.
126-
127-
### Vue 2 support
128-
129-
Please see [Volar's Installation](https://github.com/johnsoncodehk/volar/blob/master/docs/installation.md) for setup instructions.
130-

messages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"v1.0.8": "messages/1.0.8.txt",
2+
"3.0.0": "messages/3.0.0.txt",
33
"install": "README.md"
44
}

messages/1.0.8.txt

Lines changed: 0 additions & 45 deletions
This file was deleted.

messages/2.2.0.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

messages/3.0.0.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Breaking change
2+
3+
This server is now based on the Vue Language Server 2.x rather than the deprecated and no longer updated Vetur.
4+
5+
The legacy, deprecated Vetur is now available through the LSP-vetur package for those who really need it.

plugin.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from LSP.plugin import ClientConfig
23
from LSP.plugin import WorkspaceFolder
34
from LSP.plugin.core.typing import Any, Callable, List, Optional, Mapping
@@ -7,34 +8,36 @@
78
import os
89
import sublime
910

11+
PACKAGE_NAME = __package__
12+
SERVER_DIRECTORY = 'server'
13+
SERVER_NODE_MODULES = os.path.join(SERVER_DIRECTORY, 'node_modules')
14+
SERVER_BINARY_PATH = os.path.join(SERVER_NODE_MODULES, '@vue', 'language-server', 'bin', 'vue-language-server.js')
1015

1116
def plugin_loaded():
12-
LspVolarPlugin.setup()
17+
LspVuePlugin.setup()
1318

1419

1520
def plugin_unloaded():
16-
LspVolarPlugin.cleanup()
21+
LspVuePlugin.cleanup()
1722

1823

19-
class LspVolarPlugin(NpmClientHandler):
20-
package_name = __package__
21-
server_directory = 'server'
22-
server_binary_path = os.path.join(server_directory, 'node_modules', '@vue', 'language-server', 'bin', 'vue-language-server.js')
24+
class LspVuePlugin(NpmClientHandler):
25+
package_name = PACKAGE_NAME
26+
server_directory = SERVER_DIRECTORY
27+
server_binary_path = SERVER_BINARY_PATH
2328

2429
@classmethod
2530
def required_node_version(cls) -> str:
26-
return '>=16'
31+
return '>=18'
2732

2833
@classmethod
2934
def is_allowed_to_start(
3035
cls,
3136
window: sublime.Window,
32-
initiating_view: Optional[sublime.View] = None,
33-
workspace_folders: Optional[List[WorkspaceFolder]] = None,
34-
configuration: Optional[ClientConfig] = None
37+
initiating_view: sublime.View,
38+
workspace_folders: List[WorkspaceFolder],
39+
configuration: ClientConfig
3540
) -> Optional[str]:
36-
if not workspace_folders or not configuration:
37-
return 'Can not run without a workspace folder'
3841
if configuration.init_options.get('typescript.tsdk'):
3942
return # don't find the `typescript.tsdk` if it was set explicitly in LSP-volar.sublime-settings
4043
typescript_lib_path = cls.find_typescript_lib_path(workspace_folders[0].path)

0 commit comments

Comments
 (0)