From fe5d1e472a957cbab29ab0a087c30bde6deb219f Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 22 Jul 2024 18:32:15 +0200 Subject: [PATCH] feat!: rename to care.nvim --- .github/ISSUE_TEMPLATE/bug_report.yml | 12 ++-- .github/ISSUE_TEMPLATE/config.yml | 2 +- .github/ISSUE_TEMPLATE/feature_request.yml | 4 +- .github/workflows/auto_release.yml | 2 +- CONTRIBUTING.md | 4 +- ...scm-1.rockspec => care.nvim-scm-1.rockspec | 4 +- docs/config.norg | 54 ++++++++-------- docs/context.norg | 16 ++--- docs/core.norg | 30 ++++----- docs/design.norg | 10 +-- docs/entry.norg | 24 +++---- docs/internal_source.norg | 16 ++--- docs/menu.norg | 48 +++++++------- docs/misc.norg | 8 +-- docs/source.norg | 16 ++--- flake.nix | 10 +-- lua/{neocomplete => care}/config.lua | 10 +-- lua/{neocomplete => care}/context.lua | 4 +- lua/{neocomplete => care}/core.lua | 22 +++---- lua/{neocomplete => care}/entry.lua | 4 +- lua/{neocomplete => care}/ghost_text.lua | 26 ++++---- lua/{neocomplete => care}/highlights.lua | 26 ++++---- lua/care/init.lua | 62 +++++++++++++++++++ lua/{neocomplete => care}/mappings.lua | 18 +++--- lua/{neocomplete => care}/menu/confirm.lua | 12 ++-- lua/{neocomplete => care}/menu/draw.lua | 10 +-- lua/{neocomplete => care}/menu/init.lua | 26 ++++---- lua/{neocomplete => care}/sorter.lua | 6 +- lua/{neocomplete => care}/source.lua | 6 +- lua/{neocomplete => care}/sources.lua | 40 ++++++------ lua/{neocomplete => care}/types/config.lua | 40 ++++++------ lua/{neocomplete => care}/types/context.lua | 14 ++--- lua/care/types/core.lua | 21 +++++++ lua/care/types/entry.lua | 19 ++++++ lua/care/types/internal_source.lua | 14 +++++ lua/care/types/menu.lua | 48 ++++++++++++++ lua/{neocomplete => care}/types/misc.lua | 6 +- lua/{neocomplete => care}/types/source.lua | 10 +-- lua/{neocomplete => care}/types/window.lua | 30 ++++----- lua/{neocomplete => care}/utils/async.lua | 0 lua/{neocomplete => care}/utils/format.lua | 4 +- lua/{neocomplete => care}/utils/init.lua | 0 lua/{neocomplete => care}/utils/lsp.lua | 0 lua/{neocomplete => care}/utils/window.lua | 8 +-- lua/neocomplete/init.lua | 62 ------------------- lua/neocomplete/types/core.lua | 21 ------- lua/neocomplete/types/entry.lua | 19 ------ lua/neocomplete/types/internal_source.lua | 14 ----- lua/neocomplete/types/menu.lua | 48 -------------- minimal_init.lua | 24 +++---- plugin/care.lua | 5 ++ plugin/neocomplete.lua | 5 -- readme.md | 4 +- spec/benches/menu/complete.lua | 8 +-- spec/benches/menu/draw.lua | 4 +- spec/data/entries.lua | 12 ++-- spec/tests/complete/eol_spec.lua | 8 +-- spec/tests/complete/middle_of_line_spec.lua | 8 +-- spec/tests/complete/old_bugs_spec.lua | 36 +++++------ spec/tests/context_spec.lua | 2 +- spec/tests/utils/async_spec.lua | 2 +- spec/tests/utils/general_spec.lua | 2 +- spec/tests/utils/lsp_spec.lua | 2 +- 63 files changed, 516 insertions(+), 516 deletions(-) rename neocomplete.nvim-scm-1.rockspec => care.nvim-scm-1.rockspec (70%) rename lua/{neocomplete => care}/config.lua (89%) rename lua/{neocomplete => care}/context.lua (95%) rename lua/{neocomplete => care}/core.lua (79%) rename lua/{neocomplete => care}/entry.lua (97%) rename lua/{neocomplete => care}/ghost_text.lua (75%) rename lua/{neocomplete => care}/highlights.lua (52%) create mode 100644 lua/care/init.lua rename lua/{neocomplete => care}/mappings.lua (59%) rename lua/{neocomplete => care}/menu/confirm.lua (93%) rename lua/{neocomplete => care}/menu/draw.lua (92%) rename lua/{neocomplete => care}/menu/init.lua (89%) rename lua/{neocomplete => care}/sorter.lua (92%) rename lua/{neocomplete => care}/source.lua (89%) rename lua/{neocomplete => care}/sources.lua (69%) rename lua/{neocomplete => care}/types/config.lua (54%) rename lua/{neocomplete => care}/types/context.lua (55%) create mode 100644 lua/care/types/core.lua create mode 100644 lua/care/types/entry.lua create mode 100644 lua/care/types/internal_source.lua create mode 100644 lua/care/types/menu.lua rename lua/{neocomplete => care}/types/misc.lua (57%) rename lua/{neocomplete => care}/types/source.lua (52%) rename lua/{neocomplete => care}/types/window.lua (56%) rename lua/{neocomplete => care}/utils/async.lua (100%) rename lua/{neocomplete => care}/utils/format.lua (92%) rename lua/{neocomplete => care}/utils/init.lua (100%) rename lua/{neocomplete => care}/utils/lsp.lua (100%) rename lua/{neocomplete => care}/utils/window.lua (97%) delete mode 100644 lua/neocomplete/init.lua delete mode 100644 lua/neocomplete/types/core.lua delete mode 100644 lua/neocomplete/types/entry.lua delete mode 100644 lua/neocomplete/types/internal_source.lua delete mode 100644 lua/neocomplete/types/menu.lua create mode 100644 plugin/care.lua delete mode 100644 plugin/neocomplete.lua diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 9fdc276..8a7dcb2 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -1,5 +1,5 @@ name: Bug Report -description: Report a problem with neocomplete.nvim +description: Report a problem with care.nvim title: "bug: " labels: [bug] body: @@ -20,9 +20,9 @@ body: required: true - type: textarea attributes: - label: "neocomplete.nvim setup" + label: "care.nvim setup" description: | - - Copy your entire `require("neocomplete").setup` function + - Copy your entire `require("care").setup` function validations: required: true - type: textarea @@ -40,12 +40,12 @@ body: - type: textarea attributes: label: "Healthcheck" - description: "Output of `:checkhealth neocomplete`" + description: "Output of `:checkhealth care`" render: markdown placeholder: | - neocomplete: require("neocomplete.health").check() + care: require("care.health").check() ======================================================================== - ## neocomplete.nvim + ## care.nvim - type: textarea attributes: label: "Steps to reproduce" diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 901f9ec..b7af6e3 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,5 +1,5 @@ blank_issues_enabled: false contact_links: - name: Ask a question - url: https://github.com/max397574/neocomplete.nvim/discussions + url: https://github.com/max397574/care.nvim/discussions about: Use discussions to ask questions diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index 46b137a..3b7ba63 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -1,5 +1,5 @@ name: Feature request -description: Request a feature for neocomplete.nvim +description: Request a feature for care.nvim labels: [feature] body: - type: checkboxes @@ -7,7 +7,7 @@ body: attributes: label: Issues options: - - label: I have checked [existing issues](https://github.com/max397574/neocomplete.nvim/issues) and there are no existing ones with the same request. + - label: I have checked [existing issues](https://github.com/max397574/care.nvim/issues) and there are no existing ones with the same request. required: true - type: textarea attributes: diff --git a/.github/workflows/auto_release.yml b/.github/workflows/auto_release.yml index 4aa0187..d621de6 100644 --- a/.github/workflows/auto_release.yml +++ b/.github/workflows/auto_release.yml @@ -14,4 +14,4 @@ jobs: with: token: ${{ secrets.PAT }} release-type: simple - package-name: neocomplete.nvim + package-name: care.nvim diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 09dd245..12a23a2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,7 +48,7 @@ It can be setup with the following options: { path = "luvit-meta/library", words = { "vim%.uv" } }, { path = "luassert/library", words = { "vim%.uv" } }, { path = "busted/library", words = { "vim%.uv" } }, - { path = "neocomplete.nvim/lua/neocomplete/types/" }, + { path = "care.nvim/lua/care/types/" }, }, }, }, @@ -66,7 +66,7 @@ Run nix develop ``` -You can test-drive a minimal Neovim package with only neocomplete.nvim and its dependencies +You can test-drive a minimal Neovim package with only care.nvim and its dependencies installed by running ```bash nix run .#nvim diff --git a/neocomplete.nvim-scm-1.rockspec b/care.nvim-scm-1.rockspec similarity index 70% rename from neocomplete.nvim-scm-1.rockspec rename to care.nvim-scm-1.rockspec index fd70135..5fe1096 100644 --- a/neocomplete.nvim-scm-1.rockspec +++ b/care.nvim-scm-1.rockspec @@ -1,8 +1,8 @@ rockspec_format = '3.0' -package = "neocomplete.nvim" +package = "care.nvim" version = "scm-1" source = { - url = "git+https://github.com/max397574/neocomplete.nvim" + url = "git+https://github.com/max397574/care.nvim" } dependencies = { "fzy", diff --git a/docs/config.norg b/docs/config.norg index 6bf4521..5f9d081 100644 --- a/docs/config.norg +++ b/docs/config.norg @@ -1,6 +1,6 @@ @document.meta title: Source -description: Type description of neocomplete.nvim config +description: Type description of care.nvim config authors: [ max397574 ] @@ -10,7 +10,7 @@ categories: [ ] tangle: { languages: { - lua: ../lua/neocomplete/types/config.lua + lua: ../lua/care/types/config.lua } scope: tagged delimiter: none @@ -21,23 +21,23 @@ version: 1.1.1 @end * General - The config of neocomplete is used to configure the ui and neocomplete itself. + The config of care is used to configure the ui and care itself. #tangle @code lua - --- Configuration for neocomplete.nvim - ---@class neocomplete.config + --- Configuration for care.nvim + ---@class care.config @end There are two main parts to the config. The first one is the `ui` field and the second on is the - rest of the configuration which is for configuring neocomplete itself. + rest of the configuration which is for configuring care itself. ** UI In the ui field the completion menu, the docs view and the format of the entries are configured. There is also a field for configuring type icons. #tangle @code lua - --- Configuration for the ui of neocomplete - ---@field ui neocomplete.config.ui + --- Configuration for the ui of care + ---@field ui care.config.ui @end ** Snippet expansion @@ -76,43 +76,43 @@ version: 1.1.1 @end ** Enabled - This function can be used to disable neocomplete in certain contexts. By default this disables - neocomplete in prompts. + This function can be used to disable care in certain contexts. By default this disables + care in prompts. #tangle @code lua - --- Configuration for the ui of neocomplete + --- Configuration for the ui of care ---@field enabled fun(): boolean @end * UI - The ui configuration is used to configure the whole ui of neocomplete. One of the main goals of + The ui configuration is used to configure the whole ui of care. One of the main goals of this is to be as extensible as possible. This is especially important for the completion entries. Read more about that under {:./design:**** Configuraton of item display}. #tangle @code lua - --- The main class for the ui configuration of neocomplete.nvim - ---@class neocomplete.config.ui + --- The main class for the ui configuration of care.nvim + ---@class care.config.ui @end The most important part for many users will be the `menu` field. It's used to configure the completion menu. #tangle @code lua - --- Configuration of the completion menu of neocomplete.nvim - ---@field menu neocomplete.config.ui.menu + --- Configuration of the completion menu of care.nvim + ---@field menu care.config.ui.menu @end You can also configure the documentation view just like the main menu. #tangle @code lua - --- Configuration of the documentation view of neocomplete.nvim - ---@field docs_view neocomplete.config.ui.docs + --- Configuration of the documentation view of care.nvim + ---@field docs_view care.config.ui.docs @end Lastly the users can also configure the icons which will be used for the different items. #tangle @code lua --- The icons for the different compltion item kinds - ---@field type_icons neocomplete.config.ui.type_icons + ---@field type_icons care.config.ui.type_icons @end ** Ghost text @@ -121,9 +121,9 @@ version: 1.1.1 #tangle @code lua --- Configuration of ghost text - ---@field ghost_text neocomplete.config.ui.ghost_text + ---@field ghost_text care.config.ui.ghost_text - ---@class neocomplete.config.ui.ghost_text + ---@class care.config.ui.ghost_text ---@field enabled boolean ---@field position "inline"|"overlay" @end @@ -132,8 +132,8 @@ version: 1.1.1 This configuration should allow you to completely adapt the completion menu to your likings. #tangle @code lua - --- Configuration of the completion menu of neocomplete.nvim - ---@class neocomplete.config.ui.menu + --- Configuration of the completion menu of care.nvim + ---@class care.config.ui.menu @end It includes some basic window properties like the border and the maximum height of the window. It @@ -187,7 +187,7 @@ version: 1.1.1 #tangle @code lua --- How an entry should be formatted - ---@field format_entry fun(entry: neocomplete.entry): { [1]: string, [2]: string }[][] + ---@field format_entry fun(entry: care.entry): { [1]: string, [2]: string }[][] --- How the sections in the menu should be aligned ---@field alignment ("left"|"center"|"right")[] @end @@ -196,8 +196,8 @@ version: 1.1.1 This configuration allows you to configure the documentation view. #tangle @code lua - --- Configuration of the completion menu of neocomplete.nvim - ---@class neocomplete.config.ui.docs + --- Configuration of the completion menu of care.nvim + ---@class care.config.ui.docs @end It consists of some basic window properties like the border and the maximum height of the window. It also has a field to define the character used for the scrollbar. @@ -218,5 +218,5 @@ version: 1.1.1 #tangle @code lua --- The icons used for the different completion item types - ---@alias neocomplete.config.ui.type_icons table + ---@alias care.config.ui.type_icons table @end diff --git a/docs/context.norg b/docs/context.norg index 7b153e0..9b2aa87 100644 --- a/docs/context.norg +++ b/docs/context.norg @@ -12,7 +12,7 @@ created: 2023-11-15T17:42:46+0100 updated: 2024-06-18T18:18:38+0100 tangle: { languages: { - lua: ../lua/neocomplete/types/context.lua + lua: ../lua/care/types/context.lua } scope: tagged delimiter: none @@ -26,7 +26,7 @@ version: 1.1.1 #tangle @code lua --- Context provided to completion sources - ---@class neocomplete.context + ---@class care.context @end * Methods @@ -36,7 +36,7 @@ version: 1.1.1 #tangle @code lua --- Context changed since previous - ---@field changed fun(neocomplete.context): boolean + ---@field changed fun(care.context): boolean @end ** New @@ -47,7 +47,7 @@ version: 1.1.1 #tangle @code lua --- Create a new context - ---@field new fun(previous: neocomplete.context?): neocomplete.context + ---@field new fun(previous: care.context?): care.context @end * Fields @@ -56,7 +56,7 @@ version: 1.1.1 #tangle @code lua --- The previous context - ---@field previous neocomplete.context? + ---@field previous care.context? @end ** Cursor @@ -64,7 +64,7 @@ version: 1.1.1 #tangle @code lua --- The cursor position - ---@field cursor neocomplete.context.cursor + ---@field cursor care.context.cursor @end ** Bufnr @@ -80,7 +80,7 @@ version: 1.1.1 #tangle @code lua --- Reason for triggering completion - ---@field reason neocomplete.completionReason? + ---@field reason care.completionReason? @end ** Current line @@ -103,7 +103,7 @@ version: 1.1.1 #tangle @code lua --- A cursor position - ---@class neocomplete.context.cursor + ---@class care.context.cursor ---@field row integer ---@field col integer @end diff --git a/docs/core.norg b/docs/core.norg index ff97b6c..c7b7060 100644 --- a/docs/core.norg +++ b/docs/core.norg @@ -1,6 +1,6 @@ @document.meta title: Core -description: Type description of neocomplete.nvim source +description: Type description of care.nvim source authors: [ max397574 ] @@ -12,7 +12,7 @@ created: 2023-11-15T17:42:46+0100 updated: 2024-07-10T21:06:51+0100 tangle: { languages: { - lua: ../lua/neocomplete/types/core.lua + lua: ../lua/care/types/core.lua } scope: tagged delimiter: none @@ -21,12 +21,12 @@ version: 1.1.1 @end * General - This module is for the core of neocomplete. There all comes together with the menu being opened + This module is for the core of care. There all comes together with the menu being opened and the completion triggered. #tangle @code lua - --- The core module of neocomplete - ---@class neocomplete.core + --- The core module of care + ---@class care.core @end ** New @@ -34,7 +34,7 @@ version: 1.1.1 #tangle @code lua --- Create a new instance of the core - ---@field new fun(): neocomplete.core + ---@field new fun(): care.core @end * Methods @@ -44,7 +44,7 @@ version: 1.1.1 #tangle @code lua --- Complete - ---@field complete fun(self: neocomplete.core, reason: neocomplete.completionReason?): nil + ---@field complete fun(self: care.core, reason: care.completionReason?): nil @end ** On Change @@ -53,28 +53,28 @@ version: 1.1.1 #tangle @code lua --- The function that gets invoked when the text changes - ---@field on_change fun(neocomplete.core): nil + ---@field on_change fun(care.core): nil @end ** Block - The `block` method can be used to temporarily disable neocomplete. It returns a function which is + The `block` method can be used to temporarily disable care. It returns a function which is used to unblock it again. This is used for the `insert` selection behavior where you don't want to get new completions when changing the text. #tangle @code lua - --- Block neocomplete temporarily + --- Block care temporarily --- Call return value to unblock - ---@field block fun(neocomplete.core): fun(): nil + ---@field block fun(care.core): fun(): nil @end ** Setup - The setup function is used to setup neocomplete so it will actually provide autocompletion when + The setup function is used to setup care so it will actually provide autocompletion when typing by setting up an autocommand. #tangle @code lua --- Setup core (for now autocommands) - ---@field setup fun(self: neocomplete.core): nil + ---@field setup fun(self: care.core): nil @end * Fields @@ -84,7 +84,7 @@ version: 1.1.1 #tangle @code lua --- Context instance of the core - ---@field context neocomplete.context + ---@field context care.context @end ** Menu @@ -92,7 +92,7 @@ version: 1.1.1 #tangle @code lua --- Menu instance of the core - ---@field menu neocomplete.menu + ---@field menu care.menu @end ** Blocked diff --git a/docs/design.norg b/docs/design.norg index 9fc31d5..e64a77a 100644 --- a/docs/design.norg +++ b/docs/design.norg @@ -1,6 +1,6 @@ @document.meta title: Design -description: Design of neocomplete.nvim +description: Design of care.nvim authors: [ max397574 ] @@ -8,16 +8,16 @@ categories: [ docs ] created: 2023-11-15T17:42:49+0100 -updated: 2024-07-16T19:15:01+0100 +updated: 2024-07-22T18:34:25+0100 version: 1.1.1 @end * General - There is the {https://github.com/max397574/neocomplete.nvim}[neocomplete.nvim] plugin. This is + There is the {https://github.com/max397574/care.nvim}[care.nvim] plugin. This is the main module of the whole completion architecture. Then there are also sources, which is where the core gets it's completions from. -** Neocomplete.nvim +** Care.nvim This is the core of the autocompletion. From here the sources are used to get completions which are then displayed in the {*** Completion Menu} @@ -168,7 +168,7 @@ version: 1.1.1 ** Types We have files for types which are tangled from a norg file (this one?) using lua-ls annotations. - They are prefixed with `neocomplete.`. + They are prefixed with `care.`. As often as possible we should try to use the `lsp.*` types which are in neovim core. The types are documented in the `docs/` folder and are tangled to lua type files with {https://github.com/nvim-neorg/neorg}[neorg]. diff --git a/docs/entry.norg b/docs/entry.norg index e254b3f..50c26a7 100644 --- a/docs/entry.norg +++ b/docs/entry.norg @@ -1,6 +1,6 @@ @document.meta title: Entry -description: Type description of neocomplete.nvim entry +description: Type description of care.nvim entry authors: [ max397574 ] @@ -12,7 +12,7 @@ created: 2023-11-15T17:42:46+0100 updated: 2024-07-15T19:07:45+0100 tangle: { languages: { - lua: ../lua/neocomplete/types/entry.lua + lua: ../lua/care/types/entry.lua } scope: tagged delimiter: none @@ -25,8 +25,8 @@ version: 1.1.1 completion item for which the lsp type is used. #tangle @code lua - --- An entry for the neocomplete completion menu - ---@class neocomplete.entry + --- An entry for the care completion menu + ---@class care.entry ---@field completion_item lsp.CompletionItem @end @@ -36,7 +36,7 @@ version: 1.1.1 #tangle @code lua --- Creates a new entry - ---@field new fun(completion_item: lsp.CompletionItem, source: neocomplete.internal_source, context: neocomplete.context): neocomplete.entry + ---@field new fun(completion_item: lsp.CompletionItem, source: care.internal_source, context: care.context): care.entry @end ** Get insert text @@ -45,7 +45,7 @@ version: 1.1.1 #tangle @code lua --- Get insert text - ---@field get_insert_text fun(self: neocomplete.entry): string + ---@field get_insert_text fun(self: care.entry): string @end ** Get insert word @@ -56,7 +56,7 @@ version: 1.1.1 #tangle @code lua --- Get insert word - ---@field get_insert_word fun(self: neocomplete.entry): string + ---@field get_insert_word fun(self: care.entry): string @end * Fields @@ -66,7 +66,7 @@ version: 1.1.1 #tangle @code lua --- Source from which the entry came - ---@field source neocomplete.internal_source + ---@field source care.internal_source @end ** Context @@ -75,12 +75,12 @@ version: 1.1.1 #tangle @code lua --- Context in which entry was completed - ---@field context neocomplete.context + ---@field context care.context @end ** Matches Position of matches which were found during filtering. This is just used to highlight them in the - completion menu with `@neocomplete.match`. + completion menu with `@care.match`. #tangle @code lua --- Matches in filter text @@ -89,7 +89,7 @@ version: 1.1.1 ** Score This is the score obtained from filtering. It is used to sort which happens in the - `neocomplete.sorter` module. + `care.sorter` module. #tangle @code lua --- Score from filtering @@ -101,5 +101,5 @@ version: 1.1.1 #tangle @code lua --- Get offset of entry from beginning of line - ---@field get_offset fun(self: neocomplete.entry): integer + ---@field get_offset fun(self: care.entry): integer @end diff --git a/docs/internal_source.norg b/docs/internal_source.norg index 5d07fcc..cb7da97 100644 --- a/docs/internal_source.norg +++ b/docs/internal_source.norg @@ -12,7 +12,7 @@ created: 2024-05-31T12:48:14+0100 updated: 2024-06-18T19:34:31+0100 tangle: { languages: { - lua: ../lua/neocomplete/types/internal_source.lua + lua: ../lua/care/types/internal_source.lua } scope: tagged delimiter: none @@ -25,8 +25,8 @@ version: 1.1.1 metadata about which the source author doesn't have to care and sometimes can't know. #tangle @code lua - --- Internal class for neocomplete to store source metadata - ---@class neocomplete.internal_source + --- Internal class for care to store source metadata + ---@class care.internal_source @end ** Source @@ -34,7 +34,7 @@ version: 1.1.1 #tangle @code lua --- The external completion source - ---@field source neocomplete.source + ---@field source care.source @end @@ -44,7 +44,7 @@ version: 1.1.1 #tangle @code lua --- The entries recieved by last completion - ---@field entries neocomplete.entry[] + ---@field entries care.entry[] @end ** New @@ -52,7 +52,7 @@ version: 1.1.1 #tangle @code lua --- The entries recieved by last completion - ---@field new fun(completion_source: neocomplete.source): neocomplete.internal_source + ---@field new fun(completion_source: care.source): care.internal_source @end ** Incomplete @@ -70,7 +70,7 @@ version: 1.1.1 #tangle @code lua --- Get the keyword pattern - ---@field get_keyword_pattern fun(self: neocomplete.internal_source): string + ---@field get_keyword_pattern fun(self: care.internal_source): string @end ** Get offset @@ -80,5 +80,5 @@ version: 1.1.1 #tangle @code lua --- The offset at which completions from source were loaded - ---@field get_offset fun(self: neocomplete.internal_source, context: neocomplete.context): integer + ---@field get_offset fun(self: care.internal_source, context: care.context): integer @end diff --git a/docs/menu.norg b/docs/menu.norg index 62d57bb..3081ab8 100644 --- a/docs/menu.norg +++ b/docs/menu.norg @@ -1,6 +1,6 @@ @document.meta title: Menu -description: Type description of neocomplete.nvim menu +description: Type description of care.nvim menu authors: [ max397574 ] @@ -12,7 +12,7 @@ created: 2024-05-29T11:30:25+0100 updated: 2024-07-14T08:43:31+0100 tangle: { languages: { - lua: ../lua/neocomplete/types/menu.lua + lua: ../lua/care/types/menu.lua } scope: tagged delimiter: none @@ -21,12 +21,12 @@ version: 1.1.1 @end * General - This is the main class of the neocomplete completion menu. The menu is used to display completion + This is the main class of the care completion menu. The menu is used to display completion entries and also contains the logic for selecting and inserting the completions. #tangle @code lua - --- The completion menu of neocomplete - ---@class neocomplete.menu + --- The completion menu of care + ---@class care.menu @end * Internals @@ -41,7 +41,7 @@ version: 1.1.1 #tangle @code lua --- Create a new instance of the menu - ---@field new fun(): neocomplete.menu + ---@field new fun(): care.menu @end ** Draw @@ -51,7 +51,7 @@ version: 1.1.1 #tangle @code lua --- Draws the menu - ---@field draw fun(self: neocomplete.menu): nil + ---@field draw fun(self: care.menu): nil @end ** Is open @@ -60,7 +60,7 @@ version: 1.1.1 #tangle @code lua --- Returns true if completion window is visible - ---@field is_open fun(self: neocomplete.menu): boolean + ---@field is_open fun(self: care.menu): boolean @end @@ -70,7 +70,7 @@ version: 1.1.1 #tangle @code lua --- Select next entry in menu - ---@field select_next fun(self: neocomplete.menu, count: integer): nil + ---@field select_next fun(self: care.menu, count: integer): nil @end ** Select prev @@ -78,7 +78,7 @@ version: 1.1.1 #tangle @code lua --- Select previous entry in menu - ---@field select_prev fun(self: neocomplete.menu, count: integer): nil + ---@field select_prev fun(self: care.menu, count: integer): nil @end ** Open @@ -87,7 +87,7 @@ version: 1.1.1 #tangle @code lua --- Opens the menu with specified entries - ---@field open fun(self: neocomplete.menu, entries: neocomplete.entry[], offset: integer): nil + ---@field open fun(self: care.menu, entries: care.entry[], offset: integer): nil @end ** Close @@ -95,7 +95,7 @@ version: 1.1.1 #tangle @code lua --- Closes the window of the menu - ---@field close fun(self: neocomplete.menu): nil + ---@field close fun(self: care.menu): nil @end ** Get active entry @@ -104,7 +104,7 @@ version: 1.1.1 #tangle @code lua --- Gets the currently selected entry - ---@field get_active_entry fun(self: neocomplete.menu): neocomplete.entry? + ---@field get_active_entry fun(self: care.menu): care.entry? @end ** Confirm @@ -113,7 +113,7 @@ version: 1.1.1 #tangle @code lua --- Selects the current entry and inserts it's text - ---@field confirm fun(self: neocomplete.menu): nil + ---@field confirm fun(self: care.menu): nil @end ** Complete @@ -123,7 +123,7 @@ version: 1.1.1 #tangle @code lua --- Completes with the given entry - ---@field complete fun(self: neocomplete.menu, entry: neocomplete.entry): nil + ---@field complete fun(self: care.menu, entry: care.entry): nil @end ** Readjust window @@ -131,7 +131,7 @@ version: 1.1.1 #tangle @code lua --- Readjust size of completino window - ---@field readjust_win fun(self: neocomplete.menu, offset: integer): nil + ---@field readjust_win fun(self: care.menu, offset: integer): nil @end ** Docs Visible @@ -139,7 +139,7 @@ version: 1.1.1 #tangle @code lua --- Checks if docs are open - ---@field docs_visible fun(self: neocomplete.menu): boolean + ---@field docs_visible fun(self: care.menu): boolean @end ** Scroll docs @@ -147,7 +147,7 @@ version: 1.1.1 #tangle @code lua --- Scroll in the docs window - ---@field scroll_docs fun(self: neocomplete.menu, delta: integer): nil + ---@field scroll_docs fun(self: care.menu, delta: integer): nil @end * Fields @@ -155,14 +155,14 @@ version: 1.1.1 #tangle @code lua --- Wrapper for utilities for the window of the menu - ---@field menu_window neocomplete.window + ---@field menu_window care.window @end ** Docs Window #tangle @code lua --- Wrapper for utilities for the window of the docs - ---@field docs_window neocomplete.window + ---@field docs_window care.window @end ** Ghost text @@ -170,7 +170,7 @@ version: 1.1.1 #tangle @code lua --- Instance of ghost text to draw the ghost text - ---@field ghost_text neocomplete.ghost_text + ---@field ghost_text care.ghost_text @end ** Entries @@ -178,7 +178,7 @@ version: 1.1.1 #tangle @code lua --- Entries of the menu - ---@field entries neocomplete.entry[] + ---@field entries care.entry[] @end ** Namespace @@ -193,8 +193,8 @@ version: 1.1.1 In this field the user config is stored for easier access. #tangle @code lua - --- Neocomplete config to be used in the menu - ---@field config neocomplete.config + --- Care config to be used in the menu + ---@field config care.config @end ** Buffer diff --git a/docs/misc.norg b/docs/misc.norg index 6cf287e..626326d 100644 --- a/docs/misc.norg +++ b/docs/misc.norg @@ -12,7 +12,7 @@ created: 2024-05-29T11:30:25+0100 updated: 2024-06-08T18:52:40+0100 tangle: { languages: { - lua: ../lua/neocomplete/types/misc.lua + lua: ../lua/care/types/misc.lua } scope: tagged delimiter: none @@ -28,9 +28,9 @@ version: 1.1.1 #tangle @code lua --- Context provided to completion sources - ---@class neocomplete.completion_context + ---@class care.completion_context ---@field completion_context lsp.CompletionContext - ---@field context neocomplete.context + ---@field context care.context @end * Reason @@ -40,7 +40,7 @@ version: 1.1.1 #tangle @code lua --- Reason for triggering completion - ---@alias neocomplete.completionReason + ---@alias care.completionReason ---| 1 # Auto ---| 2 # Manual @end diff --git a/docs/source.norg b/docs/source.norg index 3231cc7..f5faa67 100644 --- a/docs/source.norg +++ b/docs/source.norg @@ -1,6 +1,6 @@ @document.meta title: Source -description: Type description of neocomplete.nvim source +description: Type description of care.nvim source authors: [ max397574 ] @@ -12,7 +12,7 @@ created: 2023-11-15T17:42:46+0100 updated: 2024-07-15T20:10:47+0100 tangle: { languages: { - lua: ../lua/neocomplete/types/source.lua + lua: ../lua/care/types/source.lua } scope: tagged delimiter: none @@ -21,12 +21,12 @@ version: 1.1.1 @end * General - The sources are used to get get completions for neocomplete.nvim. + The sources are used to get get completions for care.nvim. #tangle @code lua - --- A completion source for neocomplete.nvim - ---@class neocomplete.source + --- A completion source for care.nvim + ---@class care.source @end * Fields @@ -65,7 +65,7 @@ version: 1.1.1 #tangle @code lua --- Resolve a completion item - ---@field resolve_item? fun(self: neocomplete.source, item: lsp.CompletionItem, callback: fun(item: lsp.CompletionItem)): nil + ---@field resolve_item? fun(self: care.source, item: lsp.CompletionItem, callback: fun(item: lsp.CompletionItem)): nil @end ** `get_trigger_characters()` @@ -100,7 +100,7 @@ version: 1.1.1 #tangle @code lua --- Get keyword pattern for this source - ---@field get_keyword_pattern? fun(self: neocomplete.source): string + ---@field get_keyword_pattern? fun(self: care.source): string @end @@ -112,5 +112,5 @@ version: 1.1.1 #tangle @code lua --- Returns completion in the provided context - ---@field complete fun(completion_context: neocomplete.completion_context, callback: fun(items: lsp.CompletionItem[], is_incomplete?: boolean)): nil + ---@field complete fun(completion_context: care.completion_context, callback: fun(items: lsp.CompletionItem[], is_incomplete?: boolean)): nil @end diff --git a/flake.nix b/flake.nix index fc6d5a2..243c9d2 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "neocomplete.nvim package + dev environment"; + description = "care.nvim package + dev environment"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; @@ -52,16 +52,16 @@ }; packages = rec { - default = neocomplete-nvim; - neocomplete-nvim = pkgs.vimUtils.buildVimPlugin { - pname = "neocomplete.nvim"; + default = care-nvim; + care-nvim = pkgs.vimUtils.buildVimPlugin { + pname = "care.nvim"; version = "dev"; src = self; }; nvim = let config = pkgs.neovimUtils.makeNeovimConfig { plugins = with pkgs; [ - neocomplete-nvim + care-nvim fzy ]; }; diff --git a/lua/neocomplete/config.lua b/lua/care/config.lua similarity index 89% rename from lua/neocomplete/config.lua rename to lua/care/config.lua index 8f9d482..5bcf974 100644 --- a/lua/neocomplete/config.lua +++ b/lua/care/config.lua @@ -1,10 +1,10 @@ local config = {} ----@type neocomplete.config +---@type care.config ---@diagnostic disable-next-line: missing-fields config.options = {} ----@type neocomplete.config +---@type care.config config.defaults = { ui = { menu = { @@ -16,13 +16,13 @@ config.defaults = { local type_icons = config.options.ui.type_icons -- TODO: remove since now can only be number, or also allow custom string kinds? local entry_kind = type(completion_item.kind) == "string" and completion_item.kind - or require("neocomplete.utils.lsp").get_kind_name(completion_item.kind) + or require("care.utils.lsp").get_kind_name(completion_item.kind) return { - { { completion_item.label .. " ", "@neocomplete.entry" } }, + { { completion_item.label .. " ", "@care.entry" } }, { { " " .. (type_icons[entry_kind] or type_icons.Text) .. " ", - ("@neocomplete.type.%s"):format(entry_kind), + ("@care.type.%s"):format(entry_kind), }, }, } diff --git a/lua/neocomplete/context.lua b/lua/care/context.lua similarity index 95% rename from lua/neocomplete/context.lua rename to lua/care/context.lua index 66b7100..ad3d5fe 100644 --- a/lua/neocomplete/context.lua +++ b/lua/care/context.lua @@ -1,11 +1,11 @@ ----@type neocomplete.context +---@type care.context ---@diagnostic disable-next-line: missing-fields local context = {} ---@type lsp.CompletionContext function context.new(previous) - ---@type neocomplete.context + ---@type care.context local self = setmetatable({}, { __index = context }) previous = previous or {} -- reset so table doesn't get too big diff --git a/lua/neocomplete/core.lua b/lua/care/core.lua similarity index 79% rename from lua/neocomplete/core.lua rename to lua/care/core.lua index 0a822f1..b9bef65 100644 --- a/lua/neocomplete/core.lua +++ b/lua/care/core.lua @@ -1,12 +1,12 @@ ----@type neocomplete.core +---@type care.core ---@diagnostic disable-next-line: missing-fields local core = {} function core.new() - ---@type neocomplete.core + ---@type care.core local self = setmetatable({}, { __index = core }) - self.context = require("neocomplete.context").new() - self.menu = require("neocomplete.menu").new() + self.context = require("care.context").new() + self.menu = require("care.menu").new() self.blocked = false self.last_opened_at = -1 return self @@ -14,18 +14,18 @@ end function core:complete(reason) reason = reason or 2 - local sources = require("neocomplete.sources").get_sources() + local sources = require("care.sources").get_sources() local entries = {} local remaining = #sources self.context.reason = reason local offset = self.context.cursor.col for i, source in ipairs(sources) do if source.source.is_available() then - require("neocomplete.sources").complete(self.context, source, function(items, is_incomplete) + require("care.sources").complete(self.context, source, function(items, is_incomplete) source.incomplete = is_incomplete or false source.entries = items - require("neocomplete.sources").sources[i].incomplete = is_incomplete or false - require("neocomplete.sources").sources[i].entries = items + require("care.sources").sources[i].incomplete = is_incomplete or false + require("care.sources").sources[i].entries = items remaining = remaining - 1 if not vim.tbl_isempty(items or {}) then local source_offset = source:get_offset(self.context) @@ -65,7 +65,7 @@ function core.setup(self) callback = function() self:on_change() end, - group = "neocomplete", + group = "care", }) end @@ -80,8 +80,8 @@ function core.on_change(self) if self.blocked then return end - self.context = require("neocomplete.context").new(self.context) - if not require("neocomplete.config").options.enabled() then + self.context = require("care.context").new(self.context) + if not require("care.config").options.enabled() then return end if not self.context:changed() then diff --git a/lua/neocomplete/entry.lua b/lua/care/entry.lua similarity index 97% rename from lua/neocomplete/entry.lua rename to lua/care/entry.lua index 6f84c6e..9698978 100644 --- a/lua/neocomplete/entry.lua +++ b/lua/care/entry.lua @@ -1,9 +1,9 @@ ----@type neocomplete.entry +---@type care.entry ---@diagnostic disable-next-line: missing-fields local Entry = {} function Entry.new(completion_item, source, context) - ---@type neocomplete.entry + ---@type care.entry local self = setmetatable({}, { __index = Entry }) self.completion_item = completion_item self.source = source diff --git a/lua/neocomplete/ghost_text.lua b/lua/care/ghost_text.lua similarity index 75% rename from lua/neocomplete/ghost_text.lua rename to lua/care/ghost_text.lua index 5fea809..7f71169 100644 --- a/lua/neocomplete/ghost_text.lua +++ b/lua/care/ghost_text.lua @@ -1,28 +1,28 @@ ----@class neocomplete.ghost_text ----@field entry neocomplete.entry? +---@class care.ghost_text +---@field entry care.entry? ---@field ns integer ---@field win integer? ---@field extmark_id integer? ----@field new fun(): neocomplete.ghost_text ----@field config neocomplete.config.ui.ghost_text ----@field hide fun(self: neocomplete.ghost_text): nil ----@field show fun(self: neocomplete.ghost_text, entry: neocomplete.entry?, window: integer): nil +---@field new fun(): care.ghost_text +---@field config care.config.ui.ghost_text +---@field hide fun(self: care.ghost_text): nil +---@field show fun(self: care.ghost_text, entry: care.entry?, window: integer): nil ----@type neocomplete.ghost_text +---@type care.ghost_text ---@diagnostic disable-next-line: missing-fields local Ghost_text = {} function Ghost_text.new() - ---@type neocomplete.ghost_text + ---@type care.ghost_text local self = setmetatable({}, { __index = Ghost_text }) - self.ns = vim.api.nvim_create_namespace("neocomplete.ghost_text") - ---@type neocomplete.entry? + self.ns = vim.api.nvim_create_namespace("care.ghost_text") + ---@type care.entry? self.entry = nil ---@type integer? self.win = nil ---@type integer? self.extmark_id = nil - self.config = require("neocomplete.config").options.ui.ghost_text + self.config = require("care.config").options.ui.ghost_text vim.api.nvim_set_decoration_provider(self.ns, { on_win = function(_, win) return win == self.win @@ -42,13 +42,13 @@ function Ghost_text.new() if self.config.position == "inline" then self.extmark_id = vim.api.nvim_buf_set_extmark(vim.api.nvim_get_current_buf(), self.ns, cursor[1] - 1, cursor[2], { - virt_text = { { text_after_filter, "@neocomplete.ghost_text" } }, + virt_text = { { text_after_filter, "@care.ghost_text" } }, virt_text_pos = "inline", }) elseif self.config.position == "overlay" then self.extmark_id = vim.api.nvim_buf_set_extmark(vim.api.nvim_get_current_buf(), self.ns, cursor[1] - 1, cursor[2], { - virt_text = { { text_after_filter, "@neocomplete.ghost_text" } }, + virt_text = { { text_after_filter, "@care.ghost_text" } }, virt_text_pos = "overlay", ephemeral = true, }) diff --git a/lua/neocomplete/highlights.lua b/lua/care/highlights.lua similarity index 52% rename from lua/neocomplete/highlights.lua rename to lua/care/highlights.lua index c22aece..e089187 100644 --- a/lua/neocomplete/highlights.lua +++ b/lua/care/highlights.lua @@ -1,8 +1,8 @@ --[[ -@neocomplete: Fallback for everything -@neocomplete.type: Fallback for the type highlights (only one defined) -@neocomplete.selected: Selected entry -@neocomplete.match: Matched part of entries +@care: Fallback for everything +@care.type: Fallback for the type highlights (only one defined) +@care.selected: Selected entry +@care.match: Matched part of entries --]] -- TODO: move into function? @@ -40,14 +40,14 @@ local kinds = { } for name, group in pairs(kinds) do - hl(string.format("@neocomplete.type.%s", name), { link = group, default = true }) + hl(string.format("@care.type.%s", name), { link = group, default = true }) end -hl("@neocomplete", { link = "Normal", default = true }) -hl("@neocomplete.type", { link = "Normal", default = true }) -hl("@neocomplete.selected", { link = "Visual", default = true }) -hl("@neocomplete.match", { link = "Special", default = true }) -hl("@neocomplete.menu", { link = "NormalFloat", default = true }) -hl("@neocomplete.scrollbar", { link = "PmenuSbar", default = true }) -hl("@neocomplete.entry", { italic = true, default = true }) -hl("@neocomplete.ghost_text", { link = "Comment", default = true }) +hl("@care", { link = "Normal", default = true }) +hl("@care.type", { link = "Normal", default = true }) +hl("@care.selected", { link = "Visual", default = true }) +hl("@care.match", { link = "Special", default = true }) +hl("@care.menu", { link = "NormalFloat", default = true }) +hl("@care.scrollbar", { link = "PmenuSbar", default = true }) +hl("@care.entry", { italic = true, default = true }) +hl("@care.ghost_text", { link = "Comment", default = true }) diff --git a/lua/care/init.lua b/lua/care/init.lua new file mode 100644 index 0000000..60e0d71 --- /dev/null +++ b/lua/care/init.lua @@ -0,0 +1,62 @@ +local care = {} + +_G.care_debug = false + +---@type care.core +care.core = nil + +local function on_insert_enter() + care.core = require("care.core").new() + care.core:setup() +end + +care.api = { + get_fallback = function(key) + return require("care.mappings").get_fallback(key) + end, + is_open = function() + return care.core and care.core.menu:is_open() + end, + confirm = function() + care.core.menu:confirm() + end, + complete = function() + care.core:complete(2) + end, + close = function() + care.core.menu:close() + end, + select_prev = function(count) + care.core.menu:select_prev(count) + end, + select_next = function(count) + care.core.menu:select_next(count) + end, + jump_to_entry = function(index) + care.core.menu.index = index + end, + doc_is_open = function() + return care.core and care.core.menu and care.core.menu:docs_visible() + end, + scroll_docs = function(delta) + care.core.menu:scroll_docs(delta) + end, +} + +--- Sets up care +function care.setup(options) + require("care.mappings").setup() + require("care.config").setup(options) + require("care.highlights") + + local augroup = vim.api.nvim_create_augroup("care", {}) + vim.api.nvim_create_autocmd("InsertEnter", { + callback = function() + on_insert_enter() + end, + once = true, + group = augroup, + }) +end + +return care diff --git a/lua/neocomplete/mappings.lua b/lua/care/mappings.lua similarity index 59% rename from lua/neocomplete/mappings.lua rename to lua/care/mappings.lua index ca05b2c..09fc065 100644 --- a/lua/neocomplete/mappings.lua +++ b/lua/care/mappings.lua @@ -12,7 +12,7 @@ end local function map(plug, callback) vim.keymap.set("i", plug, function() - if require("neocomplete").api.is_open() then + if require("care").api.is_open() then callback() else vim.api.nvim_feedkeys(vim.keycode(get_mapping(plug)), "n", false) @@ -21,20 +21,20 @@ local function map(plug, callback) end function mappings.setup() - map("(NeocompleteConfirm)", function() - require("neocomplete").api.confirm() + map("(CareConfirm)", function() + require("care").api.confirm() end) - map("(NeocompleteSelectNext)", function() - require("neocomplete").api.select_next(1) + map("(CareSelectNext)", function() + require("care").api.select_next(1) end) - map("(NeocompleteSelectPrev)", function() - require("neocomplete").api.select_prev(1) + map("(CareSelectPrev)", function() + require("care").api.select_prev(1) end) - map("(NeocompleteClose)", function() - require("neocomplete").api.close() + map("(CareClose)", function() + require("care").api.close() end) end diff --git a/lua/neocomplete/menu/confirm.lua b/lua/care/menu/confirm.lua similarity index 93% rename from lua/neocomplete/menu/confirm.lua rename to lua/care/menu/confirm.lua index 3a68926..fdc6244 100644 --- a/lua/neocomplete/menu/confirm.lua +++ b/lua/care/menu/confirm.lua @@ -10,16 +10,16 @@ local function normalize_entry(entry) return entry end ----@param entry neocomplete.entry +---@param entry care.entry return function(entry) - local config = require("neocomplete.config").options - if _G.neocomplete_debug then + local config = require("care.config").options + if _G.care_debug then vim.print(entry.completion_item) vim.print(entry.context) end - local cur_ctx = require("neocomplete.context").new() - local unblock = require("neocomplete").core:block() + local cur_ctx = require("care.context").new() + local unblock = require("care").core:block() local completion_item = entry.completion_item completion_item = normalize_entry(completion_item) @@ -36,7 +36,7 @@ return function(entry) ) vim.api.nvim_win_set_cursor(0, { entry.context.cursor.row, entry.context.cursor.col }) - cur_ctx = require("neocomplete.context").new() + cur_ctx = require("care.context").new() -- TODO: entry.insertTextMode local is_snippet = completion_item.insertTextFormat == 2 diff --git a/lua/neocomplete/menu/draw.lua b/lua/care/menu/draw.lua similarity index 92% rename from lua/neocomplete/menu/draw.lua rename to lua/care/menu/draw.lua index 265960d..c32c369 100644 --- a/lua/neocomplete/menu/draw.lua +++ b/lua/care/menu/draw.lua @@ -1,5 +1,5 @@ -local format_utils = require("neocomplete.utils.format") -local utils = require("neocomplete.utils") +local format_utils = require("care.utils.format") +local utils = require("care.utils") local function get_texts(aligned_sec) local texts = {} @@ -33,7 +33,7 @@ local function add_extmarks(aligned_sec, realign, buf, ns, column) end end ----@param self neocomplete.menu +---@param self care.menu return function(self) local alignment = self.config.ui.menu.alignment local width, entry_texts = format_utils.get_width(self.entries) @@ -49,7 +49,7 @@ return function(self) for i = 0, #self.entries do if i == self.index then vim.api.nvim_buf_set_extmark(self.menu_window.buf, self.ns, i - 1, 0, { - virt_text = { { string.rep(" ", width), "@neocomplete.selected" } }, + virt_text = { { string.rep(" ", width), "@care.selected" } }, virt_text_pos = "overlay", }) end @@ -90,7 +90,7 @@ return function(self) end for line, entry in ipairs(self.entries) do for _, idx in ipairs(entry.matches or {}) do - vim.api.nvim_buf_add_highlight(self.menu_window.buf, self.ns, "@neocomplete.match", line - 1, idx - 1, idx) + vim.api.nvim_buf_add_highlight(self.menu_window.buf, self.ns, "@care.match", line - 1, idx - 1, idx) end end end diff --git a/lua/neocomplete/menu/init.lua b/lua/care/menu/init.lua similarity index 89% rename from lua/neocomplete/menu/init.lua rename to lua/care/menu/init.lua index 10e88c7..8ca026e 100644 --- a/lua/neocomplete/menu/init.lua +++ b/lua/care/menu/init.lua @@ -1,23 +1,23 @@ ----@type neocomplete.menu +---@type care.menu ---@diagnostic disable-next-line: missing-fields local Menu = {} -local format_utils = require("neocomplete.utils.format") +local format_utils = require("care.utils.format") function Menu.new() - ---@type neocomplete.menu + ---@type care.menu local self = setmetatable({}, { __index = Menu }) self.entries = nil - self.ns = vim.api.nvim_create_namespace("neocomplete") - self.config = require("neocomplete.config").options + self.ns = vim.api.nvim_create_namespace("care") + self.config = require("care.config").options self.index = 0 - self.menu_window = require("neocomplete.utils.window").new() - self.docs_window = require("neocomplete.utils.window").new() - self.ghost_text = require("neocomplete.ghost_text").new() + self.menu_window = require("care.utils.window").new() + self.docs_window = require("care.utils.window").new() + self.ghost_text = require("care.ghost_text").new() return self end -Menu.draw = require("neocomplete.menu.draw") +Menu.draw = require("care.menu.draw") function Menu:readjust_win(offset) self.index = 0 @@ -35,13 +35,13 @@ function Menu.close(self) self.menu_window:close() self.docs_window:close() self.ghost_text:hide() - local sources = require("neocomplete.sources").get_sources() + local sources = require("care.sources").get_sources() for i, _ in ipairs(sources) do - require("neocomplete.sources").sources[i].entries = nil + require("care.sources").sources[i].entries = nil end end ----@param menu neocomplete.menu +---@param menu care.menu local function draw_docs(menu, entry, config) if not entry then return @@ -184,7 +184,7 @@ function Menu:confirm() if not entry then return end - require("neocomplete.menu.confirm")(entry) + require("care.menu.confirm")(entry) self.ghost_text:hide() self.menu_window:close() self.docs_window:close() diff --git a/lua/neocomplete/sorter.lua b/lua/care/sorter.lua similarity index 92% rename from lua/neocomplete/sorter.lua rename to lua/care/sorter.lua index ec55adb..ecc6efb 100644 --- a/lua/neocomplete/sorter.lua +++ b/lua/care/sorter.lua @@ -3,11 +3,11 @@ local sorter = {} --- Filters and sorts entries by a prefix using fzy algorithm --- Sets `score` and `matches` field of remaining entries ----@param entries neocomplete.entry[] +---@param entries care.entry[] ---@param prefix string ----@return neocomplete.entry[] +---@return care.entry[] function sorter.sort(entries, prefix) - ---@param entry neocomplete.entry + ---@param entry care.entry local function get_filter_text(entry) -- TODO: makes more sense like this because label is what user sees? -- return entry.filterText or entry.label diff --git a/lua/neocomplete/source.lua b/lua/care/source.lua similarity index 89% rename from lua/neocomplete/source.lua rename to lua/care/source.lua index 6deea35..25bef2d 100644 --- a/lua/neocomplete/source.lua +++ b/lua/care/source.lua @@ -1,9 +1,9 @@ ----@type neocomplete.internal_source +---@type care.internal_source ---@diagnostic disable-next-line: missing-fields local source = {} function source.new(completion_source) - ---@type neocomplete.internal_source + ---@type care.internal_source local self = setmetatable({}, { __index = source }) self.source = completion_source self.entries = {} @@ -11,7 +11,7 @@ function source.new(completion_source) end function source.get_keyword_pattern(self) - local keyword_pattern = require("neocomplete.config").options.keyword_pattern + local keyword_pattern = require("care.config").options.keyword_pattern if self.source.keyword_pattern then ---@type string keyword_pattern = self.source.keyword_pattern diff --git a/lua/neocomplete/sources.lua b/lua/care/sources.lua similarity index 69% rename from lua/neocomplete/sources.lua rename to lua/care/sources.lua index ea49a2b..4240ec6 100644 --- a/lua/neocomplete/sources.lua +++ b/lua/care/sources.lua @@ -1,24 +1,24 @@ -local neocomplete_sources = {} -local Entry = require("neocomplete.entry") +local care_sources = {} +local Entry = require("care.entry") ----@type neocomplete.internal_source[] -neocomplete_sources.sources = {} +---@type care.internal_source[] +care_sources.sources = {} ----@param completion_source neocomplete.source -function neocomplete_sources.register_source(completion_source) - local source = require("neocomplete.source").new(completion_source) - table.insert(neocomplete_sources.sources, source) +---@param completion_source care.source +function care_sources.register_source(completion_source) + local source = require("care.source").new(completion_source) + table.insert(care_sources.sources, source) end ----@return neocomplete.internal_source[] -function neocomplete_sources.get_sources() - return vim.deepcopy(neocomplete_sources.sources) +---@return care.internal_source[] +function care_sources.get_sources() + return vim.deepcopy(care_sources.sources) end ----@param context neocomplete.context ----@param source neocomplete.internal_source ----@param callback fun(items: neocomplete.entry[], is_incomplete?: boolean) -function neocomplete_sources.complete(context, source, callback) +---@param context care.context +---@param source care.internal_source +---@param callback fun(items: care.entry[], is_incomplete?: boolean) +function care_sources.complete(context, source, callback) local last_char = context.line_before_cursor:sub(-1) ---@type lsp.CompletionContext local completion_context @@ -34,7 +34,7 @@ function neocomplete_sources.complete(context, source, callback) } elseif not source.incomplete then -- TODO: cleanup - local keyword_pattern = require("neocomplete.config").options.keyword_pattern + local keyword_pattern = require("care.config").options.keyword_pattern if source.source.keyword_pattern then keyword_pattern = source.source.keyword_pattern end @@ -50,7 +50,7 @@ function neocomplete_sources.complete(context, source, callback) local prefix = context.line:sub(word_boundary + 1, context.cursor.col) - callback(require("neocomplete.sorter").sort(source.entries, prefix)) + callback(require("care.sorter").sort(source.entries, prefix)) return end else @@ -71,7 +71,7 @@ function neocomplete_sources.complete(context, source, callback) return Entry.new(item, source, context) end) :totable() - local keyword_pattern = require("neocomplete.config").options.keyword_pattern + local keyword_pattern = require("care.config").options.keyword_pattern if source.source.keyword_pattern then keyword_pattern = source.source.keyword_pattern end @@ -87,9 +87,9 @@ function neocomplete_sources.complete(context, source, callback) local prefix = context.line:sub(word_boundary + 1, context.cursor.col) - callback(require("neocomplete.sorter").sort(items, prefix), is_incomplete) + callback(require("care.sorter").sort(items, prefix), is_incomplete) end ) end -return neocomplete_sources +return care_sources diff --git a/lua/neocomplete/types/config.lua b/lua/care/types/config.lua similarity index 54% rename from lua/neocomplete/types/config.lua rename to lua/care/types/config.lua index 5e732c4..73b3b6b 100644 --- a/lua/neocomplete/types/config.lua +++ b/lua/care/types/config.lua @@ -1,31 +1,31 @@ ---- Configuration for neocomplete.nvim ----@class neocomplete.config ---- Configuration for the ui of neocomplete ----@field ui neocomplete.config.ui +--- Configuration for care.nvim +---@class care.config +--- Configuration for the ui of care +---@field ui care.config.ui --- Function used to expand snippets ---@field snippet_expansion fun(string): nil --- Behavior when selecting entry ---@field selection_behavior "select"|"insert" --- Pattern used to determine keywords ---@field keyword_pattern string ---- Configuration for the ui of neocomplete +--- Configuration for the ui of care ---@field enabled fun(): boolean ---- The main class for the ui configuration of neocomplete.nvim ----@class neocomplete.config.ui ---- Configuration of the completion menu of neocomplete.nvim ----@field menu neocomplete.config.ui.menu ---- Configuration of the documentation view of neocomplete.nvim ----@field docs_view neocomplete.config.ui.docs +--- The main class for the ui configuration of care.nvim +---@class care.config.ui +--- Configuration of the completion menu of care.nvim +---@field menu care.config.ui.menu +--- Configuration of the documentation view of care.nvim +---@field docs_view care.config.ui.docs --- The icons for the different compltion item kinds ----@field type_icons neocomplete.config.ui.type_icons +---@field type_icons care.config.ui.type_icons --- Configuration of ghost text ----@field ghost_text neocomplete.config.ui.ghost_text +---@field ghost_text care.config.ui.ghost_text ----@class neocomplete.config.ui.ghost_text +---@class care.config.ui.ghost_text ---@field enabled boolean ---@field position "inline"|"overlay" ---- Configuration of the completion menu of neocomplete.nvim ----@class neocomplete.config.ui.menu +--- Configuration of the completion menu of care.nvim +---@class care.config.ui.menu --- Maximum height of the menu ---@field max_height integer --- The border of the completion menu @@ -35,11 +35,11 @@ --- Position of the menu ---@field position "auto"|"bottom"|"top" --- How an entry should be formatted ----@field format_entry fun(entry: neocomplete.entry): { [1]: string, [2]: string }[][] +---@field format_entry fun(entry: care.entry): { [1]: string, [2]: string }[][] --- How the sections in the menu should be aligned ---@field alignment ("left"|"center"|"right")[] ---- Configuration of the completion menu of neocomplete.nvim ----@class neocomplete.config.ui.docs +--- Configuration of the completion menu of care.nvim +---@class care.config.ui.docs --- Maximum height of the documentation view ---@field max_height integer --- Maximum width of the documentation view @@ -49,4 +49,4 @@ --- Character used for the scrollbar ---@field scrollbar string --- The icons used for the different completion item types ----@alias neocomplete.config.ui.type_icons table \ No newline at end of file +---@alias care.config.ui.type_icons table diff --git a/lua/neocomplete/types/context.lua b/lua/care/types/context.lua similarity index 55% rename from lua/neocomplete/types/context.lua rename to lua/care/types/context.lua index 9ed2270..1e4cd02 100644 --- a/lua/neocomplete/types/context.lua +++ b/lua/care/types/context.lua @@ -1,22 +1,22 @@ --- Context provided to completion sources ----@class neocomplete.context +---@class care.context --- Context changed since previous ----@field changed fun(neocomplete.context): boolean +---@field changed fun(care.context): boolean --- Create a new context ----@field new fun(previous: neocomplete.context?): neocomplete.context +---@field new fun(previous: care.context?): care.context --- The previous context ----@field previous neocomplete.context? +---@field previous care.context? --- The cursor position ----@field cursor neocomplete.context.cursor +---@field cursor care.context.cursor --- The number of the buffer ---@field bufnr integer --- Reason for triggering completion ----@field reason neocomplete.completionReason? +---@field reason care.completionReason? --- Current line ---@field line string --- Line before cursor ---@field line_before_cursor string --- A cursor position ----@class neocomplete.context.cursor +---@class care.context.cursor ---@field row integer ---@field col integer diff --git a/lua/care/types/core.lua b/lua/care/types/core.lua new file mode 100644 index 0000000..3c24749 --- /dev/null +++ b/lua/care/types/core.lua @@ -0,0 +1,21 @@ +--- The core module of care +---@class care.core +--- Create a new instance of the core +---@field new fun(): care.core +--- Complete +---@field complete fun(self: care.core, reason: care.completionReason?): nil +--- The function that gets invoked when the text changes +---@field on_change fun(care.core): nil +--- Block care temporarily +--- Call return value to unblock +---@field block fun(care.core): fun(): nil +--- Setup core (for now autocommands) +---@field setup fun(self: care.core): nil +--- Context instance of the core +---@field context care.context +--- Menu instance of the core +---@field menu care.menu +--- Block autocompletion +---@field blocked boolean +--- Column where a new menu was opened the last time +---@field last_opened_at integer diff --git a/lua/care/types/entry.lua b/lua/care/types/entry.lua new file mode 100644 index 0000000..b0ad6da --- /dev/null +++ b/lua/care/types/entry.lua @@ -0,0 +1,19 @@ +--- An entry for the care completion menu +---@class care.entry +---@field completion_item lsp.CompletionItem +--- Creates a new entry +---@field new fun(completion_item: lsp.CompletionItem, source: care.internal_source, context: care.context): care.entry +--- Get insert text +---@field get_insert_text fun(self: care.entry): string +--- Get insert word +---@field get_insert_word fun(self: care.entry): string +--- Source from which the entry came +---@field source care.internal_source +--- Context in which entry was completed +---@field context care.context +--- Matches in filter text +---@field matches integer[] +--- Score from filtering +---@field score number +--- Get offset of entry from beginning of line +---@field get_offset fun(self: care.entry): integer diff --git a/lua/care/types/internal_source.lua b/lua/care/types/internal_source.lua new file mode 100644 index 0000000..bceb332 --- /dev/null +++ b/lua/care/types/internal_source.lua @@ -0,0 +1,14 @@ +--- Internal class for care to store source metadata +---@class care.internal_source +--- The external completion source +---@field source care.source +--- The entries recieved by last completion +---@field entries care.entry[] +--- The entries recieved by last completion +---@field new fun(completion_source: care.source): care.internal_source +--- Whether the source is incomplete +---@field incomplete boolean +--- Get the keyword pattern +---@field get_keyword_pattern fun(self: care.internal_source): string +--- The offset at which completions from source were loaded +---@field get_offset fun(self: care.internal_source, context: care.context): integer diff --git a/lua/care/types/menu.lua b/lua/care/types/menu.lua new file mode 100644 index 0000000..6800c96 --- /dev/null +++ b/lua/care/types/menu.lua @@ -0,0 +1,48 @@ +--- The completion menu of care +---@class care.menu +--- Create a new instance of the menu +---@field new fun(): care.menu +--- Draws the menu +---@field draw fun(self: care.menu): nil +--- Returns true if completion window is visible +---@field is_open fun(self: care.menu): boolean +--- Select next entry in menu +---@field select_next fun(self: care.menu, count: integer): nil +--- Select previous entry in menu +---@field select_prev fun(self: care.menu, count: integer): nil +--- Opens the menu with specified entries +---@field open fun(self: care.menu, entries: care.entry[], offset: integer): nil +--- Closes the window of the menu +---@field close fun(self: care.menu): nil +--- Gets the currently selected entry +---@field get_active_entry fun(self: care.menu): care.entry? +--- Selects the current entry and inserts it's text +---@field confirm fun(self: care.menu): nil +--- Completes with the given entry +---@field complete fun(self: care.menu, entry: care.entry): nil +--- Readjust size of completino window +---@field readjust_win fun(self: care.menu, offset: integer): nil +--- Checks if docs are open +---@field docs_visible fun(self: care.menu): boolean +--- Scroll in the docs window +---@field scroll_docs fun(self: care.menu, delta: integer): nil +--- Wrapper for utilities for the window of the menu +---@field menu_window care.window +--- Wrapper for utilities for the window of the docs +---@field docs_window care.window +--- Instance of ghost text to draw the ghost text +---@field ghost_text care.ghost_text +--- Entries of the menu +---@field entries care.entry[] +--- Namespace used for the menu +---@field ns integer +--- Care config to be used in the menu +---@field config care.config +--- Buffer of the menu +---@field buf integer +--- Window of menu +---@field winnr integer? +--- Index of selected item +---@field index integer +--- Buffer for the scrollbar +---@field scrollbar_buf integer diff --git a/lua/neocomplete/types/misc.lua b/lua/care/types/misc.lua similarity index 57% rename from lua/neocomplete/types/misc.lua rename to lua/care/types/misc.lua index b85aa4b..5cf439a 100644 --- a/lua/neocomplete/types/misc.lua +++ b/lua/care/types/misc.lua @@ -1,8 +1,8 @@ --- Context provided to completion sources ----@class neocomplete.completion_context +---@class care.completion_context ---@field completion_context lsp.CompletionContext ----@field context neocomplete.context +---@field context care.context --- Reason for triggering completion ----@alias neocomplete.completionReason +---@alias care.completionReason ---| 1 # Auto ---| 2 # Manual diff --git a/lua/neocomplete/types/source.lua b/lua/care/types/source.lua similarity index 52% rename from lua/neocomplete/types/source.lua rename to lua/care/types/source.lua index 9f2f3df..19ebccc 100644 --- a/lua/neocomplete/types/source.lua +++ b/lua/care/types/source.lua @@ -1,16 +1,16 @@ ---- A completion source for neocomplete.nvim ----@class neocomplete.source +--- A completion source for care.nvim +---@class care.source --- Name of the source ---@field name string --- Whether the source will provide completions in the current context or not ---@field is_available? fun(): boolean --- Resolve a completion item ----@field resolve_item? fun(self: neocomplete.source, item: lsp.CompletionItem, callback: fun(item: lsp.CompletionItem)): nil +---@field resolve_item? fun(self: care.source, item: lsp.CompletionItem, callback: fun(item: lsp.CompletionItem)): nil --- Characters which should trigger new completions of the source ---@field get_trigger_characters? fun(): string[] --- Keyword pattern for this source ---@field keyword_pattern? string --- Get keyword pattern for this source ----@field get_keyword_pattern? fun(self: neocomplete.source): string +---@field get_keyword_pattern? fun(self: care.source): string --- Returns completion in the provided context ----@field complete fun(completion_context: neocomplete.completion_context, callback: fun(items: lsp.CompletionItem[], is_incomplete?: boolean)): nil \ No newline at end of file +---@field complete fun(completion_context: care.completion_context, callback: fun(items: lsp.CompletionItem[], is_incomplete?: boolean)): nil diff --git a/lua/neocomplete/types/window.lua b/lua/care/types/window.lua similarity index 56% rename from lua/neocomplete/types/window.lua rename to lua/care/types/window.lua index 0d6a5e5..bf57f4a 100644 --- a/lua/neocomplete/types/window.lua +++ b/lua/care/types/window.lua @@ -1,9 +1,9 @@ ----@class neocomplete.window +---@class care.window --- Creates a new instance of the menu window ----@field new fun(): neocomplete.window +---@field new fun(): care.window ---@field winnr? integer ---- Instance of the neocomplete config ----@field config neocomplete.config +--- Instance of the care config +---@field config care.config ---@field buf integer --- Whether the window is currently opened above or below the cursor ---@field position? "above"|"below" @@ -12,32 +12,32 @@ --- The maximum available height where the window is currently open ---@field max_height integer --- Method to check whether the window is open or not ----@field is_open fun(self: neocomplete.window): boolean +---@field is_open fun(self: care.window): boolean --- Method to check whether the scrollbar window is open or not ----@field scrollbar_is_open fun(self: neocomplete.window): boolean +---@field scrollbar_is_open fun(self: care.window): boolean --- Adjust the window size to new entries. Modifies height and width while keeping position ----@field readjust fun(self: neocomplete.window, content_len: integer, width: integer, offset: integer): nil +---@field readjust fun(self: care.window, content_len: integer, width: integer, offset: integer): nil --- Opens the window for the scrollbar ----@field open_scrollbar_win fun(self: neocomplete.window, width: integer, height: integer, offset: integer): nil +---@field open_scrollbar_win fun(self: care.window, width: integer, height: integer, offset: integer): nil --- Closes the window and the scrollbar window and resets fields ----@field close fun(self: neocomplete.window): nil +---@field close fun(self: care.window): nil --- Sets the scroll of the window ----@field set_scroll fun(self: neocomplete.window, index: integer, direction: integer): nil +---@field set_scroll fun(self: care.window, index: integer, direction: integer): nil --- Opens a new main window ----@field open_cursor_relative fun(self: neocomplete.window, width: integer, wanted_height: integer, offset: integer, config: neocomplete.config.ui.docs|neocomplete.config.ui.menu): nil +---@field open_cursor_relative fun(self: care.window, width: integer, wanted_height: integer, offset: integer, config: care.config.ui.docs|care.config.ui.menu): nil --- Draw the scrollbar for the window if needed ----@field draw_scrollbar fun(self: neocomplete.window): nil +---@field draw_scrollbar fun(self: care.window): nil --- Change scroll of window ----@field scroll fun(self: neocomplete.window, delta: integer) +---@field scroll fun(self: care.window, delta: integer) --- Where the window was last opened ---@field opened_at {row: integer, col: integer} --- Namespace used for setting extmarks ---@field ns integer --- Current scroll of the window ---@field current_scroll integer ----@field get_data fun(self: neocomplete.window): neocomplete.window.data +---@field get_data fun(self: care.window): care.window.data ----@class neocomplete.window.data +---@class care.window.data ---@field first_visible_line integer ---@field last_visible_line integer ---@field visible_lines integer diff --git a/lua/neocomplete/utils/async.lua b/lua/care/utils/async.lua similarity index 100% rename from lua/neocomplete/utils/async.lua rename to lua/care/utils/async.lua diff --git a/lua/neocomplete/utils/format.lua b/lua/care/utils/format.lua similarity index 92% rename from lua/neocomplete/utils/format.lua rename to lua/care/utils/format.lua index 81bc78b..fe66583 100644 --- a/lua/neocomplete/utils/format.lua +++ b/lua/care/utils/format.lua @@ -1,7 +1,7 @@ local format_utils = {} -local config = require("neocomplete.config").options -local utils = require("neocomplete.utils") +local config = require("care.config").options +local utils = require("care.utils") --- Gets the width a window for displaying entries must have ---@return number, string[] diff --git a/lua/neocomplete/utils/init.lua b/lua/care/utils/init.lua similarity index 100% rename from lua/neocomplete/utils/init.lua rename to lua/care/utils/init.lua diff --git a/lua/neocomplete/utils/lsp.lua b/lua/care/utils/lsp.lua similarity index 100% rename from lua/neocomplete/utils/lsp.lua rename to lua/care/utils/lsp.lua diff --git a/lua/neocomplete/utils/window.lua b/lua/care/utils/window.lua similarity index 97% rename from lua/neocomplete/utils/window.lua rename to lua/care/utils/window.lua index f4ac49d..07223f8 100644 --- a/lua/neocomplete/utils/window.lua +++ b/lua/care/utils/window.lua @@ -1,13 +1,13 @@ ----@type neocomplete.window +---@type care.window ---@diagnostic disable-next-line: missing-fields local Window = {} function Window.new() - ---@type neocomplete.window + ---@type care.window local self = setmetatable({}, { __index = Window }) self.winnr = nil - self.config = require("neocomplete.config").options - self.ns = vim.api.nvim_create_namespace("neocomplete_window") + self.config = require("care.config").options + self.ns = vim.api.nvim_create_namespace("care_window") self.buf = vim.api.nvim_create_buf(false, true) self.position = nil self.opened_at = {} diff --git a/lua/neocomplete/init.lua b/lua/neocomplete/init.lua deleted file mode 100644 index b3eb62f..0000000 --- a/lua/neocomplete/init.lua +++ /dev/null @@ -1,62 +0,0 @@ -local neocomplete = {} - -_G.neocomplete_debug = false - ----@type neocomplete.core -neocomplete.core = nil - -local function on_insert_enter() - neocomplete.core = require("neocomplete.core").new() - neocomplete.core:setup() -end - -neocomplete.api = { - get_fallback = function(key) - return require("neocomplete.mappings").get_fallback(key) - end, - is_open = function() - return neocomplete.core and neocomplete.core.menu:is_open() - end, - confirm = function() - neocomplete.core.menu:confirm() - end, - complete = function() - neocomplete.core:complete(2) - end, - close = function() - neocomplete.core.menu:close() - end, - select_prev = function(count) - neocomplete.core.menu:select_prev(count) - end, - select_next = function(count) - neocomplete.core.menu:select_next(count) - end, - jump_to_entry = function(index) - neocomplete.core.menu.index = index - end, - doc_is_open = function() - return neocomplete.core and neocomplete.core.menu and neocomplete.core.menu:docs_visible() - end, - scroll_docs = function(delta) - neocomplete.core.menu:scroll_docs(delta) - end, -} - ---- Sets up neocomplete -function neocomplete.setup(options) - require("neocomplete.mappings").setup() - require("neocomplete.config").setup(options) - require("neocomplete.highlights") - - local augroup = vim.api.nvim_create_augroup("neocomplete", {}) - vim.api.nvim_create_autocmd("InsertEnter", { - callback = function() - on_insert_enter() - end, - once = true, - group = augroup, - }) -end - -return neocomplete diff --git a/lua/neocomplete/types/core.lua b/lua/neocomplete/types/core.lua deleted file mode 100644 index f5066d8..0000000 --- a/lua/neocomplete/types/core.lua +++ /dev/null @@ -1,21 +0,0 @@ ---- The core module of neocomplete ----@class neocomplete.core ---- Create a new instance of the core ----@field new fun(): neocomplete.core ---- Complete ----@field complete fun(self: neocomplete.core, reason: neocomplete.completionReason?): nil ---- The function that gets invoked when the text changes ----@field on_change fun(neocomplete.core): nil ---- Block neocomplete temporarily ---- Call return value to unblock ----@field block fun(neocomplete.core): fun(): nil ---- Setup core (for now autocommands) ----@field setup fun(self: neocomplete.core): nil ---- Context instance of the core ----@field context neocomplete.context ---- Menu instance of the core ----@field menu neocomplete.menu ---- Block autocompletion ----@field blocked boolean ---- Column where a new menu was opened the last time ----@field last_opened_at integer \ No newline at end of file diff --git a/lua/neocomplete/types/entry.lua b/lua/neocomplete/types/entry.lua deleted file mode 100644 index 879affd..0000000 --- a/lua/neocomplete/types/entry.lua +++ /dev/null @@ -1,19 +0,0 @@ ---- An entry for the neocomplete completion menu ----@class neocomplete.entry ----@field completion_item lsp.CompletionItem ---- Creates a new entry ----@field new fun(completion_item: lsp.CompletionItem, source: neocomplete.internal_source, context: neocomplete.context): neocomplete.entry ---- Get insert text ----@field get_insert_text fun(self: neocomplete.entry): string ---- Get insert word ----@field get_insert_word fun(self: neocomplete.entry): string ---- Source from which the entry came ----@field source neocomplete.internal_source ---- Context in which entry was completed ----@field context neocomplete.context ---- Matches in filter text ----@field matches integer[] ---- Score from filtering ----@field score number ---- Get offset of entry from beginning of line ----@field get_offset fun(self: neocomplete.entry): integer \ No newline at end of file diff --git a/lua/neocomplete/types/internal_source.lua b/lua/neocomplete/types/internal_source.lua deleted file mode 100644 index 7f9316c..0000000 --- a/lua/neocomplete/types/internal_source.lua +++ /dev/null @@ -1,14 +0,0 @@ ---- Internal class for neocomplete to store source metadata ----@class neocomplete.internal_source ---- The external completion source ----@field source neocomplete.source ---- The entries recieved by last completion ----@field entries neocomplete.entry[] ---- The entries recieved by last completion ----@field new fun(completion_source: neocomplete.source): neocomplete.internal_source ---- Whether the source is incomplete ----@field incomplete boolean ---- Get the keyword pattern ----@field get_keyword_pattern fun(self: neocomplete.internal_source): string ---- The offset at which completions from source were loaded ----@field get_offset fun(self: neocomplete.internal_source, context: neocomplete.context): integer \ No newline at end of file diff --git a/lua/neocomplete/types/menu.lua b/lua/neocomplete/types/menu.lua deleted file mode 100644 index ca0ac9b..0000000 --- a/lua/neocomplete/types/menu.lua +++ /dev/null @@ -1,48 +0,0 @@ ---- The completion menu of neocomplete ----@class neocomplete.menu ---- Create a new instance of the menu ----@field new fun(): neocomplete.menu ---- Draws the menu ----@field draw fun(self: neocomplete.menu): nil ---- Returns true if completion window is visible ----@field is_open fun(self: neocomplete.menu): boolean ---- Select next entry in menu ----@field select_next fun(self: neocomplete.menu, count: integer): nil ---- Select previous entry in menu ----@field select_prev fun(self: neocomplete.menu, count: integer): nil ---- Opens the menu with specified entries ----@field open fun(self: neocomplete.menu, entries: neocomplete.entry[], offset: integer): nil ---- Closes the window of the menu ----@field close fun(self: neocomplete.menu): nil ---- Gets the currently selected entry ----@field get_active_entry fun(self: neocomplete.menu): neocomplete.entry? ---- Selects the current entry and inserts it's text ----@field confirm fun(self: neocomplete.menu): nil ---- Completes with the given entry ----@field complete fun(self: neocomplete.menu, entry: neocomplete.entry): nil ---- Readjust size of completino window ----@field readjust_win fun(self: neocomplete.menu, offset: integer): nil ---- Checks if docs are open ----@field docs_visible fun(self: neocomplete.menu): boolean ---- Scroll in the docs window ----@field scroll_docs fun(self: neocomplete.menu, delta: integer): nil ---- Wrapper for utilities for the window of the menu ----@field menu_window neocomplete.window ---- Wrapper for utilities for the window of the docs ----@field docs_window neocomplete.window ---- Instance of ghost text to draw the ghost text ----@field ghost_text neocomplete.ghost_text ---- Entries of the menu ----@field entries neocomplete.entry[] ---- Namespace used for the menu ----@field ns integer ---- Neocomplete config to be used in the menu ----@field config neocomplete.config ---- Buffer of the menu ----@field buf integer ---- Window of menu ----@field winnr integer? ---- Index of selected item ----@field index integer ---- Buffer for the scrollbar ----@field scrollbar_buf integer \ No newline at end of file diff --git a/minimal_init.lua b/minimal_init.lua index f9e2a92..82f8a83 100644 --- a/minimal_init.lua +++ b/minimal_init.lua @@ -24,9 +24,9 @@ local plugins = { -- do not remove the colorscheme! { "folke/tokyonight.nvim" }, { - "max397574/neocomplete.nvim", + "max397574/care.nvim", event = "InsertEnter", - dependencies = { "max397574/neocomplete-lsp" }, + dependencies = { "max397574/care-lsp" }, config = function() vim.keymap.set("i", "", function() vim.snippet.jump(1) @@ -35,25 +35,25 @@ local plugins = { vim.snippet.jump(-1) end) vim.keymap.set("i", "", function() - require("neocomplete").api.complete() + require("care").api.complete() end) - vim.keymap.set("i", "", "(NeocompleteConfirm)") - vim.keymap.set("i", "", "(NeocompleteClose)") - vim.keymap.set("i", "", "(NeocompleteSelectNext)") - vim.keymap.set("i", "", "(NeocompleteSelectPrev)") + vim.keymap.set("i", "", "(CareConfirm)") + vim.keymap.set("i", "", "(CareClose)") + vim.keymap.set("i", "", "(CareSelectNext)") + vim.keymap.set("i", "", "(CareSelectPrev)") vim.keymap.set("i", "", function() - if require("neocomplete").api.doc_is_open() then - require("neocomplete").api.scroll_docs(4) + if require("care").api.doc_is_open() then + require("care").api.scroll_docs(4) else vim.api.nvim_feedkeys(vim.keycode(""), "n", false) end end) vim.keymap.set("i", "", function() - if require("neocomplete").api.doc_is_open() then - require("neocomplete").api.scroll_docs(-4) + if require("care").api.doc_is_open() then + require("care").api.scroll_docs(-4) else vim.api.nvim_feedkeys(vim.keycode(""), "n", false) end @@ -61,7 +61,7 @@ local plugins = { vim.api.nvim_create_autocmd("InsertLeave", { callback = function() - require("neocomplete").api.close() + require("care").api.close() end, }) end, diff --git a/plugin/care.lua b/plugin/care.lua new file mode 100644 index 0000000..a9bb6ed --- /dev/null +++ b/plugin/care.lua @@ -0,0 +1,5 @@ +local loaded_care = false +if not loaded_care then + require("care").setup() + loaded_care = true +end diff --git a/plugin/neocomplete.lua b/plugin/neocomplete.lua deleted file mode 100644 index 1ececbc..0000000 --- a/plugin/neocomplete.lua +++ /dev/null @@ -1,5 +0,0 @@ -local loaded_neocomplete = false -if not loaded_neocomplete then - require("neocomplete").setup() - loaded_neocomplete = true -end diff --git a/readme.md b/readme.md index 6e9a19d..e16096a 100644 --- a/readme.md +++ b/readme.md @@ -1,8 +1,8 @@ -# neocomplete.nvim +# care.nvim initialized automatically -use require"neocomplete.config".setup({...}) to configure +use require"care.config".setup({...}) to configure credits mariasolos work in core and core in general diff --git a/spec/benches/menu/complete.lua b/spec/benches/menu/complete.lua index e04f51d..620ecd2 100644 --- a/spec/benches/menu/complete.lua +++ b/spec/benches/menu/complete.lua @@ -1,6 +1,6 @@ -- usage: `$ nvim --clean --headless -c "set runtimepath+=." -l spec/benches/menu/complete.lua` -local Context = require("neocomplete.context") -local Entry = require("neocomplete.entry") +local Context = require("care.context") +local Entry = require("care.entry") local function complete(completion_item, context) ---@diagnostic disable-next-line: missing-fields @@ -9,12 +9,12 @@ local function complete(completion_item, context) return [[\%(-\?\d\+\%(\.\d\+\)\?\|\h\w*\%(-\w*\)*\)]] end, }, context) - local menu = require("neocomplete.menu").new() + local menu = require("care.menu").new() menu:complete(entry) end local function do_complete() - require("neocomplete").core = { + require("care").core = { block = function() return function() end end, diff --git a/spec/benches/menu/draw.lua b/spec/benches/menu/draw.lua index 9a6de6f..bd21a77 100644 --- a/spec/benches/menu/draw.lua +++ b/spec/benches/menu/draw.lua @@ -1,6 +1,6 @@ -- usage: `$ nvim --clean --headless -c "set runtimepath+=." -l spec/benches/menu/draw.lua` -require("neocomplete").setup() -local core = require("neocomplete.core").new() +require("care").setup() +local core = require("care.core").new() local entries = require("spec.data.entries").minimal(10000) local start_time = os.clock() core.menu:open(entries, 0) diff --git a/spec/data/entries.lua b/spec/data/entries.lua index 0d5f4a3..54b5458 100644 --- a/spec/data/entries.lua +++ b/spec/data/entries.lua @@ -30,10 +30,10 @@ local kinds = { ---Creates an example source for testing ---It won't have any entries set ----@return neocomplete.internal_source +---@return care.internal_source local function example_source() - ---@type neocomplete.internal_source - local source = require("neocomplete.source").new({ + ---@type care.internal_source + local source = require("care.source").new({ complete = function() return {} end, @@ -43,12 +43,12 @@ end ---Returns `amount` completion items which have a `label` defined ---@param amount integer ----@return neocomplete.entry[] +---@return care.entry[] function entry_data.label_only(amount) ---@type lsp.CompletionItem[] local ret = {} for i = 1, amount do - table.insert(ret, require("neocomplete.entry").new({ label = "test" .. i }, example_source())) + table.insert(ret, require("care.entry").new({ label = "test" .. i }, example_source())) end return ret end @@ -62,7 +62,7 @@ function entry_data.minimal(amount) for i = 1, amount do table.insert( ret, - require("neocomplete.entry").new( + require("care.entry").new( { label = "test" .. i, kind = (i % #kinds) + 1, source = example_source() }, example_source() ) diff --git a/spec/tests/complete/eol_spec.lua b/spec/tests/complete/eol_spec.lua index 0445b53..d87586b 100644 --- a/spec/tests/complete/eol_spec.lua +++ b/spec/tests/complete/eol_spec.lua @@ -1,5 +1,5 @@ -local Context = require("neocomplete.context") -local Entry = require("neocomplete.entry") +local Context = require("care.context") +local Entry = require("care.entry") local function complete(completion_item, context) ---@diagnostic disable-next-line: missing-fields @@ -8,12 +8,12 @@ local function complete(completion_item, context) return [[\%(-\?\d\+\%(\.\d\+\)\?\|\h\w*\%(-\w*\)*\)]] end, }, context) - require("neocomplete.menu.confirm")(entry) + require("care.menu.confirm")(entry) end describe("Complete at EOL", function() before_each(function() - require("neocomplete").core = { + require("care").core = { block = function() return function() end end, diff --git a/spec/tests/complete/middle_of_line_spec.lua b/spec/tests/complete/middle_of_line_spec.lua index ea527f1..8a1674e 100644 --- a/spec/tests/complete/middle_of_line_spec.lua +++ b/spec/tests/complete/middle_of_line_spec.lua @@ -1,5 +1,5 @@ -local Context = require("neocomplete.context") -local Entry = require("neocomplete.entry") +local Context = require("care.context") +local Entry = require("care.entry") local function complete(completion_item, context) ---@diagnostic disable-next-line: missing-fields @@ -8,12 +8,12 @@ local function complete(completion_item, context) return [[\%(-\?\d\+\%(\.\d\+\)\?\|\h\w*\%(-\w*\)*\)]] end, }, context) - require("neocomplete.menu.confirm")(entry) + require("care.menu.confirm")(entry) end describe("Complete in middle of line", function() before_each(function() - require("neocomplete").core = { + require("care").core = { block = function() return function() end end, diff --git a/spec/tests/complete/old_bugs_spec.lua b/spec/tests/complete/old_bugs_spec.lua index 847b150..29de68d 100644 --- a/spec/tests/complete/old_bugs_spec.lua +++ b/spec/tests/complete/old_bugs_spec.lua @@ -1,5 +1,5 @@ -local Context = require("neocomplete.context") -local Entry = require("neocomplete.entry") +local Context = require("care.context") +local Entry = require("care.entry") local function complete(completion_item, context) ---@diagnostic disable-next-line: missing-fields @@ -8,12 +8,12 @@ local function complete(completion_item, context) return [[\%(-\?\d\+\%(\.\d\+\)\?\|\h\w*\%(-\w*\)*\)]] end, }, context) - require("neocomplete.menu.confirm")(entry) + require("care.menu.confirm")(entry) end describe("Old Bugs:", function() before_each(function() - require("neocomplete").core = { + require("care").core = { block = function() return function() end end, @@ -28,10 +28,10 @@ describe("Old Bugs:", function() local completion_item = { insertTextFormat = 2, kind = 17, - label = "neocomplete.menu", + label = "care.menu", sortText = "0216", textEdit = { - newText = "neocomplete.menu", + newText = "care.menu", range = { ["end"] = { character = 7, @@ -49,8 +49,8 @@ describe("Old Bugs:", function() entry_context.line_before_cursor = 'require"' complete(completion_item, entry_context) local context = Context:new() - assert.is.equal('require"neocomplete.menu', context.line) - assert.is.equal('require"neocomplete.menu', context.line_before_cursor) + assert.is.equal('require"care.menu', context.line) + assert.is.equal('require"care.menu', context.line_before_cursor) assert.is.equal(24, context.cursor.col) end) it("luals require doesn't remove quote when triggering manually", function() @@ -60,11 +60,11 @@ describe("Old Bugs:", function() local completion_item = { insertTextFormat = 2, kind = 17, - label = "neocomplete.menu", + label = "care.menu", sortText = "0039", documentation = "this", textEdit = { - newText = "neocomplete.menu", + newText = "care.menu", range = { ["end"] = { character = 10, @@ -80,21 +80,21 @@ describe("Old Bugs:", function() local entry_context = Context.new() complete(completion_item, entry_context) local context = Context:new() - assert.is.equal('require"neocomplete.menu', context.line) - assert.is.equal('require"neocomplete.menu', context.line_before_cursor) + assert.is.equal('require"care.menu', context.line) + assert.is.equal('require"care.menu', context.line_before_cursor) assert.is.equal(24, context.cursor.col) end) it("luals require module doesn't remove prefix correctly", function() - vim.fn.setline(1, 'require"neocomplete.me') + vim.fn.setline(1, 'require"care.me') vim.cmd.startinsert({ bang = true }) ---@type lsp.CompletionItem local completion_item = { insertTextFormat = 2, kind = 17, - label = "neocomplete.menu", + label = "care.menu", sortText = "0038", textEdit = { - newText = "neocomplete.menu", + newText = "care.menu", range = { ["end"] = { character = 19, @@ -110,8 +110,8 @@ describe("Old Bugs:", function() local entry_context = Context.new() complete(completion_item, entry_context) local context = Context:new() - assert.is.equal('require"neocomplete.menu', context.line) - assert.is.equal('require"neocomplete.menu', context.line_before_cursor) + assert.is.equal('require"care.menu', context.line) + assert.is.equal('require"care.menu', context.line_before_cursor) assert.is.equal(24, context.cursor.col) end) it("cmp-path doesn't set cursor properly", function() @@ -141,7 +141,7 @@ describe("Old Bugs:", function() return "\\%([^/\\\\:\\*?<>'\"`\\|]\\)" .. "*" end, }, entry_context) - require("neocomplete.menu.confirm")(entry) + require("care.menu.confirm")(entry) local context = Context:new() assert.is.equal(" ./init.lua", context.line) diff --git a/spec/tests/context_spec.lua b/spec/tests/context_spec.lua index 35e9f24..cd2554a 100644 --- a/spec/tests/context_spec.lua +++ b/spec/tests/context_spec.lua @@ -1,4 +1,4 @@ -local Context = require("neocomplete.context") +local Context = require("care.context") describe("Context", function() before_each(function() diff --git a/spec/tests/utils/async_spec.lua b/spec/tests/utils/async_spec.lua index 50f62c4..93cb91f 100644 --- a/spec/tests/utils/async_spec.lua +++ b/spec/tests/utils/async_spec.lua @@ -1,5 +1,5 @@ ---@diagnostic disable: need-check-nil -local async = require("neocomplete.utils.async") +local async = require("care.utils.async") describe("Throttle", function() local count diff --git a/spec/tests/utils/general_spec.lua b/spec/tests/utils/general_spec.lua index 98cca6f..fe23b1d 100644 --- a/spec/tests/utils/general_spec.lua +++ b/spec/tests/utils/general_spec.lua @@ -1,4 +1,4 @@ -local utils = require("neocomplete.utils") +local utils = require("care.utils") describe("Longest line", function() it("works with empty table", function() diff --git a/spec/tests/utils/lsp_spec.lua b/spec/tests/utils/lsp_spec.lua index 412ebf9..114b0f4 100644 --- a/spec/tests/utils/lsp_spec.lua +++ b/spec/tests/utils/lsp_spec.lua @@ -1,4 +1,4 @@ -local lsp_utils = require("neocomplete.utils.lsp") +local lsp_utils = require("care.utils.lsp") describe("Lsp utils get kind", function() it("invalid", function()