neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

decoration_defs.h (4182B)


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