Skip to content

Commit

Permalink
Merge branch 'main' into count_motions
Browse files Browse the repository at this point in the history
  • Loading branch information
tris203 authored Jun 3, 2024
2 parents 49f446a + d3f33a9 commit ff1771d
Show file tree
Hide file tree
Showing 10 changed files with 390 additions and 104 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: lua_ls-typecheck

on:
push:
branches:
- "main"
pull_request:
branches:
- "main"

jobs:
build:
name: Type Check Code Base
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: stevearc/nvim-typecheck-action@v2
with:
level: Warning
48 changes: 48 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Contributing

Contributions are welcome. What is expected from contributors is outlined below. If at any stage you require help, please just ask!

## Issues first

If there is something specific you want to work on, then please open an issue/discussion first to avoid duplication of efforts. Then:

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Make your changes
4. Review the steps below before committing your changes
5. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
6. Push to the Branch (`git push origin feature/AmazingFeature`)
7. Open a Pull Request

## Before committing changes

### Update documentation

Ensure that the `README.md` is updated where changed due to the new feature.

### Lua annotations

Any new or changed functions and module level locals should be annotated with Lua specs. These not only provide documentation but also assist the Language Server with completion and signature information. You can learn more about Lua annotations [here](https://luals.github.io/wiki/annotations/).

### Add tests

Tests should be added to cover any changes or new features. These can be found in the `tests` folder. To run the tests, [Make](https://www.gnu.org/software/make/) is required. Run `make test` from the repository root.

### Format code

This project uses [StyLua](https://github.com/JohnnyMorganz/StyLua) to ensure consistent code formatting.

The StyLua documentation details a number of ways this tool can be installed, including an executable you can just download. Then from the root of this repository run `stylua -g **/*.lua` (or `stylua -g **\*.lua` if on Windows).

Please run StyLua before committing your code. Do not commit the StyLua executable to this repository.

### Lint code

This project uses [Luacheck](https://github.com/mpeterv/luacheck) for static analysis and linting of the code.

### Continuous integration
The CI system used by this repository will run the tests, check the code formatting with Stylua, and lint the code with Luacheck. These checks must pass before a pull request can be merged, so performing these tasks locally first before committing will avoid having to push fix up commits.

### Conventional commits for Commits and PR

Please use the [Conventional Commits Specification](https://www.conventionalcommits.org/en/v1.0.0/) when writing your commit messages.
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,32 @@ return {
-- E = { text = "E", prio = 5 },
-- },
-- gutterHints = {
-- -- prio is not currently used for gutter hints
-- G = { text = "G", prio = 1 },
-- gg = { text = "gg", prio = 1 },
-- PrevParagraph = { text = "{", prio = 1 },
-- NextParagraph = { text = "}", prio = 1 },
-- G = { text = "G", prio = 10 },
-- gg = { text = "gg", prio = 9 },
-- PrevParagraph = { text = "{", prio = 8 },
-- NextParagraph = { text = "}", prio = 8 },
-- },
},
}
```

## ⚙️ Config

- Items can be hidden by settings their priority to 0, if you want to hide the
entire virtual line. Set all elements to `prio = 0` in combination with the
- `hints` can be hidden by setting their priority to 0. If you want to hide the
entire virtual line, set all elements to `prio = 0` in combination with the
below.
- `showBlankVirtLine = false`
Setting this option will mean that if a Virtual Line would be blank it wont be
Setting this option will mean that if a Virtual Line would be blank it won't be
rendered
- highlightColor can be set in two ways:
- `gutterHints` can be hidden by setting their priority to 0.
- `highlightColor` can be set in two ways:

1. As a table containing a link property pointing to an existing highlight group (see `:highlight` for valid options).
2. As a table specifying custom highlight values, such as foreground and background colors. ([more info](<https://neovim.io/doc/user/api.html#nvim_set_hl()>))
1. As a table containing a link property pointing to an existing highlight group (see `:highlight` for valid options).
2. As a table specifying custom highlight values, such as foreground and background colors. ([more info](<https://neovim.io/doc/user/api.html#nvim_set_hl()>))

### Hint priorities

Any hints that could appear in the same place as others should have unique priorities to avoid conflicts.

## ❔Usage

Expand Down Expand Up @@ -85,14 +89,10 @@ This plugin supports stable and nightly. >0.9 at the time of writing.

Contributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

If you have a suggestion to improve the plugin, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!
If you have a suggestion to improve the plugin, please open an issue first, fork the repo, and create a pull request.

If there is something specific you want to work on then, please open an issue/discussion first to avoid duplication of efforts
If you have found a bug please open an issue, or submit a PR with a failing test.
If you have found a bug please open an issue, and submit a pull request with a failing test if possible.

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request
More details on how to contribute can be found in CONTRIBUTING.md. Please read this prior to creating a pull request.

Don't forget to give the project a star! Thanks again!
37 changes: 21 additions & 16 deletions lua/precognition/horizontal_motions.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
local utils = require("precognition.utils")
local cc = utils.char_classes

local M = {}

local supportedBrackets = {
Expand All @@ -27,27 +24,29 @@ end

---@param str string
---@param cursorcol integer
---@param _linelen integer
---@param linelen integer
---@param big_word boolean
---@return Precognition.PlaceLoc
function M.next_word_boundary(str, cursorcol, _linelen, big_word)
function M.next_word_boundary(str, cursorcol, linelen, big_word)
local utils = require("precognition.utils")
local cc = utils.char_classes

local offset = cursorcol
local len = vim.fn.strcharlen(str)
local char = vim.fn.strcharpart(str, offset - 1, 1)
local c_class = utils.char_class(char, big_word)

if c_class ~= cc.whitespace then
while utils.char_class(char, big_word) == c_class and offset <= len do
while utils.char_class(char, big_word) == c_class and offset <= linelen do
offset = offset + 1
char = vim.fn.strcharpart(str, offset - 1, 1)
end
end

while utils.char_class(char, big_word) == cc.whitespace and offset <= len do
while utils.char_class(char, big_word) == cc.whitespace and offset <= linelen do
offset = offset + 1
char = vim.fn.strcharpart(str, offset - 1, 1)
end
if offset > len then
if offset > linelen then
return 0
end

Expand All @@ -63,14 +62,18 @@ function M.end_of_word(str, cursorcol, linelen, big_word)
if cursorcol >= linelen then
return 0
end
local utils = require("precognition.utils")
local cc = utils.char_classes

local offset = cursorcol
local char = vim.fn.strcharpart(str, offset - 1, 1)
local c_class = utils.char_class(char, big_word)
local next_char_class = utils.char_class(vim.fn.strcharpart(str, (offset - 1) + 1, 1), big_word)
local rev_offset

if
(c_class == cc.other and next_char_class ~= cc.other) or (next_char_class == cc.other and c_class ~= cc.other)
(c_class == cc.punctuation and next_char_class ~= cc.punctuation)
or (next_char_class == cc.punctuation and c_class ~= cc.punctuation)
then
offset = offset + 1
char = vim.fn.strcharpart(str, offset - 1, 1)
Expand Down Expand Up @@ -114,11 +117,13 @@ end

---@param str string
---@param cursorcol integer
---@param _linelen integer
---@param linelen integer
---@param big_word boolean
---@return Precognition.PlaceLoc
function M.prev_word_boundary(str, cursorcol, _linelen, big_word)
local len = vim.fn.strcharlen(str)
function M.prev_word_boundary(str, cursorcol, linelen, big_word)
local utils = require("precognition.utils")
local cc = utils.char_classes

local offset = cursorcol - 1
local char = vim.fn.strcharpart(str, offset - 1, 1)
local c_class = utils.char_class(char, big_word)
Expand All @@ -134,14 +139,14 @@ function M.prev_word_boundary(str, cursorcol, _linelen, big_word)
while utils.char_class(char, big_word) == c_class and offset >= 0 do
offset = offset - 1
char = vim.fn.strcharpart(str, offset - 1, 1)
--if remaining string is whitespace, return nil_wrap
--if remaining string is whitespace, return 0
local remaining = string.sub(str, offset)
if remaining:match("^%s*$") and #remaining > 0 then
return 0
end
end

if offset == nil or offset > len or offset < 0 then
if offset == nil or offset > linelen or offset < 0 then
return 0
end
return offset + 1
Expand Down Expand Up @@ -212,7 +217,7 @@ function M.matching_bracket(str, cursorcol, linelen)

if under_cursor == closeBracket then
local depth = 1
offset = offset - 2
offset = offset - 1
while offset >= 0 do
local char = vim.fn.strcharpart(str, offset - 1, 1)
if char == closeBracket then
Expand Down
Loading

0 comments on commit ff1771d

Please sign in to comment.