Skip to content

Commit

Permalink
Add user configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
predrag-codetribe committed Sep 29, 2019
1 parent 80128ad commit 5b37870
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 75 deletions.
81 changes: 47 additions & 34 deletions LSP-vue.sublime-settings
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
{
"config": {
"vetur": {
"completion": {
"autoImport": false,
"tagCasing": "kebab",
"useScaffoldSnippets": false
},
"format": {
"defaultFormatter": {
"js": "none",
"ts": "none"
},
"defaultFormatterOptions": {},
"scriptInitialIndent": false,
"styleInitialIndent": false,
"options": {}
},
"useWorkspaceDependencies": false,
"validation": {
"script": true,
"style": true,
"template": true
"client" : {
"enabled": true,
"languages": [
{
"languageId": "vue",
"scopes": ["text.html.vue"],
"syntaxes": ["Packages/Vue Syntax Highlight/Vue Component.sublime-syntax"]
}
],
"initializationOptions": {
// "config": {
// "vetur": {
// "completion": {
// "autoImport": false,
// "tagCasing": "kebab",
// "useScaffoldSnippets": false
// },
// "format": {
// "defaultFormatter": {
// "js": "none",
// "ts": "none"
// },
// "defaultFormatterOptions": {},
// "scriptInitialIndent": false,
// "styleInitialIndent": false,
// "options": {}
// },
// "useWorkspaceDependencies": false,
// "validation": {
// "script": true,
// "style": true,
// "template": true
// }
// },
// "css": {},
// "emmet": {},
// "stylusSupremacy": {},
// "html": {
// "suggest": {}
// },
// "javascript": {
// "format": {}
// },
// "typescript": {
// "format": {}
// }
// }
},
"css": {},
"emmet": {},
"stylusSupremacy": {},
"html": {
"suggest": {}
},
"javascript": {
"format": {}
},
"typescript": {
"format": {}
}
"settings": {}
}
}
74 changes: 33 additions & 41 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import subprocess

from LSP.plugin.core.handlers import LanguageHandler
from LSP.plugin.core.settings import ClientConfig, LanguageConfig
from LSP.plugin.core.settings import ClientConfig, LanguageConfig, read_client_config


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


def getGlobalSnippetDir() -> str:

This comment has been minimized.

Copy link
@rchl

rchl Sep 30, 2019

Member

That was removed but while the crash is fixed in the server now, having this would still be beneficial as it allowed loading snippets from user directory. Otherwise it's not possible.

This comment has been minimized.

Copy link
@predragnikolic

predragnikolic Sep 30, 2019

Member

Otherwise it's not possible.

It is possible, you can specify your own snippet directory like so:

// LSP-vue.sublime-settings - User
{
    "client" : {
        "enabled": true,
        "initializationOptions": {
            // "globalSnippetDir": "path/to/your_snippet_directory",
            // "config": {
            // ... 
            // }
        },
        "settings": {}
    }
}

Why I removed it? :)
For the snippet directory to work. The removed code assumed that the user had VS code and vetur extension installed. What if the user didn't had VS Code, or vetur? :)

One solution could be to have a folder like this one in this repo, and to point globalSnippetDir to that folder. What do you think?

This comment has been minimized.

Copy link
@rchl

rchl Sep 30, 2019

Member

It is possible, you can specify your own snippet directory like so:

Yes, but now every user has to set the path manually in settings. Previously it automatically pointed to specific path in the home directory.

Why I removed it? :)
For the snippet directory to work.

I've reported that and they fixed it - vuejs/vetur#1421
With the fix, not providing a path to global snippets still allows project-specific ones to work.
EDIT: Hmm, maybe you didn't mean that bug...? Yes, directory path was quite specific to VSCode and vetur but it wouldn't break anything if directory didn't exist.

One solution could be to have a folder like this one in this repo, and to point globalSnippetDir to that folder.

I think we had a proper solution before when we computed the path to the home directory. I think global snippets should be stored in the home directory, as they were intended to. I'm not sure if that's important to anyone, but one advantage is that VSCode and sublime can share them then.

This comment has been minimized.

Copy link
@rchl

rchl Sep 30, 2019

Member

Maybe the best solution would be to support expanding home directory in LSP settings. Then it could be solved with generic path in sublime-settings settings.

"""
Returns default global directory for user's snippets.
Uses same logic and paths as vetur.
See https://github.com/vuejs/vetur/blob/master/client/userSnippetDir.ts
"""
appName = 'Code'
if sublime.platform() == 'windows':
return os.path.expandvars('%%APPDATA%%\\{}\\User\\snippets\\vetur').format(appName)
elif sublime.platform() == 'osx':
return os.path.expanduser('~/Library/Application Support/{}/User/snippets/vetur').format(appName)
else:
return os.path.expanduser('~/.config/{}/User/snippets/vetur').format(appName)

def update_to_new_configuration(settings, old_config, new_config):
# add old config to new config
new_config['initializationOptions']['config'] = old_config
settings.set('client', new_config)
# remove old config
settings.erase('config')
sublime.save_settings("LSP-vue.sublime-settings")

class LspVuePlugin(LanguageHandler):
@property
Expand All @@ -89,34 +81,34 @@ def name(self) -> str:
@property
def config(self) -> ClientConfig:
settings = sublime.load_settings("LSP-vue.sublime-settings")
config = settings.get('config')
globalSnippetDir = settings.get('globalSnippetDir', getGlobalSnippetDir())
view = sublime.active_window().active_view()
if view is not None:
config['vetur']['format']['options']['tabs_size'] = view.settings().get("tab_size", 4)
config['vetur']['format']['options']['useTabs'] = not view.settings().get("translate_tabs_to_spaces", False)
return ClientConfig(
name='lsp-vue',
binary_args=[
# TODO: remove update_to_new_configuration after 1 November.
old_config = settings.get('config')
client_configuration = settings.get('client')
if old_config:
update_to_new_configuration(settings, old_config, client_configuration)

default_configuration = {
"command": [
'node',
server_path
server_path,
'--stdio'
],
tcp_port=None,
enabled=True,
init_options={
"config": config,
"globalSnippetDir": globalSnippetDir
},
settings=dict(),
env=dict(),
languages=[
LanguageConfig(
'vue',
['text.html.vue'],
["Packages/Vue Syntax Highlight/Vue Component.sublime-syntax"]
)
"languages": [
{
"languageId": "vue",
"scopes": ["text.html.vue"],
"syntaxes": ["Packages/Vue Syntax Highlight/Vue Component.sublime-syntax"]
}
]
)
}
default_configuration.update(client_configuration)
view = sublime.active_window().active_view()
if view is not None:
options = default_configuration['initializationOptions']['config']['vetur']['format']['options']
options['tabSize'] = view.settings().get("tab_size", 4)
options['useTabs'] = not view.settings().get("translate_tabs_to_spaces", False)

return read_client_config('lsp-vue', default_configuration)

def on_start(self, window) -> bool:
if not is_node_installed():
Expand Down

0 comments on commit 5b37870

Please sign in to comment.