5
5
import subprocess
6
6
7
7
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
9
9
10
10
11
11
package_path = os .path .dirname (__file__ )
@@ -65,21 +65,13 @@ def logAndShowMessage(msg, additional_logs=None):
65
65
sublime .active_window ().status_message (msg )
66
66
67
67
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" )
83
75
84
76
class LspVuePlugin (LanguageHandler ):
85
77
@property
@@ -89,34 +81,34 @@ def name(self) -> str:
89
81
@property
90
82
def config (self ) -> ClientConfig :
91
83
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" : [
101
92
'node' ,
102
- server_path
93
+ server_path ,
94
+ '--stdio'
103
95
],
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
+ }
118
102
]
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 )
120
112
121
113
def on_start (self , window ) -> bool :
122
114
if not is_node_installed ():
0 commit comments