feat: rename everything
This commit is contained in:
parent
8f7442eaa2
commit
67116f38bc
16 changed files with 172 additions and 165 deletions
17
.github/DISCUSSION_TEMPLATE/q-a.yml
vendored
Normal file
17
.github/DISCUSSION_TEMPLATE/q-a.yml
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
title: "Q&A"
|
||||
labels: []
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Use this space for questions, ideas, and general discussion about diffs.nvim.
|
||||
For bug reports, please [open an issue](https://github.com/barrettruth/diffs.nvim/issues/new/choose) instead.
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Question or topic
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Context
|
||||
description: Any relevant details (Neovim version, config, screenshots)
|
||||
6
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
6
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
|
|
@ -7,7 +7,7 @@ body:
|
|||
attributes:
|
||||
label: Prerequisites
|
||||
options:
|
||||
- label: I have searched [existing issues](https://github.com/barrettruth/fugitive-ts.nvim/issues)
|
||||
- label: I have searched [existing issues](https://github.com/barrettruth/diffs.nvim/issues)
|
||||
required: true
|
||||
- label: I have updated to the latest version
|
||||
required: true
|
||||
|
|
@ -48,7 +48,7 @@ body:
|
|||
- type: textarea
|
||||
attributes:
|
||||
label: "Health check"
|
||||
description: "Output of `:checkhealth fugitive-ts`"
|
||||
description: "Output of `:checkhealth diffs`"
|
||||
render: text
|
||||
|
||||
- type: textarea
|
||||
|
|
@ -68,7 +68,7 @@ body:
|
|||
spec = {
|
||||
'tpope/vim-fugitive',
|
||||
{
|
||||
'barrettruth/fugitive-ts.nvim',
|
||||
'barrettruth/diffs.nvim',
|
||||
opts = {},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
2
.github/ISSUE_TEMPLATE/config.yml
vendored
2
.github/ISSUE_TEMPLATE/config.yml
vendored
|
|
@ -1,5 +1,5 @@
|
|||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Questions
|
||||
url: https://github.com/barrettruth/fugitive-ts.nvim/discussions
|
||||
url: https://github.com/barrettruth/diffs.nvim/discussions
|
||||
about: Ask questions and discuss ideas
|
||||
|
|
|
|||
2
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
2
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
|
|
@ -7,7 +7,7 @@ body:
|
|||
attributes:
|
||||
label: Prerequisites
|
||||
options:
|
||||
- label: I have searched [existing issues](https://github.com/barrettruth/fugitive-ts.nvim/issues)
|
||||
- label: I have searched [existing issues](https://github.com/barrettruth/diffs.nvim/issues)
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
|
|
|
|||
25
README.md
25
README.md
|
|
@ -1,16 +1,17 @@
|
|||
# fugitive-ts.nvim
|
||||
# diffs.nvim
|
||||
|
||||
**Treesitter syntax highlighting for vim-fugitive**
|
||||
**Syntax highlighting for diffs in Neovim**
|
||||
|
||||
Enhance the great `vim-fugitive` with syntax-aware code to easily work with
|
||||
diffs.
|
||||
Enhance vim-fugitive and Neovim's built-in diff mode with language-aware syntax
|
||||
highlighting.
|
||||
|
||||

|
||||

|
||||
|
||||
## Features
|
||||
|
||||
- Treesitter syntax highlighting in `:Git` diffs and commit views
|
||||
- `:Gdiffsplit` / `:Gvdiffsplit` syntax through diff backgrounds
|
||||
- Background-only diff colors for any `&diff` buffer
|
||||
- Vim syntax fallback for languages without a treesitter parser
|
||||
- Hunk header context highlighting (`@@ ... @@ function foo()`)
|
||||
- Configurable debouncing, max lines, and diff prefix concealment
|
||||
|
|
@ -26,7 +27,7 @@ Using [lazy.nvim](https://github.com/folke/lazy.nvim):
|
|||
|
||||
```lua
|
||||
{
|
||||
'barrettruth/fugitive-ts.nvim',
|
||||
'barrettruth/diffs.nvim',
|
||||
dependencies = { 'tpope/vim-fugitive' },
|
||||
opts = {},
|
||||
}
|
||||
|
|
@ -35,20 +36,18 @@ Using [lazy.nvim](https://github.com/folke/lazy.nvim):
|
|||
## Documentation
|
||||
|
||||
```vim
|
||||
:help fugitive-ts.nvim
|
||||
:help diffs.nvim
|
||||
```
|
||||
|
||||
## Known Limitations
|
||||
|
||||
- Syntax "flashing": `fugitive-ts.nvim` hooks into the `FileType fugitive` event
|
||||
triggered by `vim-fugitive`, at which point the `fugitive` buffer is
|
||||
preliminarily painted. The buffer is then re-painted after `debounce_ms`
|
||||
milliseconds, causing an unavoidable visual "flash" even when
|
||||
`debounce_ms = 0`. Feel free to reach out if you know how to fix this!
|
||||
- Syntax "flashing": diffs.nvim hooks into the `FileType fugitive` event
|
||||
triggered by vim-fugitive, at which point the buffer is preliminarily painted.
|
||||
The buffer is then re-painted after `debounce_ms` milliseconds, causing an
|
||||
unavoidable visual "flash" even when `debounce_ms = 0`.
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
- [vim-fugitive](https://github.com/tpope/vim-fugitive)
|
||||
- [codediff.nvim](https://github.com/esmuellert/codediff.nvim)
|
||||
- [diffview.nvim](https://github.com/sindrets/diffview.nvim)
|
||||
- [resolve.nvim](https://github.com/spacedentist/resolve.nvim)
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
rockspec_format = '3.0'
|
||||
package = 'fugitive-ts.nvim'
|
||||
package = 'diffs.nvim'
|
||||
version = 'scm-1'
|
||||
|
||||
source = {
|
||||
url = 'git+https://github.com/barrettruth/fugitive-ts.nvim.git',
|
||||
url = 'git+https://github.com/barrettruth/diffs.nvim.git',
|
||||
}
|
||||
|
||||
description = {
|
||||
summary = 'Treesitter syntax highlighting for vim-fugitive',
|
||||
homepage = 'https://github.com/barrettruth/fugitive-ts.nvim',
|
||||
summary = 'Syntax highlighting for diffs in Neovim',
|
||||
homepage = 'https://github.com/barrettruth/diffs.nvim',
|
||||
license = 'MIT',
|
||||
}
|
||||
|
||||
|
|
@ -1,54 +1,55 @@
|
|||
*fugitive-ts.nvim.txt* Treesitter highlighting for vim-fugitive diffs
|
||||
*diffs.nvim.txt* Syntax highlighting for diffs in Neovim
|
||||
|
||||
Author: Barrett Ruth <br.barrettruth@gmail.com>
|
||||
License: MIT
|
||||
|
||||
==============================================================================
|
||||
INTRODUCTION *fugitive-ts.nvim*
|
||||
INTRODUCTION *diffs.nvim*
|
||||
|
||||
fugitive-ts.nvim adds treesitter-based syntax highlighting to vim-fugitive
|
||||
diff views. It overlays language-aware highlights on top of fugitive's
|
||||
default regex-based diff highlighting.
|
||||
diffs.nvim adds syntax highlighting to diff views. It overlays language-aware
|
||||
highlights on top of default diff highlighting in vim-fugitive and Neovim's
|
||||
built-in diff mode.
|
||||
|
||||
Features: ~
|
||||
- Syntax highlighting in |:Git| summary diffs and commit detail views
|
||||
- Syntax highlighting in |:Gdiffsplit| / |:Gvdiffsplit| side-by-side diffs
|
||||
- Background-only diff colors for any `&diff` buffer (vimdiff, diffthis, etc.)
|
||||
- Vim syntax fallback for languages without a treesitter parser
|
||||
- Blended diff background colors that preserve syntax visibility
|
||||
- Optional diff prefix (`+`/`-`/` `) concealment
|
||||
- Gutter (line number) highlighting
|
||||
|
||||
==============================================================================
|
||||
REQUIREMENTS *fugitive-ts-requirements*
|
||||
REQUIREMENTS *diffs-requirements*
|
||||
|
||||
- Neovim 0.9.0+
|
||||
- vim-fugitive (https://github.com/tpope/vim-fugitive)
|
||||
- vim-fugitive (https://github.com/tpope/vim-fugitive) for unified diff views
|
||||
- Treesitter parsers for languages you want highlighted
|
||||
|
||||
==============================================================================
|
||||
SETUP *fugitive-ts-setup*
|
||||
SETUP *diffs-setup*
|
||||
|
||||
Using lazy.nvim: >lua
|
||||
{
|
||||
'barrettruth/fugitive-ts.nvim',
|
||||
'barrettruth/diffs.nvim',
|
||||
dependencies = { 'tpope/vim-fugitive' },
|
||||
opts = {},
|
||||
}
|
||||
<
|
||||
The plugin works automatically with no configuration required. For
|
||||
customization, see |fugitive-ts-config|.
|
||||
customization, see |diffs-config|.
|
||||
|
||||
==============================================================================
|
||||
CONFIGURATION *fugitive-ts-config*
|
||||
CONFIGURATION *diffs-config*
|
||||
|
||||
*fugitive-ts.Config*
|
||||
*diffs.Config*
|
||||
Fields: ~
|
||||
{enabled} (boolean, default: true)
|
||||
Enable or disable highlighting globally.
|
||||
|
||||
{debug} (boolean, default: false)
|
||||
Enable debug logging to |:messages| with
|
||||
`[fugitive-ts]` prefix.
|
||||
`[diffs]` prefix.
|
||||
|
||||
{debounce_ms} (integer, default: 0)
|
||||
Debounce delay in milliseconds for re-highlighting
|
||||
|
|
@ -64,17 +65,17 @@ CONFIGURATION *fugitive-ts-config*
|
|||
|
||||
{treesitter} (table, default: see below)
|
||||
Treesitter highlighting options.
|
||||
See |fugitive-ts.TreesitterConfig| for fields.
|
||||
See |diffs.TreesitterConfig| for fields.
|
||||
|
||||
{vim} (table, default: see below)
|
||||
Vim syntax highlighting options (experimental).
|
||||
See |fugitive-ts.VimConfig| for fields.
|
||||
See |diffs.VimConfig| for fields.
|
||||
|
||||
{highlights} (table, default: see below)
|
||||
Controls which highlight features are enabled.
|
||||
See |fugitive-ts.Highlights| for fields.
|
||||
See |diffs.Highlights| for fields.
|
||||
|
||||
*fugitive-ts.TreesitterConfig*
|
||||
*diffs.TreesitterConfig*
|
||||
Treesitter config fields: ~
|
||||
{enabled} (boolean, default: true)
|
||||
Apply treesitter syntax highlighting to code.
|
||||
|
|
@ -83,7 +84,7 @@ CONFIGURATION *fugitive-ts-config*
|
|||
Skip treesitter highlighting for hunks larger than
|
||||
this many lines. Prevents lag on massive diffs.
|
||||
|
||||
*fugitive-ts.VimConfig*
|
||||
*diffs.VimConfig*
|
||||
Vim config fields: ~
|
||||
{enabled} (boolean, default: false)
|
||||
Use vim syntax highlighting as fallback when no
|
||||
|
|
@ -98,12 +99,12 @@ CONFIGURATION *fugitive-ts-config*
|
|||
this many lines. Lower than the treesitter default
|
||||
due to the per-character cost of |synID()|.
|
||||
|
||||
*fugitive-ts.Highlights*
|
||||
*diffs.Highlights*
|
||||
Highlights table fields: ~
|
||||
{background} (boolean, default: true)
|
||||
Apply background highlighting to `+`/`-` lines
|
||||
using `FugitiveTsAdd`/`FugitiveTsDelete` groups
|
||||
(derived from `DiffAdd`/`DiffDelete` backgrounds).
|
||||
using `DiffsAdd`/`DiffsDelete` groups (derived
|
||||
from `DiffAdd`/`DiffDelete` backgrounds).
|
||||
|
||||
{gutter} (boolean, default: true)
|
||||
Highlight line numbers with matching colors.
|
||||
|
|
@ -118,22 +119,22 @@ CONFIGURATION *fugitive-ts-config*
|
|||
|vim.filetype.add()| and |vim.treesitter.language.register()|.
|
||||
|
||||
==============================================================================
|
||||
API *fugitive-ts-api*
|
||||
API *diffs-api*
|
||||
|
||||
setup({opts}) *fugitive-ts.setup()*
|
||||
setup({opts}) *diffs.setup()*
|
||||
Configure the plugin with `opts`.
|
||||
|
||||
Parameters: ~
|
||||
{opts} (|fugitive-ts.Config|, optional) Configuration table.
|
||||
{opts} (|diffs.Config|, optional) Configuration table.
|
||||
|
||||
attach({bufnr}) *fugitive-ts.attach()*
|
||||
attach({bufnr}) *diffs.attach()*
|
||||
Manually attach highlighting to a buffer. Called automatically for
|
||||
fugitive buffers via the `FileType fugitive` autocmd.
|
||||
|
||||
Parameters: ~
|
||||
{bufnr} (integer, optional) Buffer number. Defaults to current buffer.
|
||||
|
||||
refresh({bufnr}) *fugitive-ts.refresh()*
|
||||
refresh({bufnr}) *diffs.refresh()*
|
||||
Manually refresh highlighting for a buffer. Useful after external changes
|
||||
or for debugging.
|
||||
|
||||
|
|
@ -141,11 +142,11 @@ refresh({bufnr}) *fugitive-ts.refresh()*
|
|||
{bufnr} (integer, optional) Buffer number. Defaults to current buffer.
|
||||
|
||||
==============================================================================
|
||||
IMPLEMENTATION *fugitive-ts-implementation*
|
||||
IMPLEMENTATION *diffs-implementation*
|
||||
|
||||
Summary / commit detail views: ~
|
||||
1. `FileType fugitive` or `FileType git` (for `fugitive://` buffers)
|
||||
triggers |fugitive-ts.attach()|
|
||||
triggers |diffs.attach()|
|
||||
2. The buffer is parsed to detect file headers (`M path/to/file`,
|
||||
`diff --git a/... b/...`) and hunk headers (`@@ -10,3 +10,4 @@`)
|
||||
3. For each hunk:
|
||||
|
|
@ -154,45 +155,42 @@ Summary / commit detail views: ~
|
|||
- Code is parsed with |vim.treesitter.get_string_parser()|
|
||||
- If no treesitter parser and `vim.enabled`: vim syntax fallback via
|
||||
scratch buffer and |synID()|
|
||||
- Background extmarks (`FugitiveTsAdd`/`FugitiveTsDelete`) at priority 198
|
||||
- Background extmarks (`DiffsAdd`/`DiffsDelete`) at priority 198
|
||||
- `Normal` extmarks at priority 199 clear underlying diff foreground
|
||||
- Syntax highlights are applied as extmarks at priority 200
|
||||
- Conceal extmarks hide diff prefixes when `hide_prefix` is enabled
|
||||
4. Re-highlighting occurs on `TextChanged` (debounced) and `Syntax` events
|
||||
|
||||
Diffsplit views: ~
|
||||
1. `OptionSet diff` detects when a window enters diff mode
|
||||
2. If any `&diff` window in the tabpage contains a `fugitive://` buffer,
|
||||
all `&diff` windows receive a window-local 'winhighlight' override
|
||||
3. The override remaps `DiffAdd`/`DiffDelete`/`DiffChange`/`DiffText` to
|
||||
Diff mode views: ~
|
||||
1. `OptionSet diff` detects when any window enters diff mode
|
||||
2. All `&diff` windows in the tabpage receive a window-local 'winhighlight'
|
||||
override that remaps `DiffAdd`/`DiffDelete`/`DiffChange`/`DiffText` to
|
||||
background-only variants, allowing existing treesitter highlighting to
|
||||
show through the diff colors
|
||||
|
||||
==============================================================================
|
||||
KNOWN LIMITATIONS *fugitive-ts-limitations*
|
||||
KNOWN LIMITATIONS *diffs-limitations*
|
||||
|
||||
Syntax Highlighting Flash ~
|
||||
*fugitive-ts-flash*
|
||||
*diffs-flash*
|
||||
When opening a fugitive buffer, there is an unavoidable visual "flash" where
|
||||
the buffer briefly shows fugitive's default diff highlighting before
|
||||
fugitive-ts.nvim applies treesitter highlights.
|
||||
diffs.nvim applies treesitter highlights.
|
||||
|
||||
This occurs because fugitive-ts.nvim hooks into the `FileType fugitive` event,
|
||||
This occurs because diffs.nvim hooks into the `FileType fugitive` event,
|
||||
which fires after vim-fugitive has already painted the buffer. Even with
|
||||
`debounce_ms = 0`, the re-painting goes through Neovim's event loop.
|
||||
|
||||
To minimize the flash, use a low debounce value: >lua
|
||||
require('fugitive-ts').setup({
|
||||
require('diffs').setup({
|
||||
debounce_ms = 0,
|
||||
})
|
||||
<
|
||||
See https://github.com/barrettruth/fugitive-ts.nvim/issues/18 for discussion
|
||||
and potential solutions.
|
||||
|
||||
==============================================================================
|
||||
HEALTH CHECK *fugitive-ts-health*
|
||||
HEALTH CHECK *diffs-health*
|
||||
|
||||
Run |:checkhealth| fugitive-ts to verify your setup.
|
||||
Run |:checkhealth| diffs to verify your setup.
|
||||
|
||||
Checks performed:
|
||||
- Neovim version >= 0.9.0
|
||||
|
|
@ -1,19 +1,19 @@
|
|||
local M = {}
|
||||
|
||||
function M.check()
|
||||
vim.health.start('fugitive-ts.nvim')
|
||||
vim.health.start('diffs.nvim')
|
||||
|
||||
if vim.fn.has('nvim-0.9.0') == 1 then
|
||||
vim.health.ok('Neovim 0.9.0+ detected')
|
||||
else
|
||||
vim.health.error('fugitive-ts.nvim requires Neovim 0.9.0+')
|
||||
vim.health.error('diffs.nvim requires Neovim 0.9.0+')
|
||||
end
|
||||
|
||||
local fugitive_loaded = vim.fn.exists(':Git') == 2
|
||||
if fugitive_loaded then
|
||||
vim.health.ok('vim-fugitive detected')
|
||||
else
|
||||
vim.health.warn('vim-fugitive not detected (required for this plugin to be useful)')
|
||||
vim.health.warn('vim-fugitive not detected (required for unified diff highlighting)')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
local M = {}
|
||||
|
||||
local dbg = require('fugitive-ts.log').dbg
|
||||
local dbg = require('diffs.log').dbg
|
||||
|
||||
---@param bufnr integer
|
||||
---@param ns integer
|
||||
---@param hunk fugitive-ts.Hunk
|
||||
---@param hunk diffs.Hunk
|
||||
---@param col_offset integer
|
||||
---@param text string
|
||||
---@param lang string
|
||||
|
|
@ -49,15 +49,15 @@ local function highlight_text(bufnr, ns, hunk, col_offset, text, lang)
|
|||
return extmark_count
|
||||
end
|
||||
|
||||
---@class fugitive-ts.HunkOpts
|
||||
---@class diffs.HunkOpts
|
||||
---@field hide_prefix boolean
|
||||
---@field treesitter fugitive-ts.TreesitterConfig
|
||||
---@field vim fugitive-ts.VimConfig
|
||||
---@field highlights fugitive-ts.Highlights
|
||||
---@field treesitter diffs.TreesitterConfig
|
||||
---@field vim diffs.VimConfig
|
||||
---@field highlights diffs.Highlights
|
||||
|
||||
---@param bufnr integer
|
||||
---@param ns integer
|
||||
---@param hunk fugitive-ts.Hunk
|
||||
---@param hunk diffs.Hunk
|
||||
---@param code_lines string[]
|
||||
---@return integer
|
||||
local function highlight_treesitter(bufnr, ns, hunk, code_lines)
|
||||
|
|
@ -125,9 +125,9 @@ local function highlight_treesitter(bufnr, ns, hunk, code_lines)
|
|||
return extmark_count
|
||||
end
|
||||
|
||||
---@alias fugitive-ts.SyntaxQueryFn fun(line: integer, col: integer): integer, string
|
||||
---@alias diffs.SyntaxQueryFn fun(line: integer, col: integer): integer, string
|
||||
|
||||
---@param query_fn fugitive-ts.SyntaxQueryFn
|
||||
---@param query_fn diffs.SyntaxQueryFn
|
||||
---@param code_lines string[]
|
||||
---@return {line: integer, col_start: integer, col_end: integer, hl_name: string}[]
|
||||
function M.coalesce_syntax_spans(query_fn, code_lines)
|
||||
|
|
@ -168,7 +168,7 @@ end
|
|||
|
||||
---@param bufnr integer
|
||||
---@param ns integer
|
||||
---@param hunk fugitive-ts.Hunk
|
||||
---@param hunk diffs.Hunk
|
||||
---@param code_lines string[]
|
||||
---@return integer
|
||||
local function highlight_vim_syntax(bufnr, ns, hunk, code_lines)
|
||||
|
|
@ -223,8 +223,8 @@ end
|
|||
|
||||
---@param bufnr integer
|
||||
---@param ns integer
|
||||
---@param hunk fugitive-ts.Hunk
|
||||
---@param opts fugitive-ts.HunkOpts
|
||||
---@param hunk diffs.Hunk
|
||||
---@param opts diffs.HunkOpts
|
||||
function M.highlight_hunk(bufnr, ns, hunk, opts)
|
||||
local use_ts = hunk.lang and opts.treesitter.enabled
|
||||
local use_vim = not use_ts and hunk.ft and opts.vim.enabled
|
||||
|
|
@ -267,10 +267,8 @@ function M.highlight_hunk(bufnr, ns, hunk, opts)
|
|||
local prefix = line:sub(1, 1)
|
||||
|
||||
local is_diff_line = prefix == '+' or prefix == '-'
|
||||
local line_hl = is_diff_line and (prefix == '+' and 'FugitiveTsAdd' or 'FugitiveTsDelete')
|
||||
or nil
|
||||
local number_hl = is_diff_line and (prefix == '+' and 'FugitiveTsAddNr' or 'FugitiveTsDeleteNr')
|
||||
or nil
|
||||
local line_hl = is_diff_line and (prefix == '+' and 'DiffsAdd' or 'DiffsDelete') or nil
|
||||
local number_hl = is_diff_line and (prefix == '+' and 'DiffsAddNr' or 'DiffsDeleteNr') or nil
|
||||
|
||||
if opts.hide_prefix then
|
||||
local virt_hl = (opts.highlights.background and line_hl) or nil
|
||||
|
|
@ -1,35 +1,35 @@
|
|||
---@class fugitive-ts.Highlights
|
||||
---@class diffs.Highlights
|
||||
---@field background boolean
|
||||
---@field gutter boolean
|
||||
|
||||
---@class fugitive-ts.TreesitterConfig
|
||||
---@class diffs.TreesitterConfig
|
||||
---@field enabled boolean
|
||||
---@field max_lines integer
|
||||
|
||||
---@class fugitive-ts.VimConfig
|
||||
---@class diffs.VimConfig
|
||||
---@field enabled boolean
|
||||
---@field max_lines integer
|
||||
|
||||
---@class fugitive-ts.Config
|
||||
---@class diffs.Config
|
||||
---@field enabled boolean
|
||||
---@field debug boolean
|
||||
---@field debounce_ms integer
|
||||
---@field hide_prefix boolean
|
||||
---@field treesitter fugitive-ts.TreesitterConfig
|
||||
---@field vim fugitive-ts.VimConfig
|
||||
---@field highlights fugitive-ts.Highlights
|
||||
---@field treesitter diffs.TreesitterConfig
|
||||
---@field vim diffs.VimConfig
|
||||
---@field highlights diffs.Highlights
|
||||
|
||||
---@class fugitive-ts
|
||||
---@class diffs
|
||||
---@field attach fun(bufnr?: integer)
|
||||
---@field refresh fun(bufnr?: integer)
|
||||
---@field setup fun(opts?: fugitive-ts.Config)
|
||||
---@field setup fun(opts?: diffs.Config)
|
||||
local M = {}
|
||||
|
||||
local highlight = require('fugitive-ts.highlight')
|
||||
local log = require('fugitive-ts.log')
|
||||
local parser = require('fugitive-ts.parser')
|
||||
local highlight = require('diffs.highlight')
|
||||
local log = require('diffs.log')
|
||||
local parser = require('diffs.parser')
|
||||
|
||||
local ns = vim.api.nvim_create_namespace('fugitive_ts')
|
||||
local ns = vim.api.nvim_create_namespace('diffs')
|
||||
|
||||
---@param hex integer
|
||||
---@param bg_hex integer
|
||||
|
|
@ -63,7 +63,7 @@ local function resolve_hl(name)
|
|||
return hl
|
||||
end
|
||||
|
||||
---@type fugitive-ts.Config
|
||||
---@type diffs.Config
|
||||
local default_config = {
|
||||
enabled = true,
|
||||
debug = false,
|
||||
|
|
@ -83,7 +83,7 @@ local default_config = {
|
|||
},
|
||||
}
|
||||
|
||||
---@type fugitive-ts.Config
|
||||
---@type diffs.Config
|
||||
local config = vim.deepcopy(default_config)
|
||||
|
||||
---@type table<integer, boolean>
|
||||
|
|
@ -220,25 +220,25 @@ local function compute_highlight_groups()
|
|||
local blended_add = blend_color(add_bg, bg, 0.4)
|
||||
local blended_del = blend_color(del_bg, bg, 0.4)
|
||||
|
||||
vim.api.nvim_set_hl(0, 'FugitiveTsAdd', { bg = blended_add })
|
||||
vim.api.nvim_set_hl(0, 'FugitiveTsDelete', { bg = blended_del })
|
||||
vim.api.nvim_set_hl(0, 'FugitiveTsAddNr', { fg = add_fg, bg = blended_add })
|
||||
vim.api.nvim_set_hl(0, 'FugitiveTsDeleteNr', { fg = del_fg, bg = blended_del })
|
||||
vim.api.nvim_set_hl(0, 'DiffsAdd', { bg = blended_add })
|
||||
vim.api.nvim_set_hl(0, 'DiffsDelete', { bg = blended_del })
|
||||
vim.api.nvim_set_hl(0, 'DiffsAddNr', { fg = add_fg, bg = blended_add })
|
||||
vim.api.nvim_set_hl(0, 'DiffsDeleteNr', { fg = del_fg, bg = blended_del })
|
||||
|
||||
local diff_change = resolve_hl('DiffChange')
|
||||
local diff_text = resolve_hl('DiffText')
|
||||
|
||||
vim.api.nvim_set_hl(0, 'FugitiveTsDiffAdd', { bg = diff_add.bg })
|
||||
vim.api.nvim_set_hl(0, 'FugitiveTsDiffDelete', { bg = diff_delete.bg })
|
||||
vim.api.nvim_set_hl(0, 'FugitiveTsDiffChange', { bg = diff_change.bg })
|
||||
vim.api.nvim_set_hl(0, 'FugitiveTsDiffText', { bg = diff_text.bg })
|
||||
vim.api.nvim_set_hl(0, 'DiffsDiffAdd', { bg = diff_add.bg })
|
||||
vim.api.nvim_set_hl(0, 'DiffsDiffDelete', { bg = diff_delete.bg })
|
||||
vim.api.nvim_set_hl(0, 'DiffsDiffChange', { bg = diff_change.bg })
|
||||
vim.api.nvim_set_hl(0, 'DiffsDiffText', { bg = diff_text.bg })
|
||||
end
|
||||
|
||||
local DIFF_WINHIGHLIGHT = table.concat({
|
||||
'DiffAdd:FugitiveTsDiffAdd',
|
||||
'DiffDelete:FugitiveTsDiffDelete',
|
||||
'DiffChange:FugitiveTsDiffChange',
|
||||
'DiffText:FugitiveTsDiffText',
|
||||
'DiffAdd:DiffsDiffAdd',
|
||||
'DiffDelete:DiffsDiffDelete',
|
||||
'DiffChange:DiffsDiffChange',
|
||||
'DiffText:DiffsDiffText',
|
||||
}, ',')
|
||||
|
||||
function M.attach_diff()
|
||||
|
|
@ -249,20 +249,15 @@ function M.attach_diff()
|
|||
local tabpage = vim.api.nvim_get_current_tabpage()
|
||||
local wins = vim.api.nvim_tabpage_list_wins(tabpage)
|
||||
|
||||
local has_fugitive = false
|
||||
local diff_wins = {}
|
||||
|
||||
for _, win in ipairs(wins) do
|
||||
if vim.api.nvim_win_is_valid(win) and vim.wo[win].diff then
|
||||
table.insert(diff_wins, win)
|
||||
local bufnr = vim.api.nvim_win_get_buf(win)
|
||||
if M.is_fugitive_buffer(bufnr) then
|
||||
has_fugitive = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not has_fugitive then
|
||||
if #diff_wins == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
|
|
@ -282,7 +277,7 @@ function M.detach_diff()
|
|||
end
|
||||
end
|
||||
|
||||
---@param opts? fugitive-ts.Config
|
||||
---@param opts? diffs.Config
|
||||
function M.setup(opts)
|
||||
opts = opts or {}
|
||||
|
||||
|
|
@ -318,13 +313,13 @@ function M.setup(opts)
|
|||
end
|
||||
|
||||
if opts.debounce_ms and opts.debounce_ms < 0 then
|
||||
error('fugitive-ts: debounce_ms must be >= 0')
|
||||
error('diffs: debounce_ms must be >= 0')
|
||||
end
|
||||
if opts.treesitter and opts.treesitter.max_lines and opts.treesitter.max_lines < 1 then
|
||||
error('fugitive-ts: treesitter.max_lines must be >= 1')
|
||||
error('diffs: treesitter.max_lines must be >= 1')
|
||||
end
|
||||
if opts.vim and opts.vim.max_lines and opts.vim.max_lines < 1 then
|
||||
error('fugitive-ts: vim.max_lines must be >= 1')
|
||||
error('diffs: vim.max_lines must be >= 1')
|
||||
end
|
||||
|
||||
config = vim.tbl_deep_extend('force', default_config, opts)
|
||||
|
|
@ -13,7 +13,7 @@ function M.dbg(msg, ...)
|
|||
if not enabled then
|
||||
return
|
||||
end
|
||||
vim.notify('[fugitive-ts] ' .. string.format(msg, ...), vim.log.levels.DEBUG)
|
||||
vim.notify('[diffs] ' .. string.format(msg, ...), vim.log.levels.DEBUG)
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
---@class fugitive-ts.Hunk
|
||||
---@class diffs.Hunk
|
||||
---@field filename string
|
||||
---@field ft string?
|
||||
---@field lang string?
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
local M = {}
|
||||
|
||||
local dbg = require('fugitive-ts.log').dbg
|
||||
local dbg = require('diffs.log').dbg
|
||||
|
||||
---@param filename string
|
||||
---@return string?
|
||||
|
|
@ -38,10 +38,10 @@ local function get_lang_from_ft(ft)
|
|||
end
|
||||
|
||||
---@param bufnr integer
|
||||
---@return fugitive-ts.Hunk[]
|
||||
---@return diffs.Hunk[]
|
||||
function M.parse_buffer(bufnr)
|
||||
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
||||
---@type fugitive-ts.Hunk[]
|
||||
---@type diffs.Hunk[]
|
||||
local hunks = {}
|
||||
|
||||
---@type string?
|
||||
|
|
@ -1,16 +1,16 @@
|
|||
if vim.g.loaded_fugitive_ts then
|
||||
if vim.g.loaded_diffs then
|
||||
return
|
||||
end
|
||||
vim.g.loaded_fugitive_ts = 1
|
||||
vim.g.loaded_diffs = 1
|
||||
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = { 'fugitive', 'git' },
|
||||
callback = function(args)
|
||||
local ft = require('fugitive-ts')
|
||||
if args.match == 'git' and not ft.is_fugitive_buffer(args.buf) then
|
||||
local diffs = require('diffs')
|
||||
if args.match == 'git' and not diffs.is_fugitive_buffer(args.buf) then
|
||||
return
|
||||
end
|
||||
ft.attach(args.buf)
|
||||
diffs.attach(args.buf)
|
||||
end,
|
||||
})
|
||||
|
||||
|
|
@ -18,9 +18,9 @@ vim.api.nvim_create_autocmd('OptionSet', {
|
|||
pattern = 'diff',
|
||||
callback = function()
|
||||
if vim.wo.diff then
|
||||
require('fugitive-ts').attach_diff()
|
||||
require('diffs').attach_diff()
|
||||
else
|
||||
require('fugitive-ts').detach_diff()
|
||||
require('diffs').detach_diff()
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
require('spec.helpers')
|
||||
local highlight = require('fugitive-ts.highlight')
|
||||
local highlight = require('diffs.highlight')
|
||||
|
||||
describe('highlight', function()
|
||||
describe('highlight_hunk', function()
|
||||
|
|
@ -9,8 +9,8 @@ describe('highlight', function()
|
|||
ns = vim.api.nvim_create_namespace('fugitive_ts_test')
|
||||
local diff_add = vim.api.nvim_get_hl(0, { name = 'DiffAdd' })
|
||||
local diff_delete = vim.api.nvim_get_hl(0, { name = 'DiffDelete' })
|
||||
vim.api.nvim_set_hl(0, 'FugitiveTsAdd', { bg = diff_add.bg })
|
||||
vim.api.nvim_set_hl(0, 'FugitiveTsDelete', { bg = diff_delete.bg })
|
||||
vim.api.nvim_set_hl(0, 'DiffsAdd', { bg = diff_add.bg })
|
||||
vim.api.nvim_set_hl(0, 'DiffsDelete', { bg = diff_delete.bg })
|
||||
end)
|
||||
|
||||
local function create_buffer(lines)
|
||||
|
|
@ -325,7 +325,7 @@ describe('highlight', function()
|
|||
local extmarks = get_extmarks(bufnr)
|
||||
local has_diff_add = false
|
||||
for _, mark in ipairs(extmarks) do
|
||||
if mark[4] and mark[4].line_hl_group == 'FugitiveTsAdd' then
|
||||
if mark[4] and mark[4].line_hl_group == 'DiffsAdd' then
|
||||
has_diff_add = true
|
||||
break
|
||||
end
|
||||
|
|
@ -358,7 +358,7 @@ describe('highlight', function()
|
|||
local extmarks = get_extmarks(bufnr)
|
||||
local has_diff_delete = false
|
||||
for _, mark in ipairs(extmarks) do
|
||||
if mark[4] and mark[4].line_hl_group == 'FugitiveTsDelete' then
|
||||
if mark[4] and mark[4].line_hl_group == 'DiffsDelete' then
|
||||
has_diff_delete = true
|
||||
break
|
||||
end
|
||||
|
|
@ -523,7 +523,7 @@ describe('highlight', function()
|
|||
local extmarks = get_extmarks(bufnr)
|
||||
local has_diff_add = false
|
||||
for _, mark in ipairs(extmarks) do
|
||||
if mark[4] and mark[4].line_hl_group == 'FugitiveTsAdd' then
|
||||
if mark[4] and mark[4].line_hl_group == 'DiffsAdd' then
|
||||
has_diff_add = true
|
||||
break
|
||||
end
|
||||
|
|
@ -554,7 +554,7 @@ describe('highlight', function()
|
|||
|
||||
local hunk = {
|
||||
filename = 'test.lua',
|
||||
ft = 'lua',
|
||||
ft = 'abap',
|
||||
lang = nil,
|
||||
start_line = 1,
|
||||
lines = { ' local x = 1', '+local y = 2' },
|
||||
|
|
@ -587,7 +587,7 @@ describe('highlight', function()
|
|||
|
||||
local hunk = {
|
||||
filename = 'test.lua',
|
||||
ft = 'lua',
|
||||
ft = 'abap',
|
||||
lang = nil,
|
||||
start_line = 1,
|
||||
lines = { ' local x = 1', '+local y = 2' },
|
||||
|
|
@ -618,7 +618,7 @@ describe('highlight', function()
|
|||
local bufnr = create_buffer(lines)
|
||||
local hunk = {
|
||||
filename = 'test.lua',
|
||||
ft = 'lua',
|
||||
ft = 'abap',
|
||||
lang = nil,
|
||||
start_line = 1,
|
||||
lines = hunk_lines,
|
||||
|
|
@ -645,7 +645,7 @@ describe('highlight', function()
|
|||
|
||||
local hunk = {
|
||||
filename = 'test.lua',
|
||||
ft = 'lua',
|
||||
ft = 'abap',
|
||||
lang = nil,
|
||||
start_line = 1,
|
||||
lines = { ' local x = 1', '+local y = 2' },
|
||||
|
|
@ -661,7 +661,7 @@ describe('highlight', function()
|
|||
local extmarks = get_extmarks(bufnr)
|
||||
local has_diff_add = false
|
||||
for _, mark in ipairs(extmarks) do
|
||||
if mark[4] and mark[4].line_hl_group == 'FugitiveTsAdd' then
|
||||
if mark[4] and mark[4].line_hl_group == 'DiffsAdd' then
|
||||
has_diff_add = true
|
||||
break
|
||||
end
|
||||
|
|
@ -692,7 +692,7 @@ describe('highlight', function()
|
|||
|
||||
local hunk = {
|
||||
filename = 'test.lua',
|
||||
ft = 'lua',
|
||||
ft = 'abap',
|
||||
lang = nil,
|
||||
start_line = 1,
|
||||
lines = { ' local x = 1', '+local y = 2' },
|
||||
|
|
|
|||
|
|
@ -1,23 +1,23 @@
|
|||
require('spec.helpers')
|
||||
local fugitive_ts = require('fugitive-ts')
|
||||
local diffs = require('diffs')
|
||||
|
||||
describe('fugitive-ts', function()
|
||||
describe('diffs', function()
|
||||
describe('setup', function()
|
||||
it('accepts empty config', function()
|
||||
assert.has_no.errors(function()
|
||||
fugitive_ts.setup({})
|
||||
diffs.setup({})
|
||||
end)
|
||||
end)
|
||||
|
||||
it('accepts nil config', function()
|
||||
assert.has_no.errors(function()
|
||||
fugitive_ts.setup()
|
||||
diffs.setup()
|
||||
end)
|
||||
end)
|
||||
|
||||
it('accepts full config', function()
|
||||
assert.has_no.errors(function()
|
||||
fugitive_ts.setup({
|
||||
diffs.setup({
|
||||
enabled = false,
|
||||
debug = true,
|
||||
debounce_ms = 100,
|
||||
|
|
@ -40,7 +40,7 @@ describe('fugitive-ts', function()
|
|||
|
||||
it('accepts partial config', function()
|
||||
assert.has_no.errors(function()
|
||||
fugitive_ts.setup({
|
||||
diffs.setup({
|
||||
debounce_ms = 25,
|
||||
})
|
||||
end)
|
||||
|
|
@ -61,13 +61,13 @@ describe('fugitive-ts', function()
|
|||
end
|
||||
|
||||
before_each(function()
|
||||
fugitive_ts.setup({ enabled = true })
|
||||
diffs.setup({ enabled = true })
|
||||
end)
|
||||
|
||||
it('does not error on empty buffer', function()
|
||||
local bufnr = create_buffer({})
|
||||
assert.has_no.errors(function()
|
||||
fugitive_ts.attach(bufnr)
|
||||
diffs.attach(bufnr)
|
||||
end)
|
||||
delete_buffer(bufnr)
|
||||
end)
|
||||
|
|
@ -80,7 +80,7 @@ describe('fugitive-ts', function()
|
|||
'+local y = 2',
|
||||
})
|
||||
assert.has_no.errors(function()
|
||||
fugitive_ts.attach(bufnr)
|
||||
diffs.attach(bufnr)
|
||||
end)
|
||||
delete_buffer(bufnr)
|
||||
end)
|
||||
|
|
@ -88,9 +88,9 @@ describe('fugitive-ts', function()
|
|||
it('is idempotent', function()
|
||||
local bufnr = create_buffer({})
|
||||
assert.has_no.errors(function()
|
||||
fugitive_ts.attach(bufnr)
|
||||
fugitive_ts.attach(bufnr)
|
||||
fugitive_ts.attach(bufnr)
|
||||
diffs.attach(bufnr)
|
||||
diffs.attach(bufnr)
|
||||
diffs.attach(bufnr)
|
||||
end)
|
||||
delete_buffer(bufnr)
|
||||
end)
|
||||
|
|
@ -110,22 +110,22 @@ describe('fugitive-ts', function()
|
|||
end
|
||||
|
||||
before_each(function()
|
||||
fugitive_ts.setup({ enabled = true })
|
||||
diffs.setup({ enabled = true })
|
||||
end)
|
||||
|
||||
it('does not error on unattached buffer', function()
|
||||
local bufnr = create_buffer({})
|
||||
assert.has_no.errors(function()
|
||||
fugitive_ts.refresh(bufnr)
|
||||
diffs.refresh(bufnr)
|
||||
end)
|
||||
delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('does not error on attached buffer', function()
|
||||
local bufnr = create_buffer({})
|
||||
fugitive_ts.attach(bufnr)
|
||||
diffs.attach(bufnr)
|
||||
assert.has_no.errors(function()
|
||||
fugitive_ts.refresh(bufnr)
|
||||
diffs.refresh(bufnr)
|
||||
end)
|
||||
delete_buffer(bufnr)
|
||||
end)
|
||||
|
|
@ -133,7 +133,7 @@ describe('fugitive-ts', function()
|
|||
|
||||
describe('config options', function()
|
||||
it('enabled=false prevents highlighting', function()
|
||||
fugitive_ts.setup({ enabled = false })
|
||||
diffs.setup({ enabled = false })
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {
|
||||
'M test.lua',
|
||||
|
|
@ -141,9 +141,9 @@ describe('fugitive-ts', function()
|
|||
' local x = 1',
|
||||
'+local y = 2',
|
||||
})
|
||||
fugitive_ts.attach(bufnr)
|
||||
diffs.attach(bufnr)
|
||||
|
||||
local ns = vim.api.nvim_create_namespace('fugitive_ts')
|
||||
local ns = vim.api.nvim_create_namespace('diffs')
|
||||
local extmarks = vim.api.nvim_buf_get_extmarks(bufnr, ns, 0, -1, {})
|
||||
assert.are.equal(0, #extmarks)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
require('spec.helpers')
|
||||
local parser = require('fugitive-ts.parser')
|
||||
local parser = require('diffs.parser')
|
||||
|
||||
describe('parser', function()
|
||||
describe('parse_buffer', function()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue