williamboman / nvim-lsp-installer

Further development has moved to https://github.com/williamboman/mason.nvim!
https://github.com/williamboman/mason.nvim
Apache License 2.0
2k stars 123 forks source link

[New server]: LuaHelper #328

Open younger-1 opened 2 years ago

younger-1 commented 2 years ago

Which server would you like to request to be added? Server name: luahelper Server homepage (e.g., GitHub page): https://github.com/Tencent/LuaHelper

Which languages does this server target? Languages: lua

Feature Compared with other Lua plugins currently on the market, it has the following improvements:

  1. Coroutine development, real-time detection, millisecond output detection results
  2. Support large-scale Lua projects, perfectly support editing and testing of 1000+ file project
  3. Comprehensive error type detection, including: grammar detection, semantic detection
  4. Various types of reference search, including: multi-file reference search, multi-layer reference search
  5. Rich configurable items, including: multiple alarm information configurations, ignorable file settings
  6. Low memory consumption, low-performance machines can still run smoothly
williamboman commented 2 years ago

Hello! Cool, wasn't aware of that implementation. Does this server exist in lspconfig (I couldn't find it)? It's a prerequisite for adding it in this plugin, so a good first step would be to add it there. I might make time pretty soon to look into this myself as it looks pretty interesting, but as always PRs are welcome!

younger-1 commented 2 years ago

