diff --git a/config/neovim/refresh_config.sh b/config/neovim/refresh_config.sh index ec95319c..5fe4beb7 100755 --- a/config/neovim/refresh_config.sh +++ b/config/neovim/refresh_config.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash +# Copy init.lua INIT_PATH="$(readlink -f ~/.config/nvim/init.lua)" cp -f "$INIT_PATH" ./config.lua cp -f "$INIT_PATH" ./config_nix.lua @@ -10,6 +11,7 @@ chmod +w ./config_nix.lua echo "Fixed permission for ./config.lua and ./config_nix.lua" echo "" +# Copy all plugins rm -rf ./store/* echo "Cleared ./store/" @@ -24,6 +26,7 @@ chmod -R +w ./store/* echo "Fixed permissions for ./store" echo "" +# Fix plugin paths for IDENTIFIER in "treesitter-parsers" "lazy-plugins" "nvim-treesitter" do CURRENT_PATH=$(eza -1 ./store | grep $IDENTIFIER) diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/.github/ISSUE_TEMPLATE/bug_report.yml b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 00000000..c6351b5e --- /dev/null +++ b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,89 @@ +name: Bug Report +description: File a bug/issue +title: "bug: " +labels: [bug] +body: + - type: markdown + attributes: + value: | + **Before** reporting an issue, make sure to read the [documentation](https://github.com/folke/lazydev.nvim) and search [existing issues](https://github.com/folke/lazydev.nvim/issues). Usage questions such as ***"How do I...?"*** belong in [Discussions](https://github.com/folke/lazydev.nvim/discussions) and will be closed. + - type: checkboxes + attributes: + label: Did you check docs and existing issues? + description: Make sure you checked all of the below before submitting an issue + options: + - label: I have read all the lazydev.nvim docs + required: true + - label: I have searched the existing issues of lazydev.nvim + required: true + - label: I have searched the existing issues of plugins related to this issue + required: true + - type: input + attributes: + label: "Neovim version (nvim -v)" + placeholder: "0.8.0 commit db1b0ee3b30f" + validations: + required: true + - type: input + attributes: + label: "Operating system/version" + placeholder: "MacOS 11.5" + validations: + required: true + - type: textarea + attributes: + label: Describe the bug + description: A clear and concise description of what the bug is. Please include any related errors you see in Neovim. + validations: + required: true + - type: textarea + attributes: + label: Steps To Reproduce + description: Steps to reproduce the behavior. + placeholder: | + 1. + 2. + 3. + validations: + required: true + - type: textarea + attributes: + label: Expected Behavior + description: A concise description of what you expected to happen. + validations: + required: true + - type: textarea + attributes: + label: Repro + description: Minimal `init.lua` to reproduce this issue. Save as `repro.lua` and run with `nvim -u repro.lua` + value: | + -- DO NOT change the paths and don't remove the colorscheme + local root = vim.fn.fnamemodify("./.repro", ":p") + + -- set stdpaths to use .repro + for _, name in ipairs({ "config", "data", "state", "cache" }) do + vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name + end + + -- bootstrap lazy + local lazypath = root .. "/plugins/lazy.nvim" + if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, }) + end + vim.opt.runtimepath:prepend(lazypath) + + -- install plugins + local plugins = { + "folke/tokyonight.nvim", + "folke/lazydev.nvim", + -- add any other plugins here + } + require("lazy").setup(plugins, { + root = root .. "/plugins", + }) + + vim.cmd.colorscheme("tokyonight") + -- add anything else here + render: Lua + validations: + required: false diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/.github/ISSUE_TEMPLATE/feature_request.yml b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 00000000..2ba3cb6f --- /dev/null +++ b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,36 @@ +name: Feature Request +description: Suggest a new feature +title: "feature: " +labels: [enhancement] +body: + - type: checkboxes + attributes: + label: Did you check the docs? + description: Make sure you read all the docs before submitting a feature request + options: + - label: I have read all the lazydev.nvim docs + required: true + - type: textarea + validations: + required: true + attributes: + label: Is your feature request related to a problem? Please describe. + description: A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + - type: textarea + validations: + required: true + attributes: + label: Describe the solution you'd like + description: A clear and concise description of what you want to happen. + - type: textarea + validations: + required: true + attributes: + label: Describe alternatives you've considered + description: A clear and concise description of any alternative solutions or features you've considered. + - type: textarea + validations: + required: false + attributes: + label: Additional context + description: Add any other context or screenshots about the feature request here. diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/.github/workflows/ci.yml b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/.github/workflows/ci.yml new file mode 100644 index 00000000..3a0b9dcc --- /dev/null +++ b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/.github/workflows/ci.yml @@ -0,0 +1,84 @@ +name: CI +on: + push: + pull_request: + +jobs: + tests: + strategy: + matrix: + # os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + - name: Install Neovim + shell: bash + run: | + mkdir -p /tmp/nvim + wget -q https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage -O /tmp/nvim/nvim.appimage + cd /tmp/nvim + chmod a+x ./nvim.appimage + ./nvim.appimage --appimage-extract + echo "/tmp/nvim/squashfs-root/usr/bin/" >> $GITHUB_PATH + - name: Run Tests + run: | + nvim --version + [ ! -d tests ] && exit 0 + nvim --headless -u tests/init.lua -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/init.lua', sequential = true}" + docs: + runs-on: ubuntu-latest + needs: tests + steps: + - uses: actions/checkout@v3 + - name: Install Neovim + shell: bash + run: | + mkdir -p /tmp/nvim + wget -q https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage -O /tmp/nvim/nvim.appimage + cd /tmp/nvim + chmod a+x ./nvim.appimage + ./nvim.appimage --appimage-extract + echo "/tmp/nvim/squashfs-root/usr/bin/" >> $GITHUB_PATH + # - name: Generate docs + # run: | + # nvim --version + # nvim --headless -u tests/init.lua -l "lua/lazydev/docs.lua" + - name: panvimdoc + uses: kdheepak/panvimdoc@main + with: + vimdoc: lazydev.nvim + version: "Neovim >= 0.8.0" + demojify: true + treesitter: true + - name: Push changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "chore(build): auto-generate vimdoc" + commit_user_name: "github-actions[bot]" + commit_user_email: "github-actions[bot]@users.noreply.github.com" + commit_author: "github-actions[bot] " + release: + name: release + if: ${{ github.ref == 'refs/heads/main' }} + needs: + - docs + - tests + runs-on: ubuntu-latest + steps: + - uses: google-github-actions/release-please-action@v3 + id: release + with: + release-type: simple + package-name: lazydev.nvim + - uses: actions/checkout@v3 + - name: tag stable versions + if: ${{ steps.release.outputs.release_created }} + run: | + git config user.name github-actions[bot] + git config user.email github-actions[bot]@users.noreply.github.com + git remote add gh-token "https://${{ secrets.GITHUB_TOKEN }}@github.com/google-github-actions/release-please-action.git" + git tag -d stable || true + git push origin :stable || true + git tag -a stable -m "Last Stable Release" + git push origin stable diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/CHANGELOG.md b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/CHANGELOG.md new file mode 100644 index 00000000..b0c4b591 --- /dev/null +++ b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/CHANGELOG.md @@ -0,0 +1,115 @@ +# Changelog + +## [1.4.0](https://github.com/folke/lazydev.nvim/compare/v1.3.0...v1.4.0) (2024-06-04) + + +### Features + +* added a `LazyDev` debugging command that shows libraries and settings for the current buffer ([3f6320d](https://github.com/folke/lazydev.nvim/commit/3f6320d43198bb847cbad6fd2a577dda18554f29)) +* added support for loading libraries based on words/mods ([7fabc0d](https://github.com/folke/lazydev.nvim/commit/7fabc0d5a44b3002b88c7c32b2b67bd3742c23ae)) + + +### Bug Fixes + +* **pkg:** luvit-meta/library not found using native package system ([#19](https://github.com/folke/lazydev.nvim/issues/19)) ([96062a7](https://github.com/folke/lazydev.nvim/commit/96062a7b94d5e6c3b4ec746b5d8d2a69e6389761)) +* **workspace:** make sure we always add the /lua root of the current project ([50927b4](https://github.com/folke/lazydev.nvim/commit/50927b4e70dce1ff68103ef1f2c197f1b75f4ac4)) + + +### Performance Improvements + +* only update single when needed ([fe37da2](https://github.com/folke/lazydev.nvim/commit/fe37da2cc14d4faffbe96be09b3fd08aa58ae972)) + +## [1.3.0](https://github.com/folke/lazydev.nvim/compare/v1.2.1...v1.3.0) (2024-06-03) + + +### Features + +* **config:** make it easier to specify plugin paths in library ([890c7d5](https://github.com/folke/lazydev.nvim/commit/890c7d5b982b829e2881f21d739e689772c7971e)) +* prettier debug ([fe68a25](https://github.com/folke/lazydev.nvim/commit/fe68a25bb37c8e683e233f09a5dd6c80c3ea9c64)) +* prettier debug ([766931a](https://github.com/folke/lazydev.nvim/commit/766931a928787e12dd42efef605b4aecdccffc11)) + + +### Bug Fixes + +* added single file support. Fixes [#10](https://github.com/folke/lazydev.nvim/issues/10) ([0592c8f](https://github.com/folke/lazydev.nvim/commit/0592c8f80a7c9bb99b7ea4d8a047d2d3bddeebd1)) +* fixup for debug. See [#10](https://github.com/folke/lazydev.nvim/issues/10) ([f3b3795](https://github.com/folke/lazydev.nvim/commit/f3b3795c6daf11da989220d859c0468b82d766ae)) +* **lsp:** dont error when workspace not loaded yet. Fixes [#10](https://github.com/folke/lazydev.nvim/issues/10) ([41e5bb1](https://github.com/folke/lazydev.nvim/commit/41e5bb150020d0841fffdd52e6a4942f51004986)) +* **lsp:** try to avoid incorrect temporary diagnostics ([22473af](https://github.com/folke/lazydev.nvim/commit/22473afec50117716db4a25e0b064437b8c6a1bd)) +* pass root_dir to enabled instead of lsp client ([37ba8ac](https://github.com/folke/lazydev.nvim/commit/37ba8ac79ab48762486deb9891547fde88a86763)) +* remove lazy.nvim dep ([4bd9af4](https://github.com/folke/lazydev.nvim/commit/4bd9af4b388c5f937c3f2308a1ead2ea2f68b09d)) +* revert set_handlers for now ([f2fe955](https://github.com/folke/lazydev.nvim/commit/f2fe95553b21fb7596c7cb060063886f17eb38c8)) +* windows fixes [#12](https://github.com/folke/lazydev.nvim/issues/12) ([f98d85a](https://github.com/folke/lazydev.nvim/commit/f98d85a16771282caceeefa0d9a65336f8b44437)) +* **workspace:** don't add workspace folder as library. See [#13](https://github.com/folke/lazydev.nvim/issues/13) ([ae12a62](https://github.com/folke/lazydev.nvim/commit/ae12a6224c466315f6ecbe6ed1ee7c5641f21d40)) +* **workspace:** resolve real paths. Fixes [#13](https://github.com/folke/lazydev.nvim/issues/13) ([b32bc5a](https://github.com/folke/lazydev.nvim/commit/b32bc5a0c6d50d0c2c3f5101a3f967d2222a539e)) + + +### Performance Improvements + +* debounce LuaLS updates ([7d843b9](https://github.com/folke/lazydev.nvim/commit/7d843b9f3aa9240e38854e7bc4df389929dbe44a)) +* dont return workspace library for the fallback scope ([2e715cd](https://github.com/folke/lazydev.nvim/commit/2e715cd4629df2b47d92468935226655cb7e88ed)) +* **lsp:** explicitely disable the fallback scope when no scopeUri and in a workspace ([b9ecd40](https://github.com/folke/lazydev.nvim/commit/b9ecd4034358a39859216d64b8548fa2b577af95)) +* properly track library usage per workspace folder ([48267c8](https://github.com/folke/lazydev.nvim/commit/48267c807750610f3f8f7cb1469308f68243f081)) + +## [1.2.1](https://github.com/folke/lazydev.nvim/compare/v1.2.0...v1.2.1) (2024-06-02) + + +### Bug Fixes + +* added support for module names with forward slashes instead of dots ([3c9423a](https://github.com/folke/lazydev.nvim/commit/3c9423a021a8e2890b2029ad20d830c713720afc)) + +## [1.2.0](https://github.com/folke/lazydev.nvim/compare/v1.1.0...v1.2.0) (2024-06-02) + + +### Features + +* added fast cmp completion source for require statements and module annotations ([a5c908d](https://github.com/folke/lazydev.nvim/commit/a5c908dc8eec1823c5a6dfbb07fbe8c74fce3a14)) +* **buf:** added support for `---[@module](https://github.com/module) "foobar"`. Fixes [#4](https://github.com/folke/lazydev.nvim/issues/4) ([6d0aaae](https://github.com/folke/lazydev.nvim/commit/6d0aaaea20d270c2c49fb0ff8b2835717e635f0d)) +* **config:** allow library to be a list of strings, or a table for easier merging ([6227a55](https://github.com/folke/lazydev.nvim/commit/6227a55bd1a4b7dcdc911377032ec5bb4eedba6b)) + + +### Bug Fixes + +* **buf:** implement on_reload ([1af5a6e](https://github.com/folke/lazydev.nvim/commit/1af5a6e801e16cf02a1ba0dc4808e522f2d06ae2)) + + +### Performance Improvements + +* **buf:** not needed to use treesitter to parse requires ([62c8bbf](https://github.com/folke/lazydev.nvim/commit/62c8bbff840432eb9e7fd3d994751cbb95c89e25)) + +## [1.1.0](https://github.com/folke/lazydev.nvim/compare/v1.0.0...v1.1.0) (2024-06-01) + + +### Features + +* added support for Neovim's package system ([37a48c0](https://github.com/folke/lazydev.nvim/commit/37a48c05311269d5cb08f0f2131e1ad583c6a485)) + + +### Bug Fixes + +* always call on_change when ataching new buffer ([f0de1e7](https://github.com/folke/lazydev.nvim/commit/f0de1e75f8e3a98e37ddf8d9b923ded039ff504e)) +* **pkg:** normalize paths for packpaths ([ee3d47f](https://github.com/folke/lazydev.nvim/commit/ee3d47f3a53891483c8a3e02f8c3e49a12064434)) + + +### Performance Improvements + +* batch require changes from file in one go ([45ef0d0](https://github.com/folke/lazydev.nvim/commit/45ef0d06cabac70c8615ae679d9efc72305f2142)) +* **pkg:** cache unloaded packs for packpath impl ([95aabb2](https://github.com/folke/lazydev.nvim/commit/95aabb27a0a8fec9826c6ca45ff8ba3d886a8888)) + +## 1.0.0 (2024-06-01) + + +### Features + +* Config.enabled ([b2da629](https://github.com/folke/lazydev.nvim/commit/b2da6296892323254b5841d45e643dcdaa6fbeb3)) +* config.enabled can be a function/boolean ([8434266](https://github.com/folke/lazydev.nvim/commit/8434266c8dd5c690134f5e66d340633e9f63e7bf)) +* initial commit ([77c5029](https://github.com/folke/lazydev.nvim/commit/77c5029d68941dfdbb3eaee4910bdc97d5c9a93b)) + + +### Bug Fixes + +* automatically add `/lua` when needed ([feef58f](https://github.com/folke/lazydev.nvim/commit/feef58f427d54ffebeec8f09b4d8c31dbea9b1c3)) + + +### Performance Improvements + +* update LSP with vim.schedule ([c211df9](https://github.com/folke/lazydev.nvim/commit/c211df939c5af6d8c0de0d6abfff300805fe66a7)) diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/README.md b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/README.md new file mode 100644 index 00000000..d645633f --- /dev/null +++ b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/README.md @@ -0,0 +1,133 @@ +# 💻 `lazydev.nvim` + +**lazydev.nvim** is a plugin that properly configures [LuaLS](https://luals.github.io/) +for editing your **Neovim** config by lazily updating your +workspace libraries. + +## 🚀 Features + +- much faster auto-completion, since only the modules you `require` + in open Neovim files will be loaded. +- no longer needed to configure what plugin sources you want + to have enabled for a certain project +- load third-party addons from [LLS-Addons](https://github.com/LuaLS/LLS-Addons) +- will update your workspace libraries for: + - **require** statements: `require("nvim-treesitter")` + - **module annotations**: `---@module "nvim-treesitter"` +- [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) completion source for the above + +![2024-06-01_21-02-40](https://github.com/folke/lazydev.nvim/assets/292349/c5f23225-88eb-454d-9b4e-1bf9183f7ff8) + +## ⚠️ Limitations + +- If you have files that only use types from a plugin, + then those types won't be available in your workspace. +- completion for module names when typing `require(...)` + will only return loaded modules in your workspace. +- To get around the above, you can: + - pre-load those plugins with the `library` option. + - use the **nvim-cmp** completion source to get all available modules. +- Neovim types are **NOT** included and also no longer needed + on **Neovim >= 0.10** + +## ⚡️ Requirements + +- Neovim >= 0.10.0 +- [lazy.nvim](https://github.com/folke/lazy.nvim) plugin manager + - **OR** a plugin manager that uses **Neovim**'s native package system + +## 📦 Installation + +With [lazy.nvim](https://github.com/folke/lazy.nvim): + +```lua +return { + { + "folke/lazydev.nvim", + ft = "lua", -- only load on lua files + opts = { + library = { + -- See the configuration section for more details + -- Load luvit types when the `vim.uv` word is found + { path = "luvit-meta/library", words = { "vim%.uv" } }, + }, + }, + }, + { "Bilal2453/luvit-meta", lazy = true }, -- optional `vim.uv` typings + { -- optional completion source for require statements and module annotations + "hrsh7th/nvim-cmp", + opts = function(_, opts) + opts.sources = opts.sources or {} + table.insert(opts.sources, { + name = "lazydev", + group_index = 0, -- set group index to 0 to skip loading LuaLS completions + }) + end, + }, + -- { "folke/neodev.nvim", enabled = false }, -- make sure to uninstall or disable neodev.nvim +} +``` + +## ⚙️ Configuration + +> [!TIP] +> You can force enable/disable **lazydev** in certain project folders using [:h 'exrc'](https://neovim.io/doc/user/options.html#'exrc') +> with `vim.g.lazydev_enabled = true` or `vim.g.lazydev_enabled = false` + +Examples: + +```lua + +{ + "folke/lazydev.nvim", + ft = "lua", -- only load on lua files + opts = { + library = { + -- Library paths can be absolute + "~/projects/my-awesome-lib", + -- Or relative, which means they will be resolved from the plugin dir. + "lazy.nvim", + "luvit-meta/library", + -- It can also be a table with trigger words / mods + -- Only load luvit types when the `vim.uv` word is found + { path = "luvit-meta/library", words = { "vim%.uv" } }, + -- always load the LazyVim library + "LazyVim", + -- Only load the lazyvim library when the `LazyVim` global is found + { path = "LazyVim", words = { "LazyVim" } }, + -- Load the wezterm types when the `wezterm` module is required + -- Needs `justinsgithub/wezterm-types` to be installed + { path = "wezterm-types", mods = { "wezterm" } }, + }, + -- always enable unless `vim.g.lazydev_enabled = false` + -- This is the default + enabled = function(root_dir) + return vim.g.lazydev_enabled == nil and true or vim.g.lazydev_enabled + end, + -- disable then a .luarc.json file is found + enabled = function(root_dir) + return not vim.uv.fs_stat(root_dir .. "/.luarc.json") + end, + }, +}, +``` + +Default settings: + +```lua +---@alias lazydev.Library {path:string, words:string[], mods:string[]} +---@alias lazydev.Library.spec string|{path:string, words?:string[], mods?:string[]} +---@class lazydev.Config +local defaults = { + runtime = vim.env.VIMRUNTIME --[[@as string]], + library = {}, ---@type lazydev.Library.spec[] + -- add the cmp source for completion of: + -- `require "modname"` + -- `---@module "modname"` + cmp = true, + ---@type boolean|(fun(root:string):boolean?) + enabled = function(root_dir) + return vim.g.lazydev_enabled == nil and true or vim.g.lazydev_enabled + end, +} +``` diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/doc/.keep b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/doc/.keep new file mode 100644 index 00000000..e69de29b diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/doc/lazydev.nvim.txt b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/doc/lazydev.nvim.txt new file mode 100644 index 00000000..89ff42a8 --- /dev/null +++ b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/doc/lazydev.nvim.txt @@ -0,0 +1,159 @@ +*lazydev.nvim.txt* For Neovim >= 0.8.0 Last change: 2024 June 04 + +============================================================================== +Table of Contents *lazydev.nvim-table-of-contents* + +1. lazydev.nvim |lazydev.nvim-lazydev.nvim| + - Features |lazydev.nvim-lazydev.nvim-features| + - Limitations |lazydev.nvim-lazydev.nvim-limitations| + - Requirements |lazydev.nvim-lazydev.nvim-requirements| + - Installation |lazydev.nvim-lazydev.nvim-installation| + - Configuration |lazydev.nvim-lazydev.nvim-configuration| +2. Links |lazydev.nvim-links| + +============================================================================== +1. lazydev.nvim *lazydev.nvim-lazydev.nvim* + +**lazydev.nvim** is a plugin that properly configures LuaLS + for editing your **Neovim** config by lazily +updating your workspace libraries. + + +FEATURES *lazydev.nvim-lazydev.nvim-features* + +- much faster auto-completion, since only the modules you `require` + in open Neovim files will be loaded. +- no longer needed to configure what plugin sources you want + to have enabled for a certain project +- load third-party addons from LLS-Addons +- will update your workspace libraries for: + - **require** statements: `require("nvim-treesitter")` + - **module annotations**`---@module "nvim-treesitter"` +- nvim-cmp completion source for the above + + +LIMITATIONS *lazydev.nvim-lazydev.nvim-limitations* + +- If you have files that only use types from a plugin, + then those types won’t be available in your workspace. +- completion for module names when typing `require(...)` + will only return loaded modules in your workspace. +- To get around the above, you can: + - pre-load those plugins with the `library` option. + - use the **nvim-cmp** completion source to get all available modules. +- Neovim types are **NOT** included and also no longer needed + on **Neovim >= 0.10** + + +REQUIREMENTS *lazydev.nvim-lazydev.nvim-requirements* + +- Neovim >= 0.10.0 +- lazy.nvim plugin manager + - **OR** a plugin manager that uses **Neovim**’s native package system + + +INSTALLATION *lazydev.nvim-lazydev.nvim-installation* + +With lazy.nvim + +>lua + return { + { + "folke/lazydev.nvim", + ft = "lua", -- only load on lua files + opts = { + library = { + -- See the configuration section for more details + -- Load luvit types when the `vim.uv` word is found + { path = "luvit-meta/library", words = { "vim%.uv" } }, + }, + }, + }, + { "Bilal2453/luvit-meta", lazy = true }, -- optional `vim.uv` typings + { -- optional completion source for require statements and module annotations + "hrsh7th/nvim-cmp", + opts = function(_, opts) + opts.sources = opts.sources or {} + table.insert(opts.sources, { + name = "lazydev", + group_index = 0, -- set group index to 0 to skip loading LuaLS completions + }) + end, + }, + -- { "folke/neodev.nvim", enabled = false }, -- make sure to uninstall or disable neodev.nvim + } +< + + +CONFIGURATION *lazydev.nvim-lazydev.nvim-configuration* + + + [!TIP] You can force enable/disable **lazydev** in certain project folders + using |:h 'exrc'| with `vim.g.lazydev_enabled = true` or `vim.g.lazydev_enabled + = false` +Examples: + +>lua + + { + "folke/lazydev.nvim", + ft = "lua", -- only load on lua files + opts = { + library = { + -- Library paths can be absolute + "~/projects/my-awesome-lib", + -- Or relative, which means they will be resolved from the plugin dir. + "lazy.nvim", + "luvit-meta/library", + -- It can also be a table with trigger words / mods + -- Only load luvit types when the `vim.uv` word is found + { path = "luvit-meta/library", words = { "vim%.uv" } }, + -- always load the LazyVim library + "LazyVim", + -- Only load the lazyvim library when the `LazyVim` global is found + { path = "LazyVim", words = { "LazyVim" } }, + -- Load the wezterm types when the `wezterm` module is required + -- Needs `justinsgithub/wezterm-types` to be installed + { path = "wezterm-types", mods = { "wezterm" } }, + }, + -- always enable unless `vim.g.lazydev_enabled = false` + -- This is the default + enabled = function(root_dir) + return vim.g.lazydev_enabled == nil and true or vim.g.lazydev_enabled + end, + -- disable then a .luarc.json file is found + enabled = function(root_dir) + return not vim.uv.fs_stat(root_dir .. "/.luarc.json") + end, + }, + }, +< + +Default settings: + +>lua + ---@alias lazydev.Library {path:string, words:string[], mods:string[]} + ---@alias lazydev.Library.spec string|{path:string, words?:string[], mods?:string[]} + ---@class lazydev.Config + local defaults = { + runtime = vim.env.VIMRUNTIME --[[@as string]], + library = {}, ---@type lazydev.Library.spec[] + -- add the cmp source for completion of: + -- `require "modname"` + -- `---@module "modname"` + cmp = true, + ---@type boolean|(fun(root:string):boolean?) + enabled = function(root_dir) + return vim.g.lazydev_enabled == nil and true or vim.g.lazydev_enabled + end, + } +< + +============================================================================== +2. Links *lazydev.nvim-links* + +1. *2024-06-01_21-02-40*: https://github.com/folke/lazydev.nvim/assets/292349/c5f23225-88eb-454d-9b4e-1bf9183f7ff8 + +Generated by panvimdoc + +vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/doc/tags b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/doc/tags new file mode 100644 index 00000000..29d0d2fd --- /dev/null +++ b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/doc/tags @@ -0,0 +1,9 @@ +lazydev.nvim-lazydev.nvim lazydev.nvim.txt /*lazydev.nvim-lazydev.nvim* +lazydev.nvim-lazydev.nvim-configuration lazydev.nvim.txt /*lazydev.nvim-lazydev.nvim-configuration* +lazydev.nvim-lazydev.nvim-features lazydev.nvim.txt /*lazydev.nvim-lazydev.nvim-features* +lazydev.nvim-lazydev.nvim-installation lazydev.nvim.txt /*lazydev.nvim-lazydev.nvim-installation* +lazydev.nvim-lazydev.nvim-limitations lazydev.nvim.txt /*lazydev.nvim-lazydev.nvim-limitations* +lazydev.nvim-lazydev.nvim-requirements lazydev.nvim.txt /*lazydev.nvim-lazydev.nvim-requirements* +lazydev.nvim-links lazydev.nvim.txt /*lazydev.nvim-links* +lazydev.nvim-table-of-contents lazydev.nvim.txt /*lazydev.nvim-table-of-contents* +lazydev.nvim.txt lazydev.nvim.txt /*lazydev.nvim.txt* diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/buf.lua b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/buf.lua new file mode 100644 index 00000000..7aefc332 --- /dev/null +++ b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/buf.lua @@ -0,0 +1,175 @@ +local Config = require("lazydev.config") +local Lsp = require("lazydev.lsp") +local Pkg = require("lazydev.pkg") +local Util = require("lazydev.util") +local Workspace = require("lazydev.workspace") + +local M = {} + +---@type table +M.attached = {} + +---@type table +M.modules = {} + +function M.setup() + for _, lib in ipairs(Config.libs) do + if #lib.words == 0 and #lib.mods == 0 then + Workspace.global():add(lib.path) + end + end + + -- debounce updates + local update = vim.schedule_wrap(M.update) + local timer = assert(vim.uv.new_timer()) + M.update = function() + timer:start(100, 0, update) + end + + local group = vim.api.nvim_create_augroup("lazydev", { clear = true }) + + vim.api.nvim_create_autocmd("LspAttach", { + group = group, + callback = function(ev) + local client = vim.lsp.get_client_by_id(ev.data.client_id) + if client and client.name == "lua_ls" then + M.on_attach(client, ev.buf) + end + end, + }) + + -- Attach to all existing clients + for _, client in ipairs(M.get_clients()) do + for buf in pairs(client.attached_buffers) do + M.on_attach(client, buf) + end + end + + -- Check for library changes + M.update() +end + +--- Gets all LuaLS clients that are enabled +function M.get_clients() + return Util.get_clients({ name = "lua_ls" }) +end + +--- Attach to the buffer +---@param client vim.lsp.Client +function M.on_attach(client, buf) + local root = Workspace.get_root(client, buf) + if not Config.is_enabled(root) then + return + end + if M.attached[buf] then + return + end + M.attached[buf] = buf + -- Attach to buffer events + vim.api.nvim_buf_attach(buf, false, { + on_lines = function(_, b, _, first, _, last) + M.on_lines(b, first, last) + end, + on_detach = function() + M.attached[buf] = nil + end, + on_reload = function() + M.on_lines(buf, 0, vim.api.nvim_buf_line_count(buf)) + end, + }) + -- Trigger initial scan + M.on_lines(buf, 0, vim.api.nvim_buf_line_count(buf)) + M.update() +end + +--- Triggered when lines are changed +---@param buf number +---@param first number +---@param last number +function M.on_lines(buf, first, last) + local lines = vim.api.nvim_buf_get_lines(buf, first, last, false) + for _, line in ipairs(lines) do + M.on_line(buf, line) + end +end + +---@param buf number +---@param line string +function M.on_line(buf, line) + -- Check for words + for word, paths in pairs(Config.words) do + if line:find(word) then + Workspace.find(buf):add(paths) + end + end + -- Check for modules + local module = Pkg.get_module(line) + if module then + M.on_mod(buf, module) + end +end + +--- Check if a module is available and add it to the library +---@param buf number +---@param modname string +function M.on_mod(buf, modname) + -- Check for configured modules + if Config.mods[modname] then + Workspace.find(buf):add(Config.mods[modname]) + end + + -- Check for modules in Neovim plugins + local mod = M.modules[modname] + + if mod == nil then + mod = vim.loader.find(modname)[1] + if not mod then + local paths = Pkg.get_unloaded(modname) + mod = vim.loader.find(modname, { rtp = false, paths = paths })[1] + end + M.modules[modname] = mod or false + end + + if mod then + local lua = mod.modpath:find("/lua/", 1, true) + local path = lua and mod.modpath:sub(1, lua + 3) or mod.modpath + if path then + Workspace.find(buf):add(path) + end + end +end + +--- Update LuaLS settings with the current library +function M.update() + if package.loaded["neodev"] then + vim.notify_once( + "Please disable `neodev.nvim` in your config.\nThis is no longer needed when you use `lazydev.nvim`", + vim.log.levels.WARN + ) + end + for _, client in ipairs(M.get_clients()) do + local update = false + + ---@param ws lsp.WorkspaceFolder + local folders = vim.tbl_map(function(ws) + return Workspace.get(client.id, ws.name) + end, client.workspace_folders or {}) + + if #folders == 0 then + folders = { Workspace.single(client) } + end + + for _, w in ipairs(folders) do + if w:update() then + update = true + end + end + + if update then + Lsp.attach(client) + Lsp.update(client) + end + end +end + +return M diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/cmd.lua b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/cmd.lua new file mode 100644 index 00000000..979c5be6 --- /dev/null +++ b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/cmd.lua @@ -0,0 +1,62 @@ +local Util = require("lazydev.util") +local Workspace = require("lazydev.workspace") + +local M = {} + +---@type table +M.commands = { + debug = function() + local buf = vim.api.nvim_get_current_buf() + local ws = Workspace.find(buf) + if not ws then + return Util.warn("No **LuaLS** workspace found.\nUse `:LazyDev lsp` to see settings of attached LSP clients.") + end + ws:debug({ details = true }) + end, + lsp = function() + local clients = Util.get_clients({ bufnr = 0 }) + local lines = {} ---@type string[] + for _, client in ipairs(clients) do + lines[#lines + 1] = "## " .. client.name + lines[#lines + 1] = "```lua" + lines[#lines + 1] = "settings = " .. vim.inspect(client.settings) + lines[#lines + 1] = "```" + end + Util.info(lines) + end, +} + +function M.execute(input) + local prefix, args = M.parse(input.args) + prefix = prefix and prefix ~= "" and prefix or "debug" + if not M.commands[prefix or ""] then + return Util.error("Invalid command") + end + M.commands[prefix](args) +end + +function M.complete(_, line) + local prefix, args = M.parse(line) + if #args > 0 then + return {} + end + + ---@param key string + return vim.tbl_filter(function(key) + return key:find(prefix, 1, true) == 1 + end, vim.tbl_keys(M.commands)) +end + +---@return string, string[] +function M.parse(args) + local parts = vim.split(vim.trim(args), "%s+") + if parts[1]:find("LazyDev") then + table.remove(parts, 1) + end + if args:sub(-1) == " " then + parts[#parts + 1] = "" + end + return table.remove(parts, 1) or "", parts +end + +return M diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/cmp.lua b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/cmp.lua new file mode 100644 index 00000000..670099c9 --- /dev/null +++ b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/cmp.lua @@ -0,0 +1,73 @@ +local Buf = require("lazydev.buf") +local Config = require("lazydev.config") +local Pkg = require("lazydev.pkg") + +local Source = {} + +function Source:get_trigger_characters() + return { '"', "'", ".", "/" } +end + +---@param params cmp.SourceCompletionApiParams +---@param callback fun(items: lsp.CompletionItem[]) +function Source:complete(params, callback) + local cmp = require("cmp") + local before = params.context.cursor_before_line + ---@type string? + local req, forward_slash = Pkg.get_module(before, { before = true }) + if not req then + return callback({}) + end + local items = {} ---@type table + + ---@param modname string + ---@param modpath string + local function add(modname, modpath) + items[modname] = items[modname] + or { + label = forward_slash and modname:gsub("%.", "/") or modname, + kind = cmp.lsp.CompletionItemKind.Module, + } + local item = items[modname] + + local plugin = Pkg.get_plugin_name(modpath) + if plugin then + if item.documentation then + item.documentation.value = item.documentation.value .. "\n- `" .. plugin .. "`" + else + item.documentation = { + kind = cmp.lsp.MarkupKind.Markdown, + value = "# Plugins:\n" .. "- `" .. plugin .. "`", + } + end + end + end + + if not req:find(".", 1, true) then + Pkg.topmods(add) + for _, lib in ipairs(Config.libs) do + for _, mod in ipairs(lib.mods) do + add(mod, lib.path) + end + end + else + Pkg.lsmod(req:gsub("%.[^%.]*$", ""), add) + end + + callback(vim.tbl_values(items)) +end + +function Source:is_available() + return Buf.attached[vim.api.nvim_get_current_buf()] +end + +local M = {} + +function M.setup() + local ok, cmp = pcall(require, "cmp") + if ok then + cmp.register_source("lazydev", Source) + end +end + +return M diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/config.lua b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/config.lua new file mode 100644 index 00000000..27ce4138 --- /dev/null +++ b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/config.lua @@ -0,0 +1,99 @@ +---@class lazydev.Config.mod: lazydev.Config +local M = {} + +---@alias lazydev.Library {path:string, words:string[], mods:string[]} +---@alias lazydev.Library.spec string|{path:string, words?:string[], mods?:string[]} +---@class lazydev.Config +local defaults = { + runtime = vim.env.VIMRUNTIME --[[@as string]], + library = {}, ---@type lazydev.Library.spec[] + ---@type boolean|(fun(root:string):boolean?) + enabled = function(root_dir) + return vim.g.lazydev_enabled == nil and true or vim.g.lazydev_enabled + end, + -- add the cmp source for completion of: + -- `require "modname"` + -- `---@module "modname"` + cmp = true, + debug = false, +} + +M.libs = {} ---@type lazydev.Library[] +M.words = {} ---@type table +M.mods = {} ---@type table + +---@type lazydev.Config +local options + +---@param root string +---@return boolean +function M.is_enabled(root) + local enabled = M.enabled + if type(enabled) == "function" then + return enabled(root) and true or false + end + return enabled +end + +M.have_0_10 = vim.fn.has("nvim-0.10") == 1 + +---@param opts? lazydev.Config +function M.setup(opts) + if not M.have_0_10 then + local msg = "lazydev.nvim requires Neovim >= 0.10" + vim.notify_once(msg, vim.log.levels.ERROR, { title = "lazydev.nvim" }) + error(msg) + return + end + + options = vim.tbl_deep_extend("force", {}, options or defaults, opts or {}) + + M.libs, M.words, M.mods = {}, {}, {} + local runtime = require("lazydev.util").norm(options.runtime) + table.insert(M.libs, { + path = vim.uv.fs_stat(runtime) and runtime or vim.env.VIMRUNTIME, + words = {}, + mods = {}, + }) + for _, lib in pairs(M.library) do + table.insert(M.libs, { + path = type(lib) == "table" and lib.path or lib, + words = type(lib) == "table" and lib.words or {}, + mods = type(lib) == "table" and lib.mods or {}, + }) + end + + for _, lib in ipairs(M.libs) do + for _, word in ipairs(lib.words) do + M.words[word] = M.words[word] or {} + table.insert(M.words[word], lib.path) + end + for _, mod in ipairs(lib.mods) do + M.mods[mod] = M.mods[mod] or {} + table.insert(M.mods[mod], lib.path) + end + end + + vim.api.nvim_create_user_command("LazyDev", function(...) + require("lazydev.cmd").execute(...) + end, { + nargs = "*", + complete = function(...) + return require("lazydev.cmd").complete(...) + end, + desc = "lazydev.nvim", + }) + + vim.schedule(function() + require("lazydev.buf").setup() + require("lazydev.cmp").setup() + end) + return options +end + +return setmetatable(M, { + __index = function(_, key) + options = options or M.setup() + return options[key] + end, +}) diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/init.lua b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/init.lua new file mode 100644 index 00000000..776d3759 --- /dev/null +++ b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/init.lua @@ -0,0 +1,8 @@ +local M = {} + +---@param opts? lazydev.Config +function M.setup(opts) + require("lazydev.config").setup(opts) +end + +return M diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/lsp.lua b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/lsp.lua new file mode 100644 index 00000000..46166e92 --- /dev/null +++ b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/lsp.lua @@ -0,0 +1,58 @@ +local Workspace = require("lazydev.workspace") + +local M = {} +M.attached = {} ---@type table + +---@param client vim.lsp.Client +function M.attach(client) + if M.attached[client.id] then + return + end + M.attached[client.id] = client.id + ---@param params lsp.ConfigurationParams + client.handlers["workspace/configuration"] = function(err, params, ctx, cfg) + if not params.items or #params.items == 0 then + return {} + end + + -- fallback scope + if #(client.workspace_folders or {}) > 0 and not params.items[1].scopeUri then + return {} + end + + local response = {} + for _, item in ipairs(params.items) do + if item.section then + local settings = client.settings + if item.section == "Lua" then + local ws = item.scopeUri and Workspace.get(client, vim.uri_to_fname(item.scopeUri)) + or Workspace.single(client) + if ws:enabled() then + settings = ws.settings + end + end + + local keys = vim.split(item.section, ".", { plain = true }) --- @type string[] + local value = vim.tbl_get(settings or {}, unpack(keys)) + -- For empty sections with no explicit '' key, return settings as is + if value == nil and item.section == "" then + value = settings + end + if value == nil then + value = vim.NIL + end + table.insert(response, value) + end + end + return response + end +end + +---@param client vim.lsp.Client +function M.update(client) + client.notify("workspace/didChangeConfiguration", { + settings = { Lua = {} }, + }) +end + +return M diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/pkg.lua b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/pkg.lua new file mode 100644 index 00000000..b0abd5f8 --- /dev/null +++ b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/pkg.lua @@ -0,0 +1,156 @@ +---@class lazydev.Pkg +local M = {} + +M.PAT_MODULE_BASE = "%-%-%-%s*@module%s*[\"']([%w%.%-_/]+)" +M.PAT_REQUIRE_BASE = "require%s*%(?%s*['\"]([%w%.%-_/]+)" +M.PAT_MODULE_BEFORE = M.PAT_MODULE_BASE .. "$" +M.PAT_REQUIRE_BEFORE = M.PAT_REQUIRE_BASE .. "$" +M.PAT_MODULE = M.PAT_MODULE_BASE .. "[\"']" +M.PAT_REQUIRE = M.PAT_REQUIRE_BASE .. "[\"']" + +local is_lazy = type(package.loaded.lazy) == "table" + +---@param modname string +---@return string[] +function M.lazy_unloaded(modname) + local Util = require("lazy.core.util") + return Util.get_unloaded_rtp(modname) +end + +---@type string[] +local packs = nil + +function M.pack_unloaded() + if packs then + return packs + end + + local sites = vim.opt.packpath:get() ---@type string[] + local default_site = vim.fn.stdpath("data") .. "/site" + if not vim.tbl_contains(sites, default_site) then + sites[#sites + 1] = default_site + end + local Util = require("lazydev.util") + packs = {} ---@type string[] + for _, site in pairs(sites) do + for _, pack in ipairs(vim.fn.expand(site .. "/pack/*/opt/*", false, true)) do + if not pack:find("*", 1, true) then + packs[#packs + 1] = Util.norm(pack) + end + end + end + return packs +end + +---@param modname string +---@return string[] +function M.get_unloaded(modname) + return is_lazy and M.lazy_unloaded(modname) or M.pack_unloaded() +end + +function M.get_plugin_path(name) + if is_lazy then + local Config = require("lazy.core.config") + local plugin = Config.spec.plugins[name] + return plugin and plugin.dir + else + for _, dir in ipairs(vim.opt.rtp:get()) do + local basename = vim.fs.basename(dir) + if basename == name then + return dir + end + end + for _, dir in ipairs(M.pack_unloaded()) do + local basename = vim.fs.basename(dir) + if basename == name then + return dir + end + end + end +end + +---@param modname string +---@return string[] +function M.find_roots(modname) + local ret = vim.loader.find(modname, { + rtp = true, + paths = M.get_unloaded(modname), + patterns = { "", ".lua" }, + all = true, + }) + return vim.tbl_map( + ---@param mod vim.loader.ModuleInfo + function(mod) + local path = mod.modpath:gsub("/init%.lua$", ""):gsub("%.lua$", "") + return path + end, + ret + ) +end + +---@param fn fun(modname:string, modpath:string) +function M.topmods(fn) + local ret = vim.loader.find("*", { + all = true, + rtp = true, + paths = M.get_unloaded(""), + }) + for _, mod in ipairs(ret) do + fn(mod.modname, mod.modpath) + end +end + +--- Get the module name from a line, +--- either `---@module "modname"` or `require "modname"` +---@param line string +---@param opts? {before?:boolean} +---@return string?, boolean? forward_slash +function M.get_module(line, opts) + local patterns = opts and opts.before and { + M.PAT_MODULE_BEFORE, + M.PAT_REQUIRE_BEFORE, + } or { + M.PAT_MODULE, + M.PAT_REQUIRE, + } + for _, pat in ipairs(patterns) do + local match = line:match(pat) + if match then + return match:gsub("/", "."), match:find("/", 1, true) + end + end +end + +---@param path string +---@return string? +function M.get_plugin_name(path) + local lua = path:find("/lua/", 1, true) + if lua then + local name = path:sub(1, lua - 1) + local slash = name:reverse():find("/", 1, true) + if slash then + name = name:sub(#name - slash + 2) + return name + end + end +end + +---@param modname string +---@param fn fun(modname:string, modpath:string) +function M.lsmod(modname, fn) + local roots = M.find_roots(modname) + for _, root in ipairs(roots) do + for name, type in vim.fs.dir(root) do + local path = vim.fs.joinpath(root, name) + if name == "init.lua" then + fn(modname, path) + elseif (type == "file" or type == "link") and name:sub(-4) == ".lua" then + fn(modname .. "." .. name:sub(1, -5), path) + elseif type == "directory" and vim.uv.fs_stat(path .. "/init.lua") then + fn(modname .. "." .. name, path .. "/init.lua") + end + end + end +end + +return M diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/util.lua b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/util.lua new file mode 100644 index 00000000..c3891f26 --- /dev/null +++ b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/util.lua @@ -0,0 +1,59 @@ +local M = {} + +---@alias NotifyOpts {level?: number, title?: string, once?: boolean} + +---@param msg string|string[] +---@param opts? NotifyOpts +function M.notify(msg, opts) + opts = opts or {} + msg = type(msg) == "table" and table.concat(msg, "\n") or msg + ---@cast msg string + msg = vim.trim(msg) + return vim[opts.once and "notify_once" or "notify"](msg, opts.level, { + title = opts.title or "lazydev.nvim", + on_open = function(win) + vim.wo.conceallevel = 3 + vim.wo.concealcursor = "n" + vim.wo.spell = false + vim.treesitter.start(vim.api.nvim_win_get_buf(win), "markdown") + end, + }) +end + +M.get_clients = vim.lsp.get_clients or vim.lsp.get_active_clients + +---@param path string +function M.is_absolute(path) + return path:sub(1, 1) == "/" or path:sub(2, 2) == ":" +end + +---@param path string +function M.norm(path) + path = vim.fs.normalize(path) + -- Special case for Windows drive letters + -- vim.fs.normalize doesn't handle them correctly + if path:sub(2, 2) == ":" then + path = path:sub(1, 1):lower() .. path:sub(2) + end + return path +end + +---@param msg string|string[] +---@param opts? NotifyOpts +function M.warn(msg, opts) + M.notify(msg, vim.tbl_extend("keep", { level = vim.log.levels.WARN }, opts or {})) +end + +---@param msg string|string[] +---@param opts? NotifyOpts +function M.error(msg, opts) + M.notify(msg, vim.tbl_extend("keep", { level = vim.log.levels.ERROR }, opts or {})) +end + +---@param msg string|string[] +---@param opts? NotifyOpts +function M.info(msg, opts) + M.notify(msg, vim.tbl_extend("keep", { level = vim.log.levels.INFO }, opts or {})) +end + +return M diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/workspace.lua b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/workspace.lua new file mode 100644 index 00000000..aa1bef37 --- /dev/null +++ b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/lua/lazydev/workspace.lua @@ -0,0 +1,188 @@ +local Config = require("lazydev.config") +local Pkg = require("lazydev.pkg") +local Util = require("lazydev.util") + +---@class lazydev.Workspace +---@field root string +---@field client_id number +---@field settings table +---@field library string[] +local M = {} +M.__index = M +M.SINGLE = "single" +M.GLOBAL = "global" + +---@type table +M.workspaces = {} + +function M.is_special(root) + return root == M.SINGLE or root == M.GLOBAL +end + +---@param client_id number +---@param root string +function M.new(client_id, root) + local self = setmetatable({ + root = root, + client_id = client_id, + settings = {}, + library = {}, + }, M) + if not M.is_special(root) then + self:add(root) + end + return self +end + +---@param client vim.lsp.Client|number +---@param root string +function M.get(client, root) + root = M.is_special(root) and root or Util.norm(root) + local client_id = type(client) == "number" and client or client.id + local id = client_id .. root + if not M.workspaces[id] then + M.workspaces[id] = M.new(client_id, root) + end + return M.workspaces[id] +end + +function M.global() + return M.get(-1, M.GLOBAL) +end + +---@param client vim.lsp.Client +function M.single(client) + return M.get(client, M.SINGLE) +end + +function M.find(buf) + local client = Util.get_clients({ + name = "lua_ls", + bufnr = buf, + })[1] + return client and M.get(client.id, M.get_root(client, buf)) +end + +---@param client vim.lsp.Client +---@param buf number +function M.get_root(client, buf) + local uri = vim.uri_from_bufnr(buf) + for _, ws in ipairs(client.workspace_folders or {}) do + if (uri .. "/"):sub(1, #ws.uri + 1) == ws.uri .. "/" then + return ws.name + end + end + return client.root_dir or "single" +end + +---@param path string|string[] +function M:add(path) + if type(path) == "table" then + for _, p in ipairs(path) do + self:add(p) + end + return + end + ---@cast path string + -- ignore special workspaces + if M.is_special(path) then + return + end + -- normalize + path = Util.norm(path) + -- try to resolve to a plugin path + if not Util.is_absolute(path) and not vim.uv.fs_stat(path) then + local name, extra = path:match("([^/]+)(/?.*)") + if name then + local pp = Pkg.get_plugin_path(name) + path = pp and (pp .. extra) or path + end + end + path = vim.uv.fs_realpath(path) or path + path = Util.norm(path) -- normalize again + -- append /lua if it exists + if not path:find("/lua/?$") and vim.uv.fs_stat(path .. "/lua") then + path = path .. "/lua" + end + if path ~= self.root and not vim.tbl_contains(self.library, path) then + table.insert(self.library, path) + if self.root ~= M.GLOBAL then + require("lazydev.buf").update() + end + end +end + +function M:client() + return vim.lsp.get_client_by_id(self.client_id) +end + +function M:enabled() + return self.root == M.GLOBAL or Config.is_enabled(self.root) +end + +function M:update() + local client = self:client() + if not client then + return + end + if not self:enabled() then + return + end + local settings = vim.deepcopy(client.settings or {}) + + local libs = {} ---@type string[] + vim.list_extend(libs, M.global().library) + vim.list_extend(libs, self.library) + + ---@type string[] + local library = vim.tbl_get(settings, "Lua", "workspace", "library") or {} + for _, path in ipairs(libs) do + if not vim.tbl_contains(library, path) then + table.insert(library, path) + end + end + + settings = vim.tbl_deep_extend("force", settings, { + Lua = { + runtime = { + version = "LuaJIT", + path = { "?.lua", "?/init.lua" }, + pathStrict = true, + }, + workspace = { + checkThirdParty = false, + library = library, + }, + }, + }) + + if not vim.deep_equal(settings, self.settings) then + self.settings = settings + if Config.debug then + self:debug() + end + return true + end +end + +---@param opts? {details: boolean} +function M:debug(opts) + opts = opts or {} + local root = M.is_special(self.root) and "[" .. self.root .. "]" or vim.fn.fnamemodify(self.root, ":~") + local lines = { "## " .. root } + ---@type string[] + local library = vim.tbl_get(self.settings, "Lua", "workspace", "library") or {} + for _, lib in ipairs(library) do + lib = vim.fn.fnamemodify(lib, ":~") + local plugin = Pkg.get_plugin_name(lib .. "/") + table.insert(lines, "- " .. (plugin and "**" .. plugin .. "** " or "") .. ("`" .. lib .. "`")) + end + if opts.details then + lines[#lines + 1] = "```lua" + lines[#lines + 1] = "settings = " .. vim.inspect(self.settings) + lines[#lines + 1] = "```" + end + Util.info(lines) +end + +return M diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/selene.toml b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/selene.toml new file mode 100644 index 00000000..eac3e9b4 --- /dev/null +++ b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/selene.toml @@ -0,0 +1,4 @@ +std = "vim" + +[lints] +mixed_table = "allow" diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/stylua.toml b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/stylua.toml new file mode 100644 index 00000000..9732fe64 --- /dev/null +++ b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/stylua.toml @@ -0,0 +1,6 @@ +indent_type = "Spaces" +indent_width = 2 +column_width = 120 +[sort_requires] +enabled = true + diff --git a/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/vim.toml b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/vim.toml new file mode 100644 index 00000000..4206f6cf --- /dev/null +++ b/config/neovim/store/lazy-plugins/vimplugin-nvim-lazydev/vim.toml @@ -0,0 +1,49 @@ +[selene] +base = "lua51" +name = "vim" + +[vim] +any = true + +[jit] +any = true + +[[describe.args]] +type = "string" +[[describe.args]] +type = "function" + +[[it.args]] +type = "string" +[[it.args]] +type = "function" + +[[before_each.args]] +type = "function" +[[after_each.args]] +type = "function" + +[assert.is_not] +any = true + +[[assert.equals.args]] +type = "any" +[[assert.equals.args]] +type = "any" +[[assert.equals.args]] +type = "any" +required = false + +[[assert.same.args]] +type = "any" +[[assert.same.args]] +type = "any" + +[[assert.truthy.args]] +type = "any" + +[[assert.spy.args]] +type = "any" + +[[assert.stub.args]] +type = "any"