-
Notifications
You must be signed in to change notification settings - Fork 15
/
types.ts
209 lines (194 loc) Β· 4.37 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import { assert, is } from "https://deno.land/x/unknownutil@v3.16.3/mod.ts";
/**
* Type of `screenpos()` result.
*/
export type ScreenPos = {
row: number;
col: number;
endcol: number;
curscol: number;
};
/**
* Return true if the value is ScreenPos.
*/
export function isScreenPos(x: unknown): x is ScreenPos {
const predObj = {
row: is.Number,
col: is.Number,
endcol: is.Number,
curscol: is.Number,
};
return is.ObjectOf(predObj)(x);
}
/**
* Assert if `x` is ScreenPos by raising an `AssertError` when it's not.
*/
export function assertScreenPos(x: unknown): asserts x is ScreenPos {
assert(x, isScreenPos, { message: "The value must be ScreenPos" });
}
/**
* Type of `getpos()` or `setpos()` result.
*/
export type Position = [
bufnum: number,
lnum: number,
col: number,
off: number,
curswant?: number,
];
/**
* Return true if the value is Position.
*/
export function isPosition(x: unknown): x is Position {
const pred = is.OneOf([
is.TupleOf([is.Number, is.Number, is.Number, is.Number]),
is.TupleOf([is.Number, is.Number, is.Number, is.Number, is.Number]),
]);
return pred(x);
}
/**
* Assert if `x` is Position by raising an `AssertError` when it's not.
*/
export function assertPosition(x: unknown): asserts x is Position {
assert(x, isPosition, { message: "The value must be Position" });
}
const validBuiltinCompletions = [
"arglist",
"augroup",
"buffer",
"behave",
"color",
"command",
"compiler",
"cscope",
"dir",
"environment",
"event",
"expression",
"file",
"file_in_path",
"filetype",
"function",
"help",
"highlight",
"history",
"locale",
"mapclear",
"mapping",
"menu",
"messages",
"option",
"packadd",
"shellcmd",
"sign",
"syntax",
"syntime",
"tag",
"tag_listfiles",
"user",
"var",
] as const;
/**
* Builtin completion
*/
export type BuiltinCompletion = typeof validBuiltinCompletions[number];
/**
* Check if the `value` is valid BuiltinCompletion
*/
export function isValidBuiltinCompletion(
value: string,
): value is BuiltinCompletion {
// deno-lint-ignore no-explicit-any
return validBuiltinCompletions.includes(value as any);
}
/**
* Type of `getbufinfo()` result.
*/
export interface BufInfo {
/** Buffer number. */
bufnr: number;
/** TRUE if the buffer is modified. */
changed: boolean;
/** Number of changes made to the buffer. */
changedtick: number;
/** TRUE if the buffer is hidden. */
hidden: boolean;
/**
* Timestamp in seconds, like `localtime()`, when the buffer was last used.
*/
lastused: number;
/** TRUE if the buffer is listed. */
listed: boolean;
/**
* Line number used for the buffer when opened in the current window.
* Only valid if the buffer has been displayed in the window in the past.
* If you want the line number of the last known cursor position in a given
* window, use `line()`:
*
* :echo line('.', {winid})
*/
lnum: number;
/** Number of lines in the buffer. (only valid when loaded) */
linecount: number;
/** TRUE if the buffer is loaded. */
loaded: boolean;
/** Full path to the file in the buffer. */
name: string;
/** List of signs placed in the buffer. */
signs?: PlacedSign[];
/** A reference to the dictionary with buffer-local variables. */
variables: number;
/** List of `window-ID`s that display this buffer. */
windows: number[];
/** List of popup `window-ID`s that display this buffer. */
popups: number[];
}
/**
* Type of `getbufinfo()` result.
*/
export interface PlacedSign {
/** Sign identifier. */
id: number;
/** Line number. */
lnum: number;
/** Sign name. */
name: string;
}
/**
* Type of `getchangelist()` result.
*/
export type ChangeList = [locations: ChangeListLocation[], pos: number];
/**
* Type of `getchangelist()` result.
*/
export interface ChangeListLocation {
/** Column number. */
col: number;
/** Column offset for 'virtualedit'. */
coladd: number;
/** Line number. */
lnum: number;
}
/**
* Type of `getmarklist()` result.
*/
export interface MarkInformation {
/** Name of the mark prefixed by "'". */
mark: string;
/**
* The position of the mark.
* Refer to `getpos()` for more information.
*/
pos: MarkPosition;
/** File name. */
file: string;
}
/**
* Type of `getmarklist()` result.
*/
export type MarkPosition = [
bufnum: number,
lnum: number,
col: number,
off: number,
];