Here are some infomation came from installing luahelper in vscode.

  1. the size of luahelper is 62M, sumneko_lua only need 14M.
  2. the binary has differnet name in each platform
  3. it support standalone configuration file luahelper.json (https://github.com/Tencent/LuaHelper/blob/master/docs/manual/config.md)
  4. the configuration to lsp is not complete in both cli option and vscode extension settings
> dust
 1.5M       ┌── mac                │                                                                                                   ░▒▒▒▒▒▒▒▒▒▒███ │   2%
 620K       │ ┌── lua5.1           │                                                                                                   ░▒▒▒▒▒▒▒▒▓▓▓██ │   1%
 638K       │ ├── lua5.2           │                                                                                                   ░▒▒▒▒▒▒▒▒▓▓▓██ │   1%
 665K       │ ├── lua5.3           │                                                                                                   ░▒▒▒▒▒▒▒▒▓▓▓██ │   1%
 695K       │ ├── lua5.4           │                                                                                                   ░▒▒▒▒▒▒▒▒▓▓▓██ │   1%
 2.6M       ├─┴ linux              │                                                                                                   ░▒▒▒▒▒▒▒▒█████ │   4%
 597K       │ ┌── x86              │                                                                                                   ░▒▒▒▒▒▒▒▓▓▓▓██ │   1%
 636K       │ │ ┌── lua5.3         │                                                                                                   ░▒▒▒▒▒▒▒▓▓▓▓██ │   1%
 664K       │ │ ├── lua5.4         │                                                                                                   ░▒▒▒▒▒▒▒▓▓▓▓██ │   1%
 2.3M       │ ├─┴ x64              │                                                                                                   ░▒▒▒▒▒▒▒▓█████ │   4%
 2.9M       ├─┴ win                │                                                                                                   ░▒▒▒▒▒▒▒██████ │   5%
 7.0M     ┌─┴ luasocket            │                                                                                                   ░█████████████ │  11%
 7.4M   ┌─┴ debugger               │                                                                                                   ██████████████ │  12%
 653K   │ ┌── markdown-it          │                                                                               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██ │   1%
 1.0M   │ ├── underscore           │                                                                               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██ │   2%
 1.7M   │ ├── lodash               │                                                                               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████ │   3%
 1.5M   │ │ ┌── interfaces         │                                                                               ░░░░░░░░░░░░░░░░░░░░░░░░░░▒▒▒▒▒███ │   2%
 4.0M   │ ├─┴ azure-devops-node-api│                                                                               ░░░░░░░░░░░░░░░░░░░░░░░░░░████████ │   6%
  18M   ├─┴ node_modules           │                                                                               ██████████████████████████████████ │  29%
 1.3M   │   ┌── lua-format.exe     │                                               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███ │   2%
 1.3M   │ ┌─┴ win32                │                                               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███ │   2%
 1.9M   │ │ ┌── lua-format         │                                               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████ │   3%
 1.9M   │ ├─┴ darwin               │                                               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████ │   3%
 3.1M   │ │ ┌── lua-format         │                                               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████ │   5%
 3.1M   │ ├─┴ linux                │                                               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████ │   5%
 9.0M   │ ├── maclualsp            │                                               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████████████ │  14%
 9.1M   │ ├── lualsp.exe           │                                               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████████████ │  15%
  11M   │ ├── linuxlualsp          │                                               ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████████████████ │  18%
  36M   ├─┴ server                 │                                               ██████████████████████████████████████████████████████████████████ │  58%
  62M ┌─┴ .                        │█████████████████████████████████████████████████████████████████████████████████████████████████████████████████ │ 100%
> .\server\lualsp.exe --help
Usage of C:\Users\younger\.vscode\extensions\yinfei.luahelper-0.2.9\server\lualsp.exe:
  -localpath string
        local project path
  -logflag int
        0 is not open log, 1 is open log
  -mode int
        mode type, 0 is run cmd, 1 is local rpc, 2 is socket rpc
younger-1 commented 2 years ago

@williamboman I can't find a way to add it to lspconfig for now. May be the luahelper need more time to delivery a more available binary, as the core developer(@yinfei8) said they are refactoring the underlying architecture of luahelper.

younger-1 commented 2 years ago

luahelper's supported lsp settings:

{
    "luahelper.source.roots": "Source roots of your project",
    "luahelper.run.mode": "Way to read the configuration: read luahelper.json under each vscode project, or read the settings of the plugin",
    "luahelper.run.json": "read luahelper.json under each vscode project",
    "luahelper.run.setting": "read the overall settings of the plugin",
    "luahelper.source.rootdir": "plugin root project dir",
    "luahelper.reference.maxNum": "Maximum number of references show",
    "luahelper.run.lsp": "connect lsp server way",
    "luahelper.run.cmdrpc": "local rmd rpc",
    "luahelper.run.socketrpc": "local socket rpc(default)",
    "luahelper.project.requirePathSeparator": "require other file path's separator, default is . , Example: require('one.bb')",
    "luahelper.project.requirePathSeparator1": "default is . Example: require('one.bb')",
    "luahelper.project.requirePathSeparator2": "set as / Example: require('one/bb')",
    "luahelper.format.errShow": "If the format is wrong, whether to display the error",
    "luahelper.reference.incudeDefine": "Whether to include definitions when displaying references",
    "luahelper.lspserver.log": "Whether to open lsp server log",
    "luahelper.colors.Enable": "Enable Global Highligth Color",
    "luahelper.colors.globalfield": "Global Var Color setting",
    "luahelper.colors.globalfun": "Global Fun Color setting",
    "luahelper.show.online": "Show online people number",
    "luahelper.show.costTime": "Show plugin startup time",
    "luahelper.colors.annotatetype": "Annotate Type Color",
    "luahelper.Warn.AllEnable": "Check warn is all enable)",
    "luahelper.Warn.CheckSyntax": "[Warn Type:1], basic synctax check",
    "luahelper.Warn.CheckNoDefine": "[Warn Type:2], var not define check",
    "luahelper.Warn.CheckAfterDefine": "[Warn Type:3], var define after use",
    "luahelper.Warn.CheckLocalNoUse": "[Warn Type:4], local var define not use",
    "luahelper.Warn.CheckTableDuplicateKey": "[Warn Type:5], table define duplicate key",
    "luahelper.Warn.CheckReferNoFile": "[Warn Type:6], refer file not exist",
    "luahelper.Warn.CheckAssignParamNum": "[Warn Type:7], assign statement param num error",
    "luahelper.Warn.CheckLocalDefineParamNum": "[Warn Type:8], local define statement param num error",
    "luahelper.Warn.CheckGotoLable": "[Warn Type:9], goto statement find label error",
    "luahelper.Warn.CheckFuncParam": "[Warn Type:10], function call param num error",
    "luahelper.Warn.CheckImportModuleVar": "[Warn Type:11], import other file, not find module var",
    "luahelper.Warn.CheckIfNotVar": "[Warn Type:12], if not var statement, call var member error",
    "luahelper.Warn.CheckFunctionDuplicateParam": "[Warn Type:13], function define duplicate param",
    "luahelper.Warn.CheckBinaryExpressionDuplicate": "[Warn Type:14], binary expression, two sides are the same",
    "luahelper.Warn.CheckErrorOrAlwaysTrue": "[Warn Type:15], or expression is always true",
    "luahelper.Warn.CheckErrorAndAlwaysFalse": "[Warn Type:16], and expression is always false",
    "luahelper.Warn.CheckNoUseAssign": "[Warn Type:17], local var define not use, but assign",
    "luahelper.Warn.CheckAnnotateType": "[Warn Type:18], check annotate error",
    "luahelper.Warn.CheckDuplicateIf": "[Warn Type:19], duplicate if condition",
    "luahelper.Warn.CheckSelfAssign": "[Warn Type:20], assign self",
    "luahelper.Warn.CheckFloatEq": "[Warn Type:21], equal to float",
    "luahelper.project.IgnoreFileOrDir": "Ignore analysis files and directories. Sample:one11.lua , indicates to ignore files; .vscode/ , indicates to ignore directories.",
    "luahelper.project.IgnoreFileOrDirErrors": "Ignored file and directory errors. Sample: one11.lua,  indicates to ignore file errors, .vscode/ , indicates to ignore directory errors.",
    "luahelper.format.allReadMe": "Read all formatting settings [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md).\n",
    "luahelper.format.column_limit": "Column limit of one line [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#column_limit).\n",
    "luahelper.format.indent_width": "The number of spaces used for indentation [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#indent_width).\n",
    "luahelper.format.use_tab": "Use tab for indent [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#use_tab).\n",
    "luahelper.format.tab_width": "The number of spaces used for tab",
    "luahelper.format.continuation_indent_width": "Indent width for continuations line [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#continuation_indent_width).\n",
    "luahelper.format.keep_simple_control_block_one_line": "Allow format simple control block(e.g., if, while, for, ...) to one line [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#keep_simple_control_block_one_line).\n",
    "luahelper.format.keep_simple_function_one_line": "Allow format simple function to one line [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#keep_simple_function_one_line).\n",
    "luahelper.format.align_args": "Align arguments of a function call if there is a line break. If false, use continuation_indent_width to indentation [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#align_args).\n",
    "luahelper.format.break_after_functioncall_lp": "Break after '(' of function call if columns greater than column_limit [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#break_after_functioncall_lp).\n",
    "luahelper.format.break_before_functioncall_rp": "Break before ')' of function call if columns greater than column_limit [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#break_before_functioncall_rp).\n",
    "luahelper.format.align_parameter": "Align parameter of function define if there is a line break. if false, use continuation_indent_width to indentation [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#align_parameter).\n",
    "luahelper.format.chop_down_parameter": "Chop down all parameters if the function declaration doesn’t fit on a line [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#chop_down_parameter).\n",
    "luahelper.format.break_after_functiondef_lp": "Break after '(' of function define if columns greater than column_limit [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#break_after_functiondef_lp).\n",
    "luahelper.format.break_before_functiondef_rp": "Break before ')' of function define if columns greater than column_limit [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#break_before_functiondef_rp).\n",
    "luahelper.format.align_table_field": "Align fields of a table if there is a line break. if false, use indent_width to indentation [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#align_table_field).\n",
    "luahelper.format.break_after_table_lb": "Break after '{' of a table if columns greater than column_limit [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#break_after_table_lb).\n",
    "luahelper.format.break_before_table_rb": "Break before '}' of a table if columns greater than column_limit [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#break_before_table_rb).\n",
    "luahelper.format.chop_down_table": "Chop down any table [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#chop_down_table).\n",
    "luahelper.format.chop_down_kv_table": "Chop down table if a table contains a key [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#chop_down_kv_table).\n",
    "luahelper.format.column_table_limit": "The column limit of each line of a table. Default value the same as column_limit value [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#column_table_limit).\n",
    "luahelper.format.table_sep": "Define character to separate table fields [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#table_sep).\n",
    "luahelper.format.extra_sep_at_table_end": "Add an extra field separator after the last field unless the table is in a single line [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#extra_sep_at_table_end).\n",
    "luahelper.format.break_after_operator": "Put break after operators if columns greater than column_limit. If false, put break before operators [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#break_after_operator).\n",
    "luahelper.format.single_quote_to_double_quote": "Transform string literals to use double quotes [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#single_quote_to_double_quote).\n",
    "luahelper.format.double_quote_to_single_quote": "Transform string literals to use a single quote [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#double_quote_to_single_quote).\n",
    "luahelper.format.spaces_before_call": "Inserts a space on function calls with parentheses omitted [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#spaces_before_call).\n",
    "luahelper.format.spaces_inside_functiondef_parens": "Inserts spaces inside the parenthesis in a function header [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#spaces_inside_functiondef_parens).\n",
    "luahelper.format.spaces_inside_functioncall_parens": "Inserts spaces inside the parenthesis in a function call [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#spaces_inside_functioncall_parens).\n",
    "luahelper.format.spaces_inside_table_braces": "Inserts spaces inside the braces in a table constructor [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#spaces_inside_table_braces).\n",
    "luahelper.format.spaces_around_equals_in_field": "Inserts spaces around the equal sign in key/value fields. Other assignments are not affected, though they may be affected by other options or behavior of the formatter [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#spaces_around_equals_in_field).\n",
    "luahelper.format.line_breaks_after_function_body": "Line breaks after the function body [here](https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md#line_breaks_after_function_body).\n",
    "luahelper.base.PreviewFieldsNum": "When hovering to view a table, limits the maximum number of previews for fields."
}
williamboman commented 2 years ago

:+1:. lspconfig will actually pull that information automatically from the package.json and make it available in their server configuration docs, if you provide it under the docs.package_json of the server config, like so.

younger-1 commented 2 years ago

Wow, that's awesome. I have done! https://github.com/younger-1/nvim-lspconfig/commit/c3e0e977d40d5fd05452ba2e62258aa724a36e3a And I opened an issue in luahelper just now. See here. https://github.com/Tencent/LuaHelper/issues/64

younger-1 commented 2 years ago

When the luahelper can work properly, I will create a pull request in lspconfig

xorander00 commented 2 years ago

I whipped up a quick custom server for LuaHelper. Since my primary workstation is FreeBSD, where sumneko_lua isn't supported, I would end up switching to my MacBook if I want LSP support for some Lua code I might be working on.

Just found LuaHelper a few hours ago. Took a quick look & built the standalone executable for FreeBSD 13-amd64 (luahelper-lsp, 8.8mb). Put that in my path, took a quick look at the configuration and wrote a custom server to see where it would bomb (wasn't expecting it to work). Imagine my surprise when I saw that it worked fine and it was fast.

If anyone wants to clean this up or use it as a reference for integration into this upstream, here's the main snippet for my custom server registered with nvim-lsp-installer:

installer = function()
  local _name = 'luahelper'

  local configs = require('lspconfig.configs')
  local lsputil = require('lspconfig').util
  configs[_name] = {
    default_config = {
      filetypes = { 'lua', },
      root_dir = lsputil.root_pattern('.stylua.toml'),
    },
  }

  local install_freebsd = function()
    local servers = require('nvim-lsp-installer.servers')
    local server = require('nvim-lsp-installer.server')
    local process = require('nvim-lsp-installer.process')
    local shell = require('nvim-lsp-installer.installers.shell')

    local _root_dir = server.get_server_root_path(_name)
    local _server = server.Server:new({
      name = _name,
      root_dir = _root_dir,
      homepage = 'https://github.com/Tencent/LuaHelper',
      languages = { 'lua', },
      default_options = {
        cmd = { 'luahelper-lsp', '-mode', '1' },
        cmd_env = {
          PATH = process.extend_path({ root_dir }),
        },
      },
      installer = function(server, callback, ctx)
        local is_success = shell.polyshell('which luahelper-lsp')
        if is_success then callback(true) else callback(false) end
      end
    })

    servers.register(_server)
  end

  if require('myapi').syshost.is_os_freebsd() then
    install_freebsd()
  end
end

Please note the following...

Screenshot 2022-04-26 071511

younger-1 commented 2 years ago

@xorander00 Thanks for your sharing. I would try when I have time.