Skip to content

Commit

Permalink
start over
Browse files Browse the repository at this point in the history
  • Loading branch information
alihsaas committed Sep 21, 2021
0 parents commit b3f9ec1
Show file tree
Hide file tree
Showing 8 changed files with 1,612 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
log/
out/
vscode-lua-*/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Raoul Wols

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 10 additions & 0 deletions LSP-robloxluau.sublime-commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"caption": "Preferences: LSP-robloxluau Settings",
"command": "edit_settings",
"args": {
"base_file": "${packages}/LSP-robloxluau/LSP-robloxluau.sublime-settings",
"default": "// Settings in here override those in \"LSP-robloxluau/LSP-robloxluau.sublime-settings\"\n{\n\t$0\n}\n"
}
}
]
156 changes: 156 additions & 0 deletions LSP-robloxluau.sublime-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{
// possible values: en-US, zh-CN
"locale": "en-US",

// The startup command for this language server
"command": [
"${storage_path}/LSP-robloxluau/bin/${binplatform}/lua-language-server",
"-E",
"-e",
"LANG=\"${locale}\"",
"${storage_path}/LSP-robloxluau/main.lua"
],

// The server version to download in $CACHE/Package Storage
"server_version": "1.3.0",

// Disable the trigger characters, because there's too many of them. The
// default Lua syntax is capable enough to best decide when to trigger
// the auto-complete widget.
"disabled_capabilities": {
"completionProvider": {
"triggerCharacters": true
}
},

// We start this server when opening a lua file
"selector": "source.lua",

// The server-specific settings
"settings": {
// Color mode.
// possible values: Grammar, Semantic
"Lua.color.mode": "Grammar",
// When the input looks like a file name, automatically `require` this file.
"Lua.completion.autoRequire": true,
// Shows function call snippets.
// possible values: Disable, Both, Replace
"Lua.completion.callSnippet": "Disable",
// Previewing the relevant code snippet of the suggestion may help you understand the usage
// of the suggestion. The number set indicates the number of intercepted lines in the code
// fragment. If it is set to `0`, this feature can be disabled.
"Lua.completion.displayContext": 6,
// Enable completion.
"Lua.completion.enable": true,
// Shows keyword syntax snippets.
// possible values: Disable, Both, Replace
"Lua.completion.keywordSnippet": "Replace",
// Display parameters in completion list. When the function has multiple definitions, they
// will be displayed separately.
"Lua.completion.showParams": true,
// Shows words within the workspace.
"Lua.completion.workspaceWord": true,
// Disabled diagnostic (Use code in hover brackets).
"Lua.diagnostics.disable": [],
// Enable diagnostics.
"Lua.diagnostics.enable": true,
// Defined global variables.
"Lua.diagnostics.globals": [],
// If you want to check only opened files, choice Opened; else choice Any.
"Lua.diagnostics.neededFileStatus": {},
// Modified diagnostic severity.
"Lua.diagnostics.severity": {},
// Latency (milliseconds) for workspace diagnostics. When you start the workspace, or edit
// any file, the entire workspace will be re-diagnosed in the background. Set to negative to
// disable workspace diagnostics.
"Lua.diagnostics.workspaceDelay": 0,
// Workspace diagnostics run rate (%). Decreasing this value reduces CPU usage, but also
// reduces the speed of workspace diagnostics. The diagnosis of the file you are currently
// editing is always done at full speed and is not affected by this setting.
"Lua.diagnostics.workspaceRate": 100,
// Enabel hint.
"Lua.hint.enable": false,
// Hint parameter name when the parameter called is literal.
"Lua.hint.paramName": true,
// Show type hints at the parameter of the function.
"Lua.hint.paramType": true,
// Hint type at assignment operation.
"Lua.hint.setType": false,
// Enable hover.
"Lua.hover.enable": true,
// When the value corresponds to multiple types, limit the number of types displaying.
"Lua.hover.enumsLimit": 5,
// When hovering to view a table, limits the maximum number of previews for fields.
"Lua.hover.previewFields": 20,
// Hover to view numeric content (only if literal is not decimal).
"Lua.hover.viewNumber": true,
// Hover to view the contents of a string (only if the literal contains an escape
// character).
"Lua.hover.viewString": true,
// The maximum length of a hover to view the contents of a string.
"Lua.hover.viewStringMax": 1000,
// Adjust the enabled state of the built-in library. You can disable (or redefine) the non-
// existent library according to the actual runtime environment.
// * `default`: Indicates that the library will be enabled or disabled according to the
// runtime version
// * `enable`: always enable
// * `disable`: always disable
"Lua.runtime.builtin": {},
// File encoding. The `ansi` option is only available under the `Windows` platform.
// possible values: utf8, ansi
"Lua.runtime.fileEncoding": "utf8",
// Supports non-standard symbols. Make sure that your runtime environment supports these
// symbols.
"Lua.runtime.nonstandardSymbol": [],
// `package.path`
"Lua.runtime.path": [
"?.lua",
"?/init.lua",
"?/?.lua"
],
// Plugin path. Please read [wiki](https://github.com/sumneko/lua-language-
// server/wiki/Plugin) to learn more.
"Lua.runtime.plugin": "",
// The custom global variables are regarded as some special built-in variables, and the
// language server will provide special support
// The following example shows that 'include' is treated as' require '.
// ```json
// "Lua.runtime.special" : {
// "include" : "require"
// }
// ```
"Lua.runtime.special": {},
// Allows Unicode characters in name.
"Lua.runtime.unicodeName": false,
// Lua runtime version.
// possible values: Lua 5.1, Lua 5.2, Lua 5.3, Lua 5.4, LuaJIT
"Lua.runtime.version": "Lua 5.4",
// Enable signature help.
"Lua.signatureHelp.enable": true,
// Enable telemetry to send your editor information and error logs over the network. Read
// our privacy policy [here](https://github.com/sumneko/lua-language-server/wiki/Privacy-
// Policy).
"Lua.telemetry.enable": false,
// Show progress bar in status bar.
"Lua.window.progressBar": true,
// Ignored files and directories (Use `.gitignore` grammar).
"Lua.workspace.ignoreDir": [
".vscode"
],
// Ignore submodules.
"Lua.workspace.ignoreSubmodules": true,
// The directory path of the external function library.
// The language service will additionally load the lua files in these directories, even if
// they are not in the current workspace, for definition, completion and other features.
"Lua.workspace.library": [],
// Max preloaded files.
"Lua.workspace.maxPreload": 1000,
// Skip files larger than this value (KB) when preloading.
"Lua.workspace.preloadFileSize": 100,
// Ignore files list in `.gitignore` .
"Lua.workspace.useGitIgnore": true,
// Add private third-party library configuration file paths here, please refer to the built-
// in [configuration file path](https://github.com/sumneko/lua-language-server/tree/master/meta/3rd)
"Lua.workspace.userThirdParty": [],
}
}
21 changes: 21 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 最萌小汐

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# LSP-robloxluau

