Skip to content

Commit

Permalink
Switch to NpmClientHandler
Browse files Browse the repository at this point in the history
Also added defaults for css configuration so that it's easier for users
to customize.
  • Loading branch information
rchl authored and predragnikolic committed May 2, 2020
1 parent 077e48b commit a82d0cd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 72 deletions.
2 changes: 1 addition & 1 deletion LSP-vue.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"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"
"default": "// Settings in here override those in \"LSP-vue/LSP-vue.sublime-settings\"\n\n{\n\t$0\n}\n"
}
},
]
32 changes: 31 additions & 1 deletion LSP-vue.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,37 @@
"template": true,
},
},
"css": {},
"css": {
"validate": true,
"completion": {
"triggerPropertyValueCompletion": true,
"completePropertyWithSemicolon": true,
},
"customData": [],
"lint": {
"compatibleVendorPrefixes": "ignore",
"vendorPrefix": "warning",
"duplicateProperties": "ignore",
"emptyRules": "warning",
"importStatement": "ignore",
"boxModel": "ignore",
"universalSelector": "ignore",
"zeroUnits": "ignore",
"fontFaceProperties": "warning",
"hexColorLength": "error",
"argumentsInColorFunction": "error",
"unknownProperties": "warning",
"validProperties": [],
"ieHack": "ignore",
"unknownVendorSpecificProperties": "ignore",
"propertyIgnoredDueToDisplay": "warning",
"important": "ignore",
"float": "ignore",
"idSelector": "ignore",
"unknownAtRules": "warning",
},

},
"emmet": {},
"stylusSupremacy": {},
"html": {
Expand Down
2 changes: 1 addition & 1 deletion Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"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"
"default": "// Settings in here override those in \"LSP-vue/LSP-vue.sublime-settings\"\n\n{\n\t$0\n}\n"
}
}
]
Expand Down
78 changes: 9 additions & 69 deletions plugin.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,26 @@
import os
import shutil
import sublime

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

PACKAGE_NAME = 'LSP-vue'
SETTINGS_FILENAME = 'LSP-vue.sublime-settings'
SERVER_DIRECTORY = 'server'
SERVER_BINARY_PATH = os.path.join(SERVER_DIRECTORY, 'node_modules', 'vue-language-server', 'bin', 'vls')

server = ServerNpmResource(PACKAGE_NAME, SERVER_DIRECTORY, SERVER_BINARY_PATH)
from lsp_utils import NpmClientHandler


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


def plugin_unloaded():
server.cleanup()


def is_node_installed():
return shutil.which('node') is not None


class LspVuePlugin(LanguageHandler):
@property
def name(self) -> str:
return PACKAGE_NAME.lower()

@property
def config(self) -> ClientConfig:
# Calling setup() also here as this might run before `plugin_loaded`.
# Will be a no-op if already ran.
# See https://github.com/sublimelsp/LSP/issues/899
server.setup()
LspVuePlugin.cleanup()

configuration = self.migrate_and_read_configuration()

default_configuration = {
'enabled': True,
'command': ['node', server.binary_path, '--stdio'],
}

default_configuration.update(configuration)
class LspVuePlugin(NpmClientHandler):
package_name = __package__
server_directory = 'server'
server_binary_path = os.path.join(server_directory, 'node_modules', 'vue-language-server', 'bin', 'vls')

def on_client_configuration_ready(self, configuration: dict):
view = sublime.active_window().active_view()
if view:
view_settings = view.settings()
default_configuration \
configuration \
.setdefault('initializationOptions', {}) \
.setdefault('config', {}) \
.setdefault('vetur', {}) \
Expand All @@ -60,33 +30,3 @@ def config(self) -> ClientConfig:
'tabSize': view_settings.get('tab_size', 4),
'useTabs': not view_settings.get('translate_tabs_to_spaces', False)
})

return read_client_config(self.name, default_configuration)

def migrate_and_read_configuration(self) -> dict:
settings = {}
loaded_settings = sublime.load_settings(SETTINGS_FILENAME)

if loaded_settings:
if loaded_settings.has('client'):
client = loaded_settings.get('client')
loaded_settings.erase('client')
# Migrate old keys
for key in client:
loaded_settings.set(key, client[key])
sublime.save_settings(SETTINGS_FILENAME)

# Read configuration keys
for key in ['languages', 'initializationOptions', 'settings']:
settings[key] = loaded_settings.get(key)

return settings

def on_start(self, window) -> bool:
if not is_node_installed():
sublime.status_message('Please install Node.js for the Vue Language Server to work.')
return False
return server.ready

def on_initialized(self, client) -> None:
pass # extra initialization here.

0 comments on commit a82d0cd

Please sign in to comment.