1import { with_opacity } from "../theme/color"
2import { Layer, StyleSets } from "../theme/create_theme"
3import {
4 background,
5 border,
6 border_color,
7 foreground,
8 text,
9} from "./components"
10import hover_popover from "./hover_popover"
11
12import { build_syntax } from "../theme/syntax"
13import { interactive, toggleable } from "../element"
14import { useTheme } from "../theme"
15
16export default function editor(): any {
17 const theme = useTheme()
18
19 const { is_light } = theme
20
21 const layer = theme.highest
22
23 const autocomplete_item = {
24 corner_radius: 6,
25 padding: {
26 bottom: 2,
27 left: 6,
28 right: 6,
29 top: 2,
30 },
31 }
32
33 function diagnostic(layer: Layer, style_set: StyleSets) {
34 return {
35 text_scale_factor: 0.857,
36 header: {
37 border: border(layer, {
38 top: true,
39 }),
40 },
41 message: {
42 text: text(layer, "sans", style_set, "default", { size: "sm" }),
43 highlight_text: text(layer, "sans", style_set, "default", {
44 size: "sm",
45 weight: "bold",
46 }),
47 },
48 }
49 }
50
51 const syntax = build_syntax()
52
53 return {
54 text_color: syntax.primary.color,
55 background: background(layer),
56 active_line_background: with_opacity(background(layer, "on"), 0.75),
57 highlighted_line_background: background(layer, "on"),
58 // Inline autocomplete suggestions, Co-pilot suggestions, etc.
59 hint: syntax.hint,
60 suggestion: syntax.predictive,
61 code_actions: {
62 indicator: toggleable({
63 base: interactive({
64 base: {
65 color: foreground(layer, "variant"),
66 },
67 state: {
68 hovered: {
69 color: foreground(layer, "variant", "hovered"),
70 },
71 clicked: {
72 color: foreground(layer, "variant", "pressed"),
73 },
74 },
75 }),
76 state: {
77 active: {
78 default: {
79 color: foreground(layer, "accent"),
80 },
81 hovered: {
82 color: foreground(layer, "accent", "hovered"),
83 },
84 clicked: {
85 color: foreground(layer, "accent", "pressed"),
86 },
87 },
88 },
89 }),
90
91 vertical_scale: 0.55,
92 },
93 folds: {
94 icon_margin_scale: 2.5,
95 folded_icon: "icons/chevron_right_8.svg",
96 foldable_icon: "icons/chevron_down_8.svg",
97 indicator: toggleable({
98 base: interactive({
99 base: {
100 color: foreground(layer, "variant"),
101 },
102 state: {
103 hovered: {
104 color: foreground(layer, "on"),
105 },
106 clicked: {
107 color: foreground(layer, "base"),
108 },
109 },
110 }),
111 state: {
112 active: {
113 default: {
114 color: foreground(layer, "default"),
115 },
116 hovered: {
117 color: foreground(layer, "on"),
118 },
119 },
120 },
121 }),
122 ellipses: {
123 text_color: theme.ramps.neutral(0.71).hex(),
124 corner_radius_factor: 0.15,
125 background: {
126 // Copied from hover_popover highlight
127 default: {
128 color: theme.ramps.neutral(0.5).alpha(0.0).hex(),
129 },
130
131 hovered: {
132 color: theme.ramps.neutral(0.5).alpha(0.5).hex(),
133 },
134
135 clicked: {
136 color: theme.ramps.neutral(0.5).alpha(0.7).hex(),
137 },
138 },
139 },
140 fold_background: foreground(layer, "variant"),
141 },
142 diff: {
143 deleted: is_light
144 ? theme.ramps.red(0.5).hex()
145 : theme.ramps.red(0.4).hex(),
146 modified: is_light
147 ? theme.ramps.yellow(0.5).hex()
148 : theme.ramps.yellow(0.5).hex(),
149 inserted: is_light
150 ? theme.ramps.green(0.4).hex()
151 : theme.ramps.green(0.5).hex(),
152 removed_width_em: 0.275,
153 width_em: 0.15,
154 corner_radius: 0.05,
155 },
156 /** Highlights matching occurrences of what is under the cursor
157 * as well as matched brackets
158 */
159 document_highlight_read_background: with_opacity(
160 foreground(layer, "accent"),
161 0.1
162 ),
163 document_highlight_write_background: theme.ramps
164 .neutral(0.5)
165 .alpha(0.4)
166 .hex(), // TODO: This was blend * 2
167 error_color: background(layer, "negative"),
168 gutter_background: background(layer),
169 gutter_padding_factor: 3.5,
170 line_number: with_opacity(foreground(layer), 0.35),
171 line_number_active: foreground(layer),
172 rename_fade: 0.6,
173 wrap_guide: with_opacity(foreground(layer), 0.05),
174 active_wrap_guide: with_opacity(foreground(layer), 0.1),
175 unnecessary_code_fade: 0.5,
176 selection: theme.players[0],
177 whitespace: theme.ramps.neutral(0.5).hex(),
178 guest_selections: [
179 theme.players[1],
180 theme.players[2],
181 theme.players[3],
182 theme.players[4],
183 theme.players[5],
184 theme.players[6],
185 theme.players[7],
186 ],
187 absent_selection: theme.players[7],
188 autocomplete: {
189 background: background(theme.middle),
190 corner_radius: 8,
191 padding: 4,
192 margin: {
193 left: -14,
194 },
195 border: border(theme.middle),
196 shadow: theme.popover_shadow,
197 match_highlight: foreground(theme.middle, "accent"),
198 item: autocomplete_item,
199 hovered_item: {
200 ...autocomplete_item,
201 match_highlight: foreground(theme.middle, "accent", "hovered"),
202 background: background(theme.middle, "hovered"),
203 },
204 selected_item: {
205 ...autocomplete_item,
206 match_highlight: foreground(theme.middle, "accent", "active"),
207 background: background(theme.middle, "active"),
208 },
209 server_name_container: { padding: { left: 40 } },
210 server_name_color: text(theme.middle, "sans", "disabled", {}).color,
211 server_name_size_percent: 0.75,
212 },
213 diagnostic_header: {
214 background: background(theme.middle),
215 icon_width_factor: 1.5,
216 text_scale_factor: 0.857,
217 border: border(theme.middle, {
218 bottom: true,
219 top: true,
220 }),
221 code: {
222 ...text(theme.middle, "mono", { size: "sm" }),
223 margin: {
224 left: 10,
225 },
226 },
227 source: {
228 text: text(theme.middle, "sans", {
229 size: "sm",
230 weight: "bold",
231 }),
232 },
233 message: {
234 highlight_text: text(theme.middle, "sans", {
235 size: "sm",
236 weight: "bold",
237 }),
238 text: text(theme.middle, "sans", { size: "sm" }),
239 },
240 },
241 diagnostic_path_header: {
242 background: background(theme.middle),
243 text_scale_factor: 0.857,
244 filename: text(theme.middle, "mono", { size: "sm" }),
245 path: {
246 ...text(theme.middle, "mono", { size: "sm" }),
247 margin: {
248 left: 12,
249 },
250 },
251 },
252 error_diagnostic: diagnostic(theme.middle, "negative"),
253 warning_diagnostic: diagnostic(theme.middle, "warning"),
254 information_diagnostic: diagnostic(theme.middle, "accent"),
255 hint_diagnostic: diagnostic(theme.middle, "warning"),
256 invalid_error_diagnostic: diagnostic(theme.middle, "base"),
257 invalid_hint_diagnostic: diagnostic(theme.middle, "base"),
258 invalid_information_diagnostic: diagnostic(theme.middle, "base"),
259 invalid_warning_diagnostic: diagnostic(theme.middle, "base"),
260 hover_popover: hover_popover(),
261 link_definition: {
262 color: syntax.link_uri.color,
263 underline: syntax.link_uri.underline,
264 },
265 jump_icon: interactive({
266 base: {
267 color: foreground(layer, "on"),
268 icon_width: 20,
269 button_width: 20,
270 corner_radius: 6,
271 padding: {
272 top: 6,
273 bottom: 6,
274 left: 6,
275 right: 6,
276 },
277 },
278 state: {
279 hovered: {
280 background: background(layer, "on", "hovered"),
281 },
282 },
283 }),
284
285 scrollbar: {
286 width: 12,
287 min_height_factor: 1.0,
288 track: {
289 border: border(layer, "variant", { left: true }),
290 },
291 thumb: {
292 background: with_opacity(background(layer, "inverted"), 0.3),
293 border: {
294 width: 1,
295 color: border_color(layer, "variant"),
296 top: false,
297 right: true,
298 left: true,
299 bottom: false,
300 },
301 },
302 git: {
303 deleted: is_light
304 ? with_opacity(theme.ramps.red(0.5).hex(), 0.8)
305 : with_opacity(theme.ramps.red(0.4).hex(), 0.8),
306 modified: is_light
307 ? with_opacity(theme.ramps.yellow(0.5).hex(), 0.8)
308 : with_opacity(theme.ramps.yellow(0.4).hex(), 0.8),
309 inserted: is_light
310 ? with_opacity(theme.ramps.green(0.5).hex(), 0.8)
311 : with_opacity(theme.ramps.green(0.4).hex(), 0.8),
312 },
313 selections: foreground(layer, "accent"),
314 },
315 composition_mark: {
316 underline: {
317 thickness: 1.0,
318 color: border_color(layer),
319 },
320 },
321 syntax,
322 }
323}