Skip to content

Commit 5b37870

Browse files
Add user configuration
1 parent 80128ad commit 5b37870

File tree

2 files changed

+80
-75
lines changed

2 files changed

+80
-75
lines changed

LSP-vue.sublime-settings

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,52 @@
11
{
2-
"config": {
3-
"vetur": {
4-
"completion": {
5-
"autoImport": false,
6-
"tagCasing": "kebab",
7-
"useScaffoldSnippets": false
8-
},
9-
"format": {
10-
"defaultFormatter": {
11-
"js": "none",
12-
"ts": "none"
13-
},
14-
"defaultFormatterOptions": {},
15-
"scriptInitialIndent": false,
16-
"styleInitialIndent": false,
17-
"options": {}
18-
},
19-
"useWorkspaceDependencies": false,
20-
"validation": {
21-
"script": true,
22-
"style": true,
23-
"template": true
2+
"client" : {
3+
"enabled": true,
4+
"languages": [
5+
{
6+
"languageId": "vue",
7+
"scopes": ["text.html.vue"],
8+
"syntaxes": ["Packages/Vue Syntax Highlight/Vue Component.sublime-syntax"]
249
}
10+
],
11+
"initializationOptions": {
12+
// "config": {
13+
// "vetur": {
14+
// "completion": {
15+
// "autoImport": false,
16+
// "tagCasing": "kebab",
17+
// "useScaffoldSnippets": false
18+
// },
19+
// "format": {
20+
// "defaultFormatter": {
21+
// "js": "none",
22+
// "ts": "none"
23+
// },
24+
// "defaultFormatterOptions": {},
25+
// "scriptInitialIndent": false,
26+
// "styleInitialIndent": false,
27+
// "options": {}
28+
// },
29+
// "useWorkspaceDependencies": false,
30+
// "validation": {
31+
// "script": true,
32+
// "style": true,
33+
// "template": true
34+
// }
35+
// },
36+
// "css": {},
37+
// "emmet": {},
38+
// "stylusSupremacy": {},
39+
// "html": {
40+
// "suggest": {}
41+
// },
42+
// "javascript": {
43+
// "format": {}
44+
// },
45+
// "typescript": {
46+
// "format": {}
47+
// }
48+
// }
2549
},
26-
"css": {},
27-
"emmet": {},
28-
"stylusSupremacy": {},
29-
"html": {
30-
"suggest": {}
31-
},
32-
"javascript": {
33-
"format": {}
34-
},
35-
"typescript": {
36-
"format": {}
37-
}
50+
"settings": {}
3851
}
3952
}

plugin.py

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import subprocess
66

77
from LSP.plugin.core.handlers import LanguageHandler
8-
from LSP.plugin.core.settings import ClientConfig, LanguageConfig
8+
from LSP.plugin.core.settings import ClientConfig, LanguageConfig, read_client_config
99

1010

1111
package_path = os.path.dirname(__file__)
@@ -65,21 +65,13 @@ def logAndShowMessage(msg, additional_logs=None):
6565
sublime.active_window().status_message(msg)
6666

6767

68-
def getGlobalSnippetDir() -> str:
69-
"""
70-
Returns default global directory for user's snippets.
71-
72-
Uses same logic and paths as vetur.
73-
See https://github.com/vuejs/vetur/blob/master/client/userSnippetDir.ts
74-
"""
75-
appName = 'Code'
76-
if sublime.platform() == 'windows':
77-
return os.path.expandvars('%%APPDATA%%\\{}\\User\\snippets\\vetur').format(appName)
78-
elif sublime.platform() == 'osx':
79-
return os.path.expanduser('~/Library/Application Support/{}/User/snippets/vetur').format(appName)
80-
else:
81-
return os.path.expanduser('~/.config/{}/User/snippets/vetur').format(appName)
82-
68+
def update_to_new_configuration(settings, old_config, new_config):
69+
# add old config to new config
70+
new_config['initializationOptions']['config'] = old_config
71+
settings.set('client', new_config)
72+
# remove old config
73+
settings.erase('config')
74+
sublime.save_settings("LSP-vue.sublime-settings")
8375

8476
class LspVuePlugin(LanguageHandler):
8577
@property
@@ -89,34 +81,34 @@ def name(self) -> str:
8981
@property
9082
def config(self) -> ClientConfig:
9183
settings = sublime.load_settings("LSP-vue.sublime-settings")
92-
config = settings.get('config')
93-
globalSnippetDir = settings.get('globalSnippetDir', getGlobalSnippetDir())
94-
view = sublime.active_window().active_view()
95-
if view is not None:
96-
config['vetur']['format']['options']['tabs_size'] = view.settings().get("tab_size", 4)
97-
config['vetur']['format']['options']['useTabs'] = not view.settings().get("translate_tabs_to_spaces", False)
98-
return ClientConfig(
99-
name='lsp-vue',
100-
binary_args=[
84+
# TODO: remove update_to_new_configuration after 1 November.
85+
old_config = settings.get('config')
86+
client_configuration = settings.get('client')
87+
if old_config:
88+
update_to_new_configuration(settings, old_config, client_configuration)
89+
90+
default_configuration = {
91+
"command": [
10192
'node',
102-
server_path
93+
server_path,
94+
'--stdio'
10395
],
104-
tcp_port=None,
105-
enabled=True,
106-
init_options={
107-
"config": config,
108-
"globalSnippetDir": globalSnippetDir
109-
},
110-
settings=dict(),
111-
env=dict(),
112-
languages=[
113-
LanguageConfig(
114-
'vue',
115-
['text.html.vue'],
116-
["Packages/Vue Syntax Highlight/Vue Component.sublime-syntax"]
117-
)
96+
"languages": [
97+
{
98+
"languageId": "vue",
99+
"scopes": ["text.html.vue"],
100+
"syntaxes": ["Packages/Vue Syntax Highlight/Vue Component.sublime-syntax"]
101+
}
118102
]
119-
)
103+
}
104+
default_configuration.update(client_configuration)
105+
view = sublime.active_window().active_view()
106+
if view is not None:
107+
options = default_configuration['initializationOptions']['config']['vetur']['format']['options']
108+
options['tabSize'] = view.settings().get("tab_size", 4)
109+
options['useTabs'] = not view.settings().get("translate_tabs_to_spaces", False)
110+
111+
return read_client_config('lsp-vue', default_configuration)
120112

121113
def on_start(self, window) -> bool:
122114
if not is_node_installed():

0 commit comments

Comments
 (0)