Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autopairs integration #118

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lua/care/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ config.defaults = {
position = "overlay",
},
},
integration = { autopairs = false },
snippet_expansion = function(snippet_body)
vim.snippet.expand(snippet_body)
end,
Expand Down
22 changes: 22 additions & 0 deletions lua/care/menu/confirm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@ return function(entry)
local is_snippet = completion_item.insertTextFormat == 2
local snippet_text

-- Integrates nvim-autopairs with care.nvim
if config.integration.autopairs then
local autopairs = require("nvim-autopairs")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still use pcall and use vim.notify to give a warning if autopairs is not available

because some people always manage to mess things up like this and I'd rather not get people reporting errors

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okey ill use pcall and vim.notify

local rules = autopairs.get_rules("(")
local handlers = require("nvim-autopairs.completion.handlers")
local is_function, is_method = completion_item.kind == 3, completion_item.kind == 2
local lisp_filetypes = { clojure = true, clojurescript = true, fennel = true, janet = true }
local is_lisp = lisp_filetypes[vim.bo.ft] == true
local is_python = vim.bo.ft == "python"
local buf = vim.api.nvim_get_current_buf()

if is_function or is_method then
if is_lisp then
handlers.lisp("(", completion_item, buf)
elseif is_python then
handlers.python("(", completion_item, buf, rules)
else
handlers["*"]("(", completion_item, buf, rules)
end
end
end

if not completion_item.textEdit then
---@diagnostic disable-next-line: missing-fields
completion_item.textEdit = {
Expand Down
5 changes: 5 additions & 0 deletions lua/care/types/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@
--- Auto will prefer right if there is enough space
---@field position? "auto"|"left"|"right"

--- Configuration of integrations with other plugin
---@class care.config.integration
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to myself: add to docgen so it gets link after merging

--- Enables the autopairs integration (default false)
---@field autopairs? boolean

--- Additional data passed to format function to allow more advanced formatting
---@class care.format_data
--- Index of the entry in the completion menu
Expand Down
Loading