A language client for RobloxLuau. This package will download and unpack the robloxluau-language-server in `$DATA/Package Storage/LSP-robloxluau`.

To use this package, you must have:

- The [LSP](https://packagecontrol.io/packages/LSP) package.

# Applicable Selectors

This language server operates on files with the `source.lua` base scope.

# Configuration

Run `Preferences: LSP-robloxluau Settings` from the Command Palette.

# Locale

You can make this language server report documentation in English or Chinese. The default is English. To change it
into Chinese, run the command `Preferences: LSP-robloxluau Settings` and change the `"locale"` key.

# Disabling Diagnostics via Code Actions

This language server allows you to disable diagnostics by means of a Code Action. You can run the "Code Action" and the client (this package) is supposed to modify the settings to add or remove the unwanted diagnostic. This package implements that by editing your .sublime-project file. So in order for this to work, you need to have your window be backed by a .sublime-project file. [Learn more about projects here](https://www.sublimetext.com/docs/projects.html).
145 changes: 145 additions & 0 deletions plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
from LSP.plugin import AbstractPlugin
from LSP.plugin import register_plugin
from LSP.plugin import unregister_plugin
from LSP.plugin import DottedDict
from LSP.plugin.core.typing import Any, Callable, List, Dict, Mapping, Optional, Tuple
import sublime
import os
import urllib.request
import zipfile
import shutil
import tempfile


URL = "https://github.com/NightrainsRbx/RobloxLsp/releases/download/v{0}/robloxlsp-{0}.vsix"


class RobloxLuau(AbstractPlugin):
@classmethod
def name(cls) -> str:
return "LSP-{}".format(cls.__name__.lower())

@classmethod
def basedir(cls) -> str:
return os.path.join(cls.storage_path(), cls.name())

@classmethod
def version_file(cls) -> str:
return os.path.join(cls.basedir(), "VERSION")

@classmethod
def zipfile(cls) -> str:
return os.path.join(cls.basedir(), "robloxlsp.vsix")

@classmethod
def binplatform(cls) -> str:
return {
"linux": "Linux",
"windows": "Windows",
"osx": "macOS"
}[sublime.platform()]

@classmethod
def bindir(cls) -> str:
return os.path.join(cls.basedir(), "bin", cls.binplatform())

@classmethod
def needs_update_or_installation(cls) -> bool:
settings, _ = cls.configuration()
server_version = str(settings.get("server_version"))
try:
with open(cls.version_file(), "r") as fp:
return server_version != fp.read().strip()
except OSError:
return True

@classmethod
def install_or_update(cls) -> None:
shutil.rmtree(cls.basedir(), ignore_errors=True)
try:
settings, _ = cls.configuration()
server_version = str(settings.get("server_version"))
binplatform = cls.binplatform()
with tempfile.TemporaryDirectory() as tmp:
# Download the VSIX file
zip_file = os.path.join(tmp, "robloxlsp.vsix")
urllib.request.urlretrieve(URL.format(server_version), zip_file)
# VSIX files are just zipfiles
with zipfile.ZipFile(zip_file, "r") as z:
z.extractall(tmp)
for root, dirs, files in os.walk(os.path.join(tmp, "extension", "server", "bin")):
for d in dirs:
if d != binplatform:
shutil.rmtree(os.path.join(root, d))
for root, dirs, files in os.walk(os.path.join(tmp, "extension", "server", "bin", binplatform)):
for file in files:
os.chmod(os.path.join(root, file), 0o744)
# Make sure package storage path exists for new users
os.makedirs(cls.storage_path(), exist_ok=True)
# Move the relevant subdirectory to the package storage
shutil.move(os.path.join(tmp, "extension", "server"), cls.basedir())
# Write the version stamp
with open(cls.version_file(), "w") as fp:
fp.write(server_version)
except Exception:
shutil.rmtree(cls.basedir(), ignore_errors=True)
raise

@classmethod
def configuration(cls) -> Tuple[sublime.Settings, str]:
base_name = "{}.sublime-settings".format(cls.name())
file_path = "Packages/{}/{}".format(cls.name(), base_name)
return sublime.load_settings(base_name), file_path

@classmethod
def additional_variables(cls) -> Optional[Dict[str, str]]:
settings, _ = cls.configuration()
return {
"binplatform": {
"linux": "Linux",
"windows": "Windows",
"osx": "macOS"
}[sublime.platform()],
"locale": str(settings.get("locale"))
}

def on_pre_server_command(self, command: Mapping[str, Any], done_callback: Callable[[], None]) -> bool:
cmd = command["command"]
if cmd == "robloxluau.config":
return self._handle_robloxluau_config_command(command["arguments"], done_callback)
return super().on_pre_server_command(command, done_callback)

def _handle_robloxluau_config_command(self, args: List[Dict[str, Any]], done_callback: Callable[[], None]) -> bool:
action = args[0]["action"]
if action == "add":
key = args[0]["key"]
value = args[0]["value"]
session = self.weaksession()
if not session:
return False
window = session.window
data = window.project_data()
if not isinstance(data, dict):
return False
dd = DottedDict(data)
key = "settings.LSP.LSP-robloxluau.settings.{}".format(key)
thelist = dd.get(key)
if isinstance(thelist, list):
if value not in thelist:
thelist.append(value)
else:
thelist = [value]
dd.set(key, thelist)
data = dd.get()
window.set_project_data(data)
done_callback()
return True
return False


def plugin_loaded() -> None:
register_plugin(RobloxLuau)


def plugin_unloaded() -> None:
unregister_plugin(RobloxLuau)
Loading

0 comments on commit b3f9ec1

Please sign in to comment.