Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed .no-sublime-package
Empty file.
10 changes: 10 additions & 0 deletions LSP-html.sublime-commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"caption": "Preferences: LSP-html Settings",
"command": "edit_settings",
"args": {
"base_file": "${packages}/LSP-html/LSP-html.sublime-settings",
"default": "// Settings in here override those in \"LSP-html/LSP-html.sublime-settings\",\n\n{\n\t$0\n}\n"
}
},
]
45 changes: 29 additions & 16 deletions LSP-html.sublime-settings
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
{
"client" : {
"enabled": true,
"languages": [
{
"languageId": "html",
"scopes": ["text.html.basic"],
"syntaxes": [
"Packages/HTML/HTML.sublime-syntax",
"Packages/PHP/PHP.sublime-syntax"
]
}
],
"initializationOptions": {},
"settings": {}
}
}
"enabled": true,
"languages": [
{
"languageId": "html",
"scopes": [
"text.html.basic",
],
"syntaxes": [
"Packages/HTML/HTML.sublime-syntax",
"Packages/PHP/PHP.sublime-syntax",
],
},
],
"initializationOptions": {
"provideFormatter": true,
"embeddedLanguages": {
"css": true,
"html": true,
"javascript": true,
},
},
"settings": {
"html": {
"format": {
"enable": true,
},
},
},
}
22 changes: 11 additions & 11 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
"command": "edit_settings",
"args": {
"base_file": "${packages}/LSP-html/LSP-html.sublime-settings",
"default": "{\n\t$0\n}\n"
}
}
]
}
]
}
]
}
]
}
"default": "// Settings in here override those in \"LSP-html/LSP-html.sublime-settings\",\n\n{\n\t$0\n}\n",
},
},
],
},
],
},
],
},
],
},
]
8 changes: 8 additions & 0 deletions dependencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"*": {
"*": [
"lsp_utils",
"sublime_lib"
]
}
}
108 changes: 0 additions & 108 deletions package-lock.json

This file was deleted.

22 changes: 0 additions & 22 deletions package.json

This file was deleted.

116 changes: 46 additions & 70 deletions plugin.py
Original file line number Diff line number Diff line change
@@ -1,97 +1,73 @@
import shutil
import os
import sublime
import threading
import subprocess

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

PACKAGE_NAME = 'LSP-html'
SETTINGS_FILENAME = 'LSP-html.sublime-settings'
SERVER_DIRECTORY = 'vscode-html'
SERVER_BINARY_PATH = os.path.join(SERVER_DIRECTORY, 'out', 'htmlServerMain.js')

server = ServerNpmResource(PACKAGE_NAME, SERVER_DIRECTORY, SERVER_BINARY_PATH)

package_path = os.path.dirname(__file__)
server_path = os.path.join(package_path, 'node_modules', 'vscode-html-languageserver-bin', 'htmlServerMain.js')

def plugin_loaded():
is_server_installed = os.path.isfile(server_path)
print('LSP-html: Server {} installed.'.format('is' if is_server_installed else 'is not' ))

# install the node_modules if not installed
if not is_server_installed:
# this will be called only when the plugin gets:
# - installed for the first time,
# - or when updated on package control
logAndShowMessage('LSP-html: Installing server.')

runCommand(
onCommandDone,
["npm", "install", "--verbose", "--prefix", package_path, package_path]
)


def onCommandDone():
logAndShowMessage('LSP-html: Server installed.')


def runCommand(onExit, popenArgs):
"""
Runs the given args in a subprocess.Popen, and then calls the function
onExit when the subprocess completes.
onExit is a callable object, and popenArgs is a list/tuple of args that
would give to subprocess.Popen.
"""
def runInThread(onExit, popenArgs):
try:
if sublime.platform() == 'windows':
subprocess.check_call(popenArgs, shell=True)
else:
subprocess.check_call(popenArgs)
onExit()
except subprocess.CalledProcessError as error:
logAndShowMessage('LSP-html: Error while installing the server.', error)
return
thread = threading.Thread(target=runInThread, args=(onExit, popenArgs))
thread.start()
# returns immediately after the thread starts
return thread
server.setup()


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


def logAndShowMessage(msg, additional_logs=None):
print(msg, '\n', additional_logs) if additional_logs else print(msg)
sublime.active_window().status_message(msg)
def is_node_installed():
return shutil.which('node') is not None


class LspHtmlPlugin(LanguageHandler):
@property
def name(self) -> str:
return 'lsp-html'
return PACKAGE_NAME.lower()

@property
def config(self) -> ClientConfig:
settings = sublime.load_settings("LSP-html.sublime-settings")
client_configuration = settings.get('client')
# 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()

configuration = self.migrate_and_read_configuration()

default_configuration = {
"command": [
'node',
server_path,
'--stdio'
],
"languages": [
{
"languageId": "html",
"scopes": ["text.html.basic"],
"syntaxes": [
"Packages/HTML/HTML.sublime-syntax",
"Packages/PHP/PHP.sublime-syntax"
]
}
]
'enabled': True,
'command': ['node', server.binary_path, '--stdio'],
}
default_configuration.update(client_configuration)

default_configuration.update(configuration)

return read_client_config('lsp-html', 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 HTML Language Server to work.')
Expand Down
4 changes: 4 additions & 0 deletions vscode-html/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules/

# downloaded source codes
/vscode-html-languageserver/
11 changes: 11 additions & 0 deletions vscode-html/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This repo contains built [vscode-html-languageserver](https://github.com/vscode-langservers/vscode-html-languageserver).


# Build

Just run `compile-vscode-html-languageserver.sh`. The built result will be in `out/`.


# References

- https://github.com/mattn/vim-lsp-settings/pull/48
Loading