From fc777af3ac14477e9e9c4ae95d625be631aa32ea Mon Sep 17 00:00:00 2001 From: s1n7ax Date: Sun, 10 Dec 2023 22:54:57 +0530 Subject: [PATCH 1/2] feat: add lint & release-please workflows --- .github/workflows/docs.yml | 6 ++--- .github/workflows/lint-test.yml | 33 -------------------------- .github/workflows/lint.yml | 12 ++++++++++ .github/workflows/luarocks-release.yml | 15 ++++++++++++ .github/workflows/release.yml | 27 +++++++++++++-------- .github/workflows/stylua.yml | 16 +++++++++++++ .github/workflows/test.yml | 25 +++++++++++++++++++ .luacheckrc | 13 ++++++++++ 8 files changed, 101 insertions(+), 46 deletions(-) delete mode 100644 .github/workflows/lint-test.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/luarocks-release.yml create mode 100644 .github/workflows/stylua.yml create mode 100644 .github/workflows/test.yml create mode 100644 .luacheckrc diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index a733a26..995c3d7 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,10 +1,10 @@ +name: Vim Doc + on: push: branches: - main -name: docs - permissions: pull-requests: write contents: write @@ -23,7 +23,7 @@ jobs: version: "Neovim >= 0.9.4" demojify: true - - name: Create Pull Request + - name: create pull request uses: peter-evans/create-pull-request@v5 with: base: "main" diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml deleted file mode 100644 index 19a56eb..0000000 --- a/.github/workflows/lint-test.yml +++ /dev/null @@ -1,33 +0,0 @@ ---- -on: [push, pull_request] -name: lint-test - -jobs: - stylua: - name: stylua - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: JohnnyMorganz/stylua-action@v3 - with: - version: latest - token: ${{ secrets.GITHUB_TOKEN }} - args: --color always --check lua - - test: - runs-on: ubuntu-latest - strategy: - matrix: - nvim-versions: ['stable', 'nightly'] - name: test - steps: - - name: checkout - uses: actions/checkout@v3 - - - uses: rhysd/action-setup-vim@v1 - with: - neovim: true - version: ${{ matrix.nvim-versions }} - - - name: run tests - run: make test diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..11e3060 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,12 @@ +name: Lint + +on: + push: + pull_request: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: lunarmodules/luacheck@v1 diff --git a/.github/workflows/luarocks-release.yml b/.github/workflows/luarocks-release.yml new file mode 100644 index 0000000..4224084 --- /dev/null +++ b/.github/workflows/luarocks-release.yml @@ -0,0 +1,15 @@ +name: LuaRocks Release +on: + push: + tags: + - "v*" +jobs: + luarocks-upload: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + + - name: luarocks upload + uses: nvim-neorocks/luarocks-tag-release@v4 + env: + LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 05db001..20e1c39 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,14 +1,21 @@ -name: "release" +name: Release + on: push: - tags: - - 'v*' + branches: [main] + pull_request: + workflow_dispatch: + +permissions: + pull-requests: write + contents: write + jobs: - luarocks-upload: - runs-on: ubuntu-22.04 + release: + name: release + if: ${{ github.ref == 'refs/heads/main' }} + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: LuaRocks Upload - uses: nvim-neorocks/luarocks-tag-release@v4 - env: - LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }} + - uses: google-github-actions/release-please-action@v3 + with: + release-type: simple diff --git a/.github/workflows/stylua.yml b/.github/workflows/stylua.yml new file mode 100644 index 0000000..a7b609a --- /dev/null +++ b/.github/workflows/stylua.yml @@ -0,0 +1,16 @@ +name: Stylua + +on: + push: + pull_request: + +jobs: + stylua: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: JohnnyMorganz/stylua-action@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + version: latest + args: --color always --check lua diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..fb1e389 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,25 @@ +name: Test + +on: + push: + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + nvim-versions: ["stable", "nightly"] + + name: test + steps: + - name: checkout + uses: actions/checkout@v3 + + - uses: rhysd/action-setup-vim@v1 + with: + neovim: true + version: ${{ matrix.nvim-versions }} + + - name: run tests + run: make test diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..c5cdeab --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,13 @@ +globals = { + 'vim.o', + 'vim.g', + 'vim.wo', + 'vim.bo', + 'vim.opt', +} +read_globals = { + 'vim', + 'describe', + 'it', + 'assert', +} From ddbae22aacf310efe8f4c65deb095a94033645b9 Mon Sep 17 00:00:00 2001 From: s1n7ax Date: Sun, 10 Dec 2023 23:10:38 +0530 Subject: [PATCH 2/2] fix: lint errors --- .../ls/servers/jdtls/lspconfig-types.lua | 41 ++++++++++++++----- lua/java-core/utils/async.lua | 4 +- lua/java-core/utils/class.lua | 10 ++--- lua/java-core/utils/log.lua | 2 + 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/lua/java-core/ls/servers/jdtls/lspconfig-types.lua b/lua/java-core/ls/servers/jdtls/lspconfig-types.lua index 60ba519..19384cf 100644 --- a/lua/java-core/ls/servers/jdtls/lspconfig-types.lua +++ b/lua/java-core/ls/servers/jdtls/lspconfig-types.lua @@ -1,16 +1,33 @@ ---@class LspSetupConfig ----@field root_dir fun(filename: string, bufnr: number): string | nil Returns either a filepath (string) or nil. The language server will only start if the function returns a filepath. +---@field root_dir fun(filename: string, bufnr: number): string | nil Returns either a filepath (string) or nil. +---The language server will only start if the function returns a filepath. ---@field name? string Defaults to the server's name (`clangd`, `pyright`, etc.). ---@field filetypes string[] | nil Set of filetypes for which to attempt to resolve {root_dir} ----@field autostart? boolean Controls if the `FileType` autocommand that launches a language server is created. If `false`, allows for deferring language servers until manually launched with `:LspStart` (|lspconfig-commands|). ----@field single_file_support? boolean Determines if a server is started without a matching root directory. See |lspconfig-single-file-support|. ----@field on_new_config fun(new_config: LspSetupConfig, new_root_dir: string) Function executed after a root directory is detected. This is used to modify the server configuration (including `cmd` itself). Most commonly, this is used to inject additional arguments into `cmd`. ----@field capabilities table a table which represents the neovim client capabilities. Useful for broadcasting to the server additional functionality (snippets, off-protocol features) provided by plugins. ----@field cmd string[] a list where each entry corresponds to the blankspace delimited part of the command that launches the server. The first entry is the binary used to run the language server. Additional entries are passed as arguments. ----@field handlers table a list of handlers which override the function used to process a response from a given language server. Applied only to the server referenced by setup. See |lsp-handler|. ----@field init_options table a table passed during the initialization notification after launching a language server. Equivalent to the `initializationOptions` field found in `InitializeParams` in the LSP specification. ----@field on_attach fun(client: object, bufnr: number) Callback invoked by Nvim's built-in client when attaching a buffer to a language server. Often used to set Nvim (buffer or global) options or to override the Nvim client properties (`server_capabilities`) after a language server attaches. Most commonly used for settings buffer local keybindings. See |lspconfig-keybindings| for a usage example. ----@field settings table The `settings` table is sent in `on_init` via a `workspace/didChangeConfiguration` notification from the Nvim client to the language server. These settings allow a user to change optional runtime settings of the language server. +---@field autostart? boolean Controls if the `FileType` autocommand that launches a language server is created. +---If `false`, allows for deferring language servers until manually launched with `:LspStart` (|lspconfig-commands|). +---@field single_file_support? boolean Determines if a server is started without a matching root directory. +---See |lspconfig-single-file-support|. +---@field on_new_config fun(new_config: LspSetupConfig, new_root_dir: string) Function executed after a root directory +---is detected. This is used to modify the server configuration (including `cmd` itself). +---Most commonly, this is used to inject additional arguments into `cmd`. +---@field capabilities table a table which represents the neovim client +---capabilities. Useful for broadcasting to the server additional functionality (snippets, off-protocol features) +---provided by plugins. +---@field cmd string[] a list where each entry corresponds to the blankspace delimited part of the command that +---launches the server. The first entry is the binary used to run the language server. +---Additional entries are passed as arguments. +---@field handlers table a list of handlers which override the function used to process a response +---from a given language server. Applied only to the server referenced by setup. See |lsp-handler|. +---@field init_options table a table passed during the initialization notification after +---launching a language server. Equivalent to the `initializationOptions` field found in `InitializeParams` +---in the LSP specification. +---@field on_attach fun(client: object, bufnr: number) Callback invoked by Nvim's built-in client when attaching a +---buffer to a language server. Often used to set Nvim (buffer or global) options or to override the Nvim client +---properties (`server_capabilities`) after a language server attaches. Most commonly used for settings buffer local +---keybindings. See |lspconfig-keybindings| for a usage example. +---@field settings table The `settings` table is sent in `on_init` via a +---`workspace/didChangeConfiguration` notification from the Nvim client to the language server. +---These settings allow a user to change optional runtime settings of the language server. ---@class LspClientRequestParameters ---@field command string @@ -23,6 +40,8 @@ ---@field code number ---@field message string +---@alias LspClientRequest fun(err: any, result: any) + ---@class LspClient ---@field attached_buffers table ---@field cancel_request function @@ -36,7 +55,7 @@ ---@field name string ---@field notify fun(method: string, params: object): boolean ---@field offset_encoding string ----@field request fun(method: string, params: LspClientRequestParameters, callback: fun(err: any, result: any), bufnr?: number): any +---@field request fun(method:string,params:LspClientRequestParameters,callback:LspClientRequest, bufnr?:number): any ---@field request_sync function ---@field requests object ---@field rpc object diff --git a/lua/java-core/utils/async.lua b/lua/java-core/utils/async.lua index 3381b14..4fb0cc8 100644 --- a/lua/java-core/utils/async.lua +++ b/lua/java-core/utils/async.lua @@ -60,8 +60,8 @@ local function async(func) end, __index = function(this, key) if key == 'catch' then - return function(_error_handler) - error_handler = _error_handler + return function(loc_error_handler) + error_handler = loc_error_handler return this end end diff --git a/lua/java-core/utils/class.lua b/lua/java-core/utils/class.lua index b5a9061..cd7bac3 100644 --- a/lua/java-core/utils/class.lua +++ b/lua/java-core/utils/class.lua @@ -34,8 +34,8 @@ local function call_ctor(c, obj, ...) parent_with_init = rawget(parent_with_init, '_parent_with_init') end if parent_with_init then -- super() points to one above whereever _init came from - rawset(obj, 'super', function(obj, ...) - call_ctor(parent_with_init, obj, ...) + rawset(obj, 'super', function(loc_obj, ...) + call_ctor(parent_with_init, loc_obj, ...) end) end else @@ -180,7 +180,7 @@ local function _class(base, c_arg, c) end -- expose a ctor which can be called by () - mt.__call = function(class_tbl, ...) + mt.__call = function(_class_tbl, ...) local obj if rawget(c, '_create') then obj = c._create(...) @@ -237,10 +237,10 @@ end -- @param c optional table to be used as class local class class = setmetatable({}, { - __call = function(fun, ...) + __call = function(_fun, ...) return _class(...) end, - __index = function(tbl, key) + __index = function(_tbl, key) if key == 'class' then io.stderr:write( 'require("pl.class").class is deprecated. Use require("pl.class")\n' diff --git a/lua/java-core/utils/log.lua b/lua/java-core/utils/log.lua index 0cb7a41..b03c837 100644 --- a/lua/java-core/utils/log.lua +++ b/lua/java-core/utils/log.lua @@ -162,6 +162,8 @@ log.new = function(config, standalone) end) end end + + return obj end log.new(default_config, true)