Skip to content

Commit

Permalink
Migrate to vue language server 2.x (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl authored Nov 7, 2024
1 parent d4da953 commit 46baed8
Show file tree
Hide file tree
Showing 16 changed files with 830 additions and 1,224 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 SublimeLSP
Copyright (c) 2024 SublimeLSP

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
18 changes: 0 additions & 18 deletions LSP-volar.sublime-commands

This file was deleted.

10 changes: 10 additions & 0 deletions LSP-vue.sublime-commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"caption": "Preferences: LSP-vue Settings",
"command": "edit_settings",
"args": {
"base_file": "${packages}/LSP-vue/LSP-vue.sublime-settings",
"default": "// Settings in here override those in \"LSP-vue/LSP-vue.sublime-settings\"\n\n{\n\t$0\n}\n"
}
},
]
54 changes: 15 additions & 39 deletions LSP-volar.sublime-settings → LSP-vue.sublime-settings
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
{
"initializationOptions": {
// List any additional file extensions that should be processed as Vue files.
"additionalExtensions": [],
// Path to volar.config.js.
"configFilePath": "./volar.config.js",
// Diagnostic update model. (1 - Push, 2 - Pull)
"diagnosticModel": 2,
// Enable this option if you want to get complete CompletionList in language client.
// (Disable for better performance)
"fullCompletionList": false,
// Maximum file size for Vue Server to load. (default: 20MB)
"maxFileSize": 20971520,
// Defines which auto-complete popup trigger characters that Volar defines are allowed.
// By default all Volar trigger characters are disabled as ST does a better job.
"ignoreTriggerCharacters": [],
"json.customBlockSchemaUrls": {},
// Reverse priority for tsconfig pickup.
"reverseConfigFilePriority": false,
// Specify the `typescript.tsdk` to tsserverlibrary.js.
// If not specified LSP-volar will use the typescript from the workspace if it exist,
// else the typescript bundled with LSP-volar will be used.
// "typescript.tsdk": "/path/to/tsserverlibrary.js",
// DON'T use this option until known issues are ironed out - https://github.com/sublimelsp/LSP-vue/issues/130.
// When `true`, the Vue Language Server handles the CSS/HTML sections and partially the SCRIPT section but for
// the JS/TS-specific functionality it relies on the `LSP-typescript` server with `@vue/typescript-plugin` TS
// plugin enabled. When set to `false`, the Vue Language Server handles everything itself.
"vue.hybridMode": false,
},
"settings": {
// Preferred tag name case.
Expand All @@ -37,30 +21,22 @@
// - "kebab": :kebab-case="..."
// - "pascal": :camelCase="..."
"vue.complete.casing.props": "autoKebab",
// Normalize import name for auto import. ("myCompVue" -> "MyComp")
"vue.features.complete.normalizeComponentImportName": true,
// Auto add `const props = ` before `defineProps` when selecting the completion item `props`, `emit` and `slots`.
"vue.complete.defineAssignment": true,
// Show inlay hints for destructured props.
"vue.inlayHints.destructuredProps": false,
// Show inlay hints for missing required props.
"vue.inlayHints.missingProps": false,
// Show inlay hints for event argument in inline handlers.
"vue.inlayHints.inlineHandlerLeading": false,
// Show inlay hints for component options wrapper for type support.
"vue.inlayHints.optionsWrapper": true,
"vue.inlayHints.optionsWrapper": false,
// Show inlay hints for v-bind shorthand.
"vue.inlayHints.vBindShorthand": false,
// Whether to have initial indent.
"volar.format.initialIndent": {
"css": false,
"html": true,
"jade": false,
"javascript": false,
"javascriptreact": false,
"json": false,
"json5": false,
"jsonc": false,
"less": false,
"sass": false,
"scss": false,
"typescript": false,
"typescriptreact": false,
},
"vue.format.template.initialIndent": true,
"vue.format.style.initialIndent": false,
"vue.format.script.initialIndent": false,
// javascript inlay hint
"javascript.inlayHints.enumMemberValues.enabled": false,
"javascript.inlayHints.functionLikeReturnTypes.enabled": false,
Expand Down
6 changes: 3 additions & 3 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"id": "lsp-servers",
"children": [
{
"caption": "LSP-volar",
"caption": "LSP-vue",
"command": "edit_settings",
"args": {
"base_file": "${packages}/LSP-volar/LSP-volar.sublime-settings",
"default": "// Settings in here override those in \"LSP-volar/LSP-volar.sublime-settings\"\n\n{\n\t$0\n}\n"
"base_file": "${packages}/LSP-vue/LSP-vue.sublime-settings",
"default": "// Settings in here override those in \"LSP-vue/LSP-vue.sublime-settings\"\n\n{\n\t$0\n}\n"
}
}
]
Expand Down
80 changes: 5 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# LSP-volar
# LSP-vue

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

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

### Installation

* 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.
* 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.
* Restart Sublime.

### Configuration

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`).

### Enable for non-Vue files

Allow LSP-volar to start in `*.ts | *.tsx | *.js | *.jsx` files.

> **Warning**
> 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`.
> See related issue: https://github.com/vuejs/language-tools/issues/3229
#### Per project:

Create a sublime project file with the following contents:

```js
{
"folders":
[
{
"path": "."
}
],
"settings": {
"LSP": {
"LSP-volar": {
"selector": "text.html.vue | source.ts | source.tsx | source.js | source.jsx"
},
"LSP-typescript": {
"enabled": false
}
}
}
}
```

#### Globally:

From the Command Palette select `Preferences: LSP-volar Settings` and paste the following:

```js
// Settings in here override those in "LSP-volar/LSP-volar.sublime-settings"

{
"selector": "text.html.vue | source.ts | source.tsx | source.js | source.jsx"
}
```

> NOTE: When enabling LSP-volar for non-Vue files, it is advisable to disable the `LSP-typescript` package to avoid showing duplicate results.
### Commands

Package provides a few commands in the Command Palette that can be useful for debugging Volar issues.

#### `LSP-volar (Debug): Show Virtual Files`

Shows a tree view of all internal virtual files associated with the currently opened `vue` file and allows for seeing their contents.

#### `LSP-volar (Debug): Write Virtual Files`

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.

> **Note**
> 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.
> **Note**
> 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.
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`).

### Inlay hints

Expand All @@ -97,7 +32,7 @@ To enable inlay hints:
}
```

2. Modify the following settings through `Preferences: LSP-volar Settings`:
2. Modify the following settings through `Preferences: LSP-vue Settings`:

```js
{
Expand All @@ -123,8 +58,3 @@ To enable inlay hints:
```

> NOTE: Inlay hints require TypeScript 4.4+.
### Vue 2 support

Please see [Volar's Installation](https://github.com/johnsoncodehk/volar/blob/master/docs/installation.md) for setup instructions.

2 changes: 1 addition & 1 deletion messages.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"v1.0.8": "messages/1.0.8.txt",
"3.0.0": "messages/3.0.0.txt",
"install": "README.md"
}
45 changes: 0 additions & 45 deletions messages/1.0.8.txt

This file was deleted.

8 changes: 0 additions & 8 deletions messages/2.2.0.txt

This file was deleted.

5 changes: 5 additions & 0 deletions messages/3.0.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Breaking change

This server is now based on the Vue Language Server 2.x rather than the deprecated and no longer updated Vetur.

The legacy, deprecated Vetur is now available through the LSP-vetur package for those who really need it.
27 changes: 15 additions & 12 deletions plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
from LSP.plugin import ClientConfig
from LSP.plugin import WorkspaceFolder
from LSP.plugin.core.typing import Any, Callable, List, Optional, Mapping
Expand All @@ -7,34 +8,36 @@
import os
import sublime

PACKAGE_NAME = __package__
SERVER_DIRECTORY = 'server'
SERVER_NODE_MODULES = os.path.join(SERVER_DIRECTORY, 'node_modules')
SERVER_BINARY_PATH = os.path.join(SERVER_NODE_MODULES, '@vue', 'language-server', 'bin', 'vue-language-server.js')

def plugin_loaded():
LspVolarPlugin.setup()
LspVuePlugin.setup()


def plugin_unloaded():
LspVolarPlugin.cleanup()
LspVuePlugin.cleanup()


class LspVolarPlugin(NpmClientHandler):
package_name = __package__
server_directory = 'server'
server_binary_path = os.path.join(server_directory, 'node_modules', '@vue', 'language-server', 'bin', 'vue-language-server.js')
class LspVuePlugin(NpmClientHandler):
package_name = PACKAGE_NAME
server_directory = SERVER_DIRECTORY
server_binary_path = SERVER_BINARY_PATH

@classmethod
def required_node_version(cls) -> str:
return '>=16'
return '>=18'

@classmethod
def is_allowed_to_start(
cls,
window: sublime.Window,
initiating_view: Optional[sublime.View] = None,
workspace_folders: Optional[List[WorkspaceFolder]] = None,
configuration: Optional[ClientConfig] = None
initiating_view: sublime.View,
workspace_folders: List[WorkspaceFolder],
configuration: ClientConfig
) -> Optional[str]:
if not workspace_folders or not configuration:
return 'Can not run without a workspace folder'
if configuration.init_options.get('typescript.tsdk'):
return # don't find the `typescript.tsdk` if it was set explicitly in LSP-volar.sublime-settings
typescript_lib_path = cls.find_typescript_lib_path(workspace_folders[0].path)
Expand Down
Loading

0 comments on commit 46baed8

Please sign in to comment.