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 autocomplete: {
188 background: background(theme.middle),
189 corner_radius: 8,
190 padding: 4,
191 margin: {
192 left: -14,
193 },
194 border: border(theme.middle),
195 shadow: theme.popover_shadow,
196 match_highlight: foreground(theme.middle, "accent"),
197 item: autocomplete_item,
198 hovered_item: {
199 ...autocomplete_item,
200 match_highlight: foreground(theme.middle, "accent", "hovered"),
201 background: background(theme.middle, "hovered"),
202 },
203 selected_item: {
204 ...autocomplete_item,
205 match_highlight: foreground(theme.middle, "accent", "active"),
206 background: background(theme.middle, "active"),
207 },
208 server_name_container: { padding: { left: 40 } },
209 server_name_color: text(theme.middle, "sans", "disabled", {}).color,
210 server_name_size_percent: 0.75,
211 },
212 diagnostic_header: {
213 background: background(theme.middle),
214 icon_width_factor: 1.5,
215 text_scale_factor: 0.857,
216 border: border(theme.middle, {
217 bottom: true,
218 top: true,
219 }),
220 code: {
221 ...text(theme.middle, "mono", { size: "sm" }),
222 margin: {
223 left: 10,
224 },
225 },
226 source: {
227 text: text(theme.middle, "sans", {
228 size: "sm",
229 weight: "bold",
230 }),
231 },
232 message: {
233 highlight_text: text(theme.middle, "sans", {
234 size: "sm",
235 weight: "bold",
236 }),
237 text: text(theme.middle, "sans", { size: "sm" }),
238 },
239 },
240 diagnostic_path_header: {
241 background: background(theme.middle),
242 text_scale_factor: 0.857,
243 filename: text(theme.middle, "mono", { size: "sm" }),
244 path: {
245 ...text(theme.middle, "mono", { size: "sm" }),
246 margin: {
247 left: 12,
248 },
249 },
250 },
251 error_diagnostic: diagnostic(theme.middle, "negative"),
252 warning_diagnostic: diagnostic(theme.middle, "warning"),
253 information_diagnostic: diagnostic(theme.middle, "accent"),
254 hint_diagnostic: diagnostic(theme.middle, "warning"),
255 invalid_error_diagnostic: diagnostic(theme.middle, "base"),
256 invalid_hint_diagnostic: diagnostic(theme.middle, "base"),
257 invalid_information_diagnostic: diagnostic(theme.middle, "base"),
258 invalid_warning_diagnostic: diagnostic(theme.middle, "base"),
259 hover_popover: hover_popover(),
260 link_definition: {
261 color: syntax.link_uri.color,
262 underline: syntax.link_uri.underline,
263 },
264 jump_icon: interactive({
265 base: {
266 color: foreground(layer, "on"),
267 icon_width: 20,
268 button_width: 20,
269 corner_radius: 6,
270 padding: {
271 top: 6,
272 bottom: 6,
273 left: 6,
274 right: 6,
275 },
276 },
277 state: {
278 hovered: {
279 background: background(layer, "on", "hovered"),
280 },
281 },
282 }),
283
284 scrollbar: {
285 width: 12,
286 min_height_factor: 1.0,
287 track: {
288 border: border(layer, "variant", { left: true }),
289 },
290 thumb: {
291 background: with_opacity(background(layer, "inverted"), 0.3),
292 border: {
293 width: 1,
294 color: border_color(layer, "variant"),
295 top: false,
296 right: true,
297 left: true,
298 bottom: false,
299 },
300 },
301 git: {
302 deleted: is_light
303 ? with_opacity(theme.ramps.red(0.5).hex(), 0.8)
304 : with_opacity(theme.ramps.red(0.4).hex(), 0.8),
305 modified: is_light
306 ? with_opacity(theme.ramps.yellow(0.5).hex(), 0.8)
307 : with_opacity(theme.ramps.yellow(0.4).hex(), 0.8),
308 inserted: is_light
309 ? with_opacity(theme.ramps.green(0.5).hex(), 0.8)
310 : with_opacity(theme.ramps.green(0.4).hex(), 0.8),
311 },
312 selections: foreground(layer, "accent")
313 },
314 composition_mark: {
315 underline: {
316 thickness: 1.0,
317 color: border_color(layer),
318 },
319 },
320 syntax,
321 }
322}