robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
bedfa7d58f
master
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 { 12char * text ; 13int 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 { 21kVPosEndOfLine , 22kVPosEndOfLineRightAlign , 23kVPosInline , 24kVPosOverlay , 25kVPosRightAlign , 26kVPosWinCol , 27}VirtTextPos ; 28 29/// Flags for virtual lines 30enum { 31kVLLeftcol = 1 ,///< Start at left window edge, ignoring number column, etc. 32}; 33 34typedef enum { 35kVLOverflowTrunc ,///< Truncate with 'nowrap' 36kVLOverflowScroll ,///< Scroll horizontally with 'nowrap' 37kVLOverflowWrap ,///< Wrap onto extra rows 38kVLOverflowAuto ,///< 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 { 49kHlModeUnknown , 50kHlModeReplace , 51kHlModeCombine , 52kHlModeBlend , 53}HlMode ; 54 55enum { 56kSHIsSign = 1 , 57kSHHlEol = 2 , 58kSHUIWatched = 4 , 59kSHUIWatchedOverlay = 8 , 60kSHSpellOn = 16 , 61kSHSpellOff = 32 , 62kSHConceal = 64 , 63kSHConcealLines = 128 , 64kSHConcealOff = 256 , 65}; 66 67typedef struct { 68uint16_t flags ; 69DecorPriority priority ; 70int hl_id ; 71schar_T conceal_char ; 72}DecorHighlightInline ; 73 74#define DECOR_HIGHLIGHT_INLINE_INIT { 0, DECOR_PRIORITY_BASE, 0, 0 } 75 76typedef struct { 77uint16_t flags ; 78DecorPriority priority ; 79int hl_id ;// if sign: highlight of sign text 80schar_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 83char * sign_name ; 84int sign_add_id ; 85int number_hl_id ; 86int line_hl_id ; 87int cursorline_hl_id ; 88uint32_t next ; 89const 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 { 96kVTIsLines = 1 , 97kVTHide = 2 , 98kVTLinesAbove = 4 , 99kVTRepeatLinebreak = 8 , 100}; 101 102typedef struct DecorVirtText DecorVirtText ; 103struct DecorVirtText { 104uint8_t flags ; 105uint8_t hl_mode ; 106DecorPriority priority ; 107int width ;// width of virt_text 108int col ; 109VirtTextPos pos ; 110// TODO(bfredl): reduce this to one datatype, later 111union { 112VirtText virt_text ; 113VirtLines virt_lines ; 114 }data ; 115DecorVirtText * 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 { 123uint32_t sh_idx ; 124DecorVirtText * vt ; 125}DecorExt ; 126 127// Stored inline in marktree, with MT_FLAG_DECOR_EXT in MTKey.flags 128typedef union { 129DecorHighlightInline hl ; 130DecorExt 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 { 138bool ext ; 139DecorInlineData 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 { 146NS ns_id ; 147 148enum { 149kDecorProviderActive = 1 , 150kDecorProviderWinDisabled = 2 , 151kDecorProviderRedrawDisabled = 3 , 152kDecorProviderDisabled = 4 , 153 }state ; 154 155int win_skip_row ; 156int win_skip_col ; 157 158LuaRef redraw_start ; 159LuaRef redraw_buf ; 160LuaRef redraw_win ; 161LuaRef redraw_line ; 162LuaRef redraw_range ; 163LuaRef redraw_end ; 164LuaRef hl_def ; 165LuaRef spell_nav ; 166LuaRef conceal_line ; 167int hl_valid ; 168bool hl_cached ; 169 170uint8_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 }