robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqMerge pull request #40113 from jreidx/feat/virt-lines-wrapbedfa7d58f

master
4.3 KiB176 linesraw
1#pragma once
2
3#include <stdint.h>
4
5#include "klib/kvec.h"
6#include "nvim/api/private/defs.h"
7#include "nvim/types_defs.h"
8
9#define DECOR_ID_INVALID UINT32_MAX
10
11typedef struct {
12  char *text;
13  int hl_id;  ///< -1 if not specified
14} VirtTextChunk;
15
16typedef kvec_t(VirtTextChunk) VirtText;
17#define VIRTTEXT_EMPTY ((VirtText)KV_INITIAL_VALUE)
18
19/// Keep in sync with virt_text_pos_str[] in decoration.h
20typedef enum {
21  kVPosEndOfLine,
22  kVPosEndOfLineRightAlign,
23  kVPosInline,
24  kVPosOverlay,
25  kVPosRightAlign,
26  kVPosWinCol,
27} VirtTextPos;
28
29/// Flags for virtual lines
30enum {
31  kVLLeftcol = 1,  ///< Start at left window edge, ignoring number column, etc.
32};
33
34typedef enum {
35  kVLOverflowTrunc,    ///< Truncate with 'nowrap'
36  kVLOverflowScroll,   ///< Scroll horizontally with 'nowrap'
37  kVLOverflowWrap,     ///< Wrap onto extra rows
38  kVLOverflowAuto,     ///< Scroll with 'nowrap'; wrap with 'wrap'
39} VirtLineOverflow;
40
41typedef kvec_t(struct virt_line { VirtText line; int flags; VirtLineOverflow overflow; }) VirtLines;
42
43typedef uint16_t DecorPriority;
44typedef uint32_t DecorPriorityInternal;
45#define DECOR_PRIORITY_BASE 0x1000
46
47/// Keep in sync with hl_mode_str[] in decoration.h
48typedef enum {
49  kHlModeUnknown,
50  kHlModeReplace,
51  kHlModeCombine,
52  kHlModeBlend,
53} HlMode;
54
55enum {
56  kSHIsSign = 1,
57  kSHHlEol = 2,
58  kSHUIWatched = 4,
59  kSHUIWatchedOverlay = 8,
60  kSHSpellOn = 16,
61  kSHSpellOff = 32,
62  kSHConceal = 64,
63  kSHConcealLines = 128,
64  kSHConcealOff = 256,
65};
66
67typedef struct {
68  uint16_t flags;
69  DecorPriority priority;
70  int hl_id;
71  schar_T conceal_char;
72} DecorHighlightInline;
73
74#define DECOR_HIGHLIGHT_INLINE_INIT { 0, DECOR_PRIORITY_BASE, 0, 0 }
75
76typedef struct {
77  uint16_t flags;
78  DecorPriority priority;
79  int hl_id;  // if sign: highlight of sign text
80  schar_T text[SIGN_WIDTH];  // conceal text only uses text[0]
81  // NOTE: if more functionality is added to a Highlight these should be overloaded
82  // or restructured
83  char *sign_name;
84  int sign_add_id;
85  int number_hl_id;
86  int line_hl_id;
87  int cursorline_hl_id;
88  uint32_t next;
89  const char *url;
90} DecorSignHighlight;
91
92#define DECOR_SIGN_HIGHLIGHT_INIT { 0, DECOR_PRIORITY_BASE, 0, { 0, 0 }, NULL, 0, 0, 0, 0, \
93                                    DECOR_ID_INVALID, NULL }
94
95enum {
96  kVTIsLines = 1,
97  kVTHide = 2,
98  kVTLinesAbove = 4,
99  kVTRepeatLinebreak = 8,
100};
101
102typedef struct DecorVirtText DecorVirtText;
103struct DecorVirtText {
104  uint8_t flags;
105  uint8_t hl_mode;
106  DecorPriority priority;
107  int width;  // width of virt_text
108  int col;
109  VirtTextPos pos;
110  // TODO(bfredl): reduce this to one datatype, later
111  union {
112    VirtText virt_text;
113    VirtLines virt_lines;
114  } data;
115  DecorVirtText *next;
116};
117#define DECOR_VIRT_TEXT_INIT { 0, kHlModeUnknown, DECOR_PRIORITY_BASE, 0, 0, kVPosEndOfLine, \
118                               { .virt_text = KV_INITIAL_VALUE }, NULL, }
119#define DECOR_VIRT_LINES_INIT { kVTIsLines, kHlModeUnknown, DECOR_PRIORITY_BASE, 0, 0, \
120                                kVPosEndOfLine, { .virt_lines = KV_INITIAL_VALUE }, NULL, }
121
122typedef struct {
123  uint32_t sh_idx;
124  DecorVirtText *vt;
125} DecorExt;
126
127// Stored inline in marktree, with MT_FLAG_DECOR_EXT in MTKey.flags
128typedef union {
129  DecorHighlightInline hl;
130  DecorExt ext;
131} DecorInlineData;
132
133// Not stored in the marktree, but used when passing around args
134//
135// Convention: an empty "no decoration" value should always be encoded
136// with ext=false and an unset DecorHighlightInline (no flags, no hl_id)
137typedef struct {
138  bool ext;
139  DecorInlineData data;
140} DecorInline;
141
142// initializes in a valid state for the DecorHighlightInline branch
143#define DECOR_INLINE_INIT { .ext = false, .data.hl = DECOR_HIGHLIGHT_INLINE_INIT }
144
145typedef struct {
146  NS ns_id;
147
148  enum {
149    kDecorProviderActive = 1,
150    kDecorProviderWinDisabled = 2,
151    kDecorProviderRedrawDisabled = 3,
152    kDecorProviderDisabled = 4,
153  } state;
154
155  int win_skip_row;
156  int win_skip_col;
157
158  LuaRef redraw_start;
159  LuaRef redraw_buf;
160  LuaRef redraw_win;
161  LuaRef redraw_line;
162  LuaRef redraw_range;
163  LuaRef redraw_end;
164  LuaRef hl_def;
165  LuaRef spell_nav;
166  LuaRef conceal_line;
167  int hl_valid;
168  bool hl_cached;
169
170  uint8_t error_count;
171} DecorProvider;
172
173#define DECORATION_PROVIDER_INIT(ns_id) (DecorProvider) \
174  { ns_id, kDecorProviderDisabled, 0, 0, LUA_NOREF, LUA_NOREF, \
175    LUA_NOREF, LUA_NOREF, LUA_NOREF, LUA_NOREF, \
176    LUA_NOREF, LUA_NOREF, -1, false, false, 0 }