Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-reineke committed Oct 26, 2021
0 parents commit 6dd6760
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [lukas-reineke]
22 changes: 22 additions & 0 deletions .github/workflows/pr_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Pull request check

on:
pull_request:

jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: JohnnyMorganz/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --check .

block-fixup:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Block Fixup Commit Merge
uses: 13rac1/[email protected]
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT Licence

Copyright (c) 2021 Lukas Reineke

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# cmp-rg

[ripgrep](https://github.com/BurntSushi/ripgrep) source for [nvim-cmp](https://github.com/hrsh7th/nvim-cmp)

## Dependencies

You need to have `rg` and `sort` installed.

## Install

Use your favourite plugin manager to install.

#### Example with Packer

[wbthomason/packer.nvim](https://github.com/wbthomason/packer.nvim)

```lua
-- init.lua
require("packer").startup(
function()
use "lukas-reineke/cmp-rg"
end
)
```

#### Example with Plug

[junegunn/vim-plug](https://github.com/junegunn/vim-plug)

```vim
" init.vim
call plug#begin('~/.vim/plugged')
Plug 'lukas-reineke/cmp-rg'
call plug#end()
```

## Setup

Add `rg` to your cmp sources

```lua
require'cmp'.setup {
sources = {
{ name = 'rg' }
}
}
```

For more options see `:help cmp-rg`
5 changes: 5 additions & 0 deletions after/plugin/cmp-rg.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
local ok, cmp = pcall(require, "cmp")

if ok then
cmp.register_source("rg", require("cmp-rg").new())
end
75 changes: 75 additions & 0 deletions doc/cmp-rg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
*cmp-rg.txt* ripgrep source for nvim-cmp


Author: Lukas Reineke <[email protected]>
Version: 1.0.0

==============================================================================
CONTENTS *cmp-rg*

1. Options |cmp-rg-options|
2. Highlights |cmp-rg-highlights|
3. Setup |cmp-rg-setup|
4. Variables |cmp-rg-variables|
5. Commands |cmp-rg-commands|
6. Changelog |cmp-rg-changelog|
7. License |cmp-rg-license|

==============================================================================
1. OPTIONS *cmp-rg-options*

------------------------------------------------------------------------------
pattern *cmp-rg-pattern*

The pattern to search for matches with ripgrep.

Default: "[a-zA-Z_-]+" ~

------------------------------------------------------------------------------
additional_arguments *cmp-rg-additional_arguments*

Any additional arguments you want to pass to ripgrep.

Default: "" ~

------------------------------------------------------------------------------
cwd *cmp-rg-cwd*

Directory from where ripgrep will search.

Default: Current working directory ~

==============================================================================
6. CHANGELOG *cmp-rg-changelog*

1.0.0
* First release

==============================================================================
7. LICENSE *cmp-rg-license*

The MIT Licence
http://www.opensource.org/licenses/mit-license.php

Copyright (c) 2021 Lukas Reineke

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

==============================================================================
vim:tw=78:ts=8:ft=help:norl
48 changes: 48 additions & 0 deletions lua/cmp-rg/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
local source = {}

source.new = function()
return setmetatable({}, { __index = source })
end

source.complete = function(self, request, callback)
local q = string.sub(request.context.cursor_before_line, request.offset)
local pattern = request.option.pattern or "[a-zA-Z_-]+"
local additional_arguments = request.option.additional_arguments or ""
local items = {}

local function on_event(job_id, data, event)
if event == "stdout" then
for _, label in ipairs(data) do
table.insert(items, { label = label })
end
callback { items = items, isIncomplete = true }
end

if event == "stderr" then
vim.cmd "echohl Error"
vim.cmd('echomsg "' .. table.concat(data, "") .. '"')
vim.cmd "echohl None"
end

if event == "exit" then
callback { items = items, isIncomplete = false }
end
end

vim.fn.jobstart(
string.format(
"rg --no-filename --no-heading --no-line-number --color never --only-matching %s %s%s . | sort -u",
additional_arguments,
q,
pattern
),
{
on_stderr = on_event,
on_stdout = on_event,
on_exit = on_event,
cwd = request.option.cwd or vim.fn.getcwd(),
}
)
end

return source
4 changes: 4 additions & 0 deletions stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 4
no_call_parentheses = true

0 comments on commit 6dd6760

Please sign in to comment.