Fork of daniellemaywood.uk/gleam — Wasm codegen work
17 kB
614 lines
1<!--
2 SPDX-License-Identifier: Apache-2.0
3 SPDX-FileCopyrightText: 2020 The Gleam contributors
4-->
5
6# Changelog
7
8## Unreleased
9
10### Compiler
11
12- The compiler now issues a friendlier error when attempting to pattern match
13 on both the prefix and suffix of a string:
14
15 ```
16 error: Syntax error
17 ┌─ /src/parse/error.gleam:2:23
18 │
19 2 │ "prefix" <> infix <> "suffix" -> infix
20 │ ^^^^^^^^^^^ This pattern is not allowed
21
22 A string pattern can only match on a literal string prefix.
23
24 Matching on a literal suffix is not possible, because `infix` would have an
25 unknown size.
26 ```
27
28 ([Gavin Morrow](https://github.com/gavinmorrow))
29
30- Improved the error message shown when using an invalid discard name for
31 functions, constants, module names, and `as` patterns.
32 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
33
34- The compiler now generates singleton values for variants with no fields on the
35 JavaScript target, allowing for faster comparison in most cases.
36 ([Surya Rose](https://github.com/GearsDatapacks))
37
38- The use of pipes to turn the Gleam code `a |> b(c)` into `b(c)(a)` has been
39 deprecated.
40 ([Surya Rose](https://github.com/GearsDatapacks))
41
42- The compiler now gives a better error message when an `@external`
43 attribute is incomplete. For example:
44
45 ```gleam
46 @external
47 pub fn wibble()
48 ```
49
50 now points to the attribute itself and explains that it is incomplete.
51 ([Asish Kumar](https://github.com/officialasishkumar))
52
53- The "did you mean one of these:" hint is now phrased in singular when there
54 is only one suggestion, additionally multiple suggestions are listed
55 in a consistent alphabetical order.
56 ([Zbyněk Juřica](https://github.com/zbyju))
57
58### Build tool
59
60- The build tool now generates Hexdocs URLs using the new format of
61 `package.hexdocs.pm` rather than `hexdocs.pm/package`.
62 ([Surya Rose](https://github.com/GearsDatapacks))
63
64- More readable error message when trying to revert an old release.
65 ([Moritz Böhme](https://github.com/MoritzBoehme))
66
67- The build tool now includes destination path in the error when it fails to
68 link or copy file or directory.
69 ([Andrey Kozhev](https://github.com/ankddev))
70
71- Git dependencies now support an optional `path` field to specify a
72 subdirectory within the repository. This is useful for monorepos that
73 contain multiple Gleam packages. For example:
74
75 ```toml
76 [dependencies]
77 my_package = {
78 git = "https://github.com/example/monorepo",
79 ref = "main",
80 path = "packages/my_package",
81 }
82 ```
83
84 ([John Downey](https://github.com/jtdowney))
85
86- The `gleam hex owner transfer` command now uses the flag `--user` instead of
87 the flag `--to`. The `gleam hex owner add` command now takes the package name
88 via the flag `--package`.
89 ([Louis Pilfold](https://github.com/lpil))
90
91- The error message when failing to decrypt the local Hex API key is now more
92 informative and helpful.
93 ([Moritz Böhme](https://github.com/MoritzBoehme))
94
95- The build tool can now authenticate requests to Hex with the API key from the
96 `HEXPM_READ_API_KEY` environment variable, when resolving and downloading
97 dependencies. This raises the request rate limit from the stricter per-IP
98 limit to the higher per-user limit, avoiding "rate limit exceeded" errors
99 when building large projects.
100 ([John Downey](https://github.com/jtdowney))
101
102### Language server
103
104- The language server now supports go-to-definition, find-references and rename
105 for record fields. These work on the field declaration, on labelled arguments,
106 on labelled patterns, on record updates and on `record.field` accesses, both
107 within a module and across modules. For example:
108
109 ```gleam
110 pub type Person {
111 Person(name: String, age: Int)
112 }
113
114 pub fn main() {
115 let lucy = Person(name: "Lucy", age: 10)
116 lucy.name
117 // ^ Go-to-definition jumps to the `name` field, and renaming it here
118 // renames the field everywhere it is used.
119 }
120 ```
121
122 ([Alistair Smith](https://github.com/alii))
123
124- The "pattern match on value" code action can now be used to pattern match on
125 values returned by function calls. For example:
126
127 ```gleam
128 pub fn main() {
129 load_user()
130 // ^^ Triggering the code action over here
131 }
132
133 fn load_user() -> Result(User, Nil) { todo }
134 ```
135
136 Will produce the following code:
137
138 ```gleam
139 pub fn main() {
140 case load_user() {
141 Ok(value) -> todo
142 Error(value) -> todo
143 }
144 }
145 ```
146
147 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
148
149- The language server now offers a code action to rewrite integers in a
150 different base. For example:
151
152 ```gleam
153 pub fn lucky_number() {
154 0b1011
155 //^^^^^^ Hovering this
156 }
157 ```
158
159 The language server is going to show code actions to rewrite it as `11`,
160 `0o13`, or `0xB`.
161 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
162
163- The "remove unreachable patterns" code action can now be triggered on
164 unreachable alternative patterns of a case expression.
165 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
166
167- The language server now permits renaming type variables in functions, types,
168 and constants. For example:
169
170 ```gleam
171 pub fn twice(value: a, f: fn(a) -> a) -> a {
172 // ^ Rename to "anything"
173 f(f(value))
174 }
175 ```
176
177 Produces:
178
179 ```gleam
180 pub fn twice(value: anything, f: fn(anything) -> anything) -> anything {
181 f(f(value))
182 }
183 ```
184
185 ([Surya Rose](https://github.com/GearsDatapacks))
186
187- The language server now automatically updates imports when a Gleam module is
188 renamed. For example:
189
190 ```gleam
191 import db_users
192
193 pub fn main() -> db_users.User {
194 db_users.new("username")
195 }
196 ```
197
198 Renaming `db_users.gleam` to `database/user.gleam` would produce:
199
200 ```gleam
201 import database/user
202
203 pub fn main() -> user.User {
204 user.new("username")
205 }
206 ```
207
208 ([Surya Rose](https://github.com/GearsDatapacks))
209
210- The language server now offers a code action to generate a missing type
211 definition when an unknown type is referenced. For example, if `Wibble`
212 is not defined:
213
214 ```gleam
215 pub fn run(data: Wibble(Int)) { todo }
216 ```
217
218 The code action will generate:
219
220 ```gleam
221 pub type Wibble(a)
222
223 pub fn run(data: Wibble(Int)) { todo }
224 ```
225
226 ([Daniele Scaratti](https://github.com/lupodevelop))
227
228- The language server now has "Discard unused variable" code action to discard
229 unused variables in different places. For example,
230
231 ```gleam
232 pub type Wibble {
233 Wibble(a: Int)
234 }
235
236 pub fn go(record: Wibble) -> Nil {
237 let wibble = 0
238 // ^ Trigger code action here
239
240 case record {
241 Wibble(a:) -> Nil
242 // ^ Trigger code action here
243 }
244
245 case [0, 1, 2] {
246 [_, ..] as wobble -> Nil
247 // ^ Trigger code action here
248 [] -> Nil
249 }
250
251 Nil
252 }
253 ```
254
255 Triggering the code action in all of these places would produce following code:
256
257 ```gleam
258 pub type Wibble {
259 Wibble(a: Int)
260 }
261
262 pub fn go(record: Wibble) -> Nil {
263 let _wibble = 0
264
265 case record {
266 Wibble(a: _) -> Nil
267 }
268
269 case [0, 1, 2] {
270 [_, ..] -> Nil
271 [] -> Nil
272 }
273
274 Nil
275 }
276 ```
277
278 ([Andrey Kozhev](https://github.com/ankddev))
279
280- The language server will now better rename types and values with import
281 aliases by removing `as ...` part in case new name is same as original name of
282 item. For example:
283
284 ```gleam
285 import wibble.{type Wibble as Wobble, Wibble as Wobble}
286
287 pub fn go() -> Wobble {
288 // ^^^^^^ Rename to `Wibble`
289 Wobble
290 //^^^^^^ Rename to `Wibble`
291 }
292 ```
293
294 Will now result in this code:
295
296 ```gleam
297 import wibble.{type Wibble, Wibble}
298
299 pub fn go() -> Wibble {
300 Wibble
301 }
302 ```
303
304 ([Andrey Kozhev](https://github.com/ankddev))
305
306- The language server now supports folding of comments and documentation
307 comments. For example, this code:
308
309 ```gleam
310 //// Very useful module.
311 ////
312 //// It could be used to make interesting things
313
314 /// Function to wibble.
315 ///
316 /// Not that it wobbles when wubble is true
317 pub fn wibble() {
318 // This todo here is temporary.
319 // It will need to be removed at some moment.
320 todo
321 }
322 ```
323
324 can now be folded to:
325
326 ```gleam
327 //// Very useful module. ...
328
329 /// Function to wibble. ...
330 pub fn wibble() {
331 // This todo here is temporary. ...
332 todo
333 }
334 ```
335
336 ([Andrey Kozhev](https://github.com/ankddev))
337
338- The "Convert to function call" code action will now convert the currently
339 hovered call and not only the final one.
340 ([Andrey Kozhev](https://github.com/ankddev))
341
342- When using the "Extract function" code action on statements whose values are
343 unused, the extracted function will return the last statement. For example:
344
345 ```gleam
346 fn main() {
347 //↓ start selection here
348 echo "line 2"
349 echo "line 3"
350 // ↑ end selection here
351 echo "line 4"
352 }
353 ```
354
355 will be turned into
356
357 ```gleam
358 fn main() {
359 function()
360 echo "line 4"
361 }
362
363 fn function() -> String {
364 echo "line 2"
365 echo "line 3"
366 }
367 ```
368
369 ([Gavin Morrow](https://github.com/gavinmorrow))
370
371- The language server now offers a code action to fix the new deprecated pipeline
372 syntax.
373 ([Surya Rose](https://github.com/GearsDatapacks))
374
375- The language server can now find references for and rename items when
376 triggered from an import statement:
377
378 ```gleam
379 import wibble.{type Wibble}
380 // ^^^^^^ Trigger find references or rename here
381
382 pub fn main() {
383 let _ = Wibble
384 }
385 ```
386
387 ([Gavin Morrow](https://github.com/gavinmorrow))
388
389- The language server now has "Convert to documentation comment" and
390 "Convert to regular comment" code actions. For example:
391
392 ```gleam
393 // Module description.
394 // Code action available here.
395
396 // Comment before function.
397 // Another code action here.
398 pub fn wibble() {
399 // No code action here.
400 todo
401 }
402
403 /// Doc comment.
404 /// Another code action here.
405 pub fn wobble () {
406 todo
407 }
408 ```
409
410 Triggering the code actions in all of these places will result in:
411
412 ```gleam
413 //// Module description.
414 //// Code action available here.
415
416 /// Comment before function.
417 /// Another code action here.
418 pub fn wibble() {
419 // No code action here.
420 todo
421 }
422
423 // Doc comment.
424 // Another code action here.
425 pub fn wobble () {
426 todo
427 }
428 ```
429
430 ([Daniel Venable](https://github.com/DanielVenable))
431
432### Formatter
433
434- Performance of the formatter has been improved.
435 `gleam format` has been measured to be up to 13% faster on projects like
436 `lustre`, with a 10% smaller peak memory footprint.
437 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
438
439- Formatter now removes import aliases if the aliased name is the
440 same as the original name. For example,
441
442 ```gleam
443 import wibble.{Wibble as Wibble}
444 ```
445
446 becomes
447
448 ```gleam
449 import wibble.{Wibble}
450 ```
451
452 ([Daniel Venable](https://github.com/DanielVenable))
453
454### Bug fixes
455
456- Fixed a bug where the generated Erlang `.app` file's `modules` list would only
457 contain the modules recompiled by the latest build, becoming empty on a warm
458 rebuild where nothing changed.
459 ([Charlie Tonneslan](https://github.com/c-tonneslan))
460
461- When using the language server to extract a function from within an anonymous
462 function, the return value of the extracted function is respected.
463
464 For example,
465
466 ```gleam
467 fn wibble() {
468 let wobble = fn() {
469 let random_number = 4
470 random_number * 42 // <- Extracting this line
471 }
472 }
473 ```
474
475 is turned into
476
477 ```gleam
478 fn wibble() {
479 let wobble = fn() {
480 let random_number = 4
481 function(random_number)
482 }
483 }
484 fn function(random_number: Int) -> Int {
485 random_number * 42
486 }
487 ```
488
489 ([Gavin Morrow](https://github.com/gavinmorrow))
490
491- Work around an ambiguity of the language server protocol that resulted in
492 editors like Zed inserting the wrong text when accepting type completions.
493 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
494
495- Fixed a bug where the post-publish message for pushing a git commit was
496 formatted incorrectly.
497 ([Louis Pilfold](https://github.com/lpil))
498
499- Fixed a bug where the compiler would generate invalid TypeScript type
500 definitions for records with a field named `constructor`.
501 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
502
503- Fixed a bug where the compiler would generate invalid code for `let assert`
504 expression with bit array patterns.
505 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
506
507- Fixed a bug where the compiler would evaluate the numerator and denominator
508 of a division in the wrong order.
509 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
510
511- Fixed a bug where the compiler would generate Erlang code that raises further
512 warnings for unused values.
513 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
514
515- Fixed a bug where the compiler would raise a warning for truncated int
516 segments when compiling a function with a JavaScript external.
517 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
518
519- Fixed a bug where the compiler would produce a confusing error message when
520 writing a constructor with a lowercase name.
521 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
522
523- A `gleam@@compile.erl` is no longer left in the build output of
524 `gleam compile-package`.
525 ([Louis Pilfold](https://github.com/lpil))
526
527- When using the language server to extract a function from within the body of a
528 use statement, only the selected statement(s) are extracted.
529
530 For example,
531
532 ```gleam
533 pub fn wibble() {
534 use wobble <- result.map(todo)
535 echo wobble as "1" // <- Extracting this line
536 echo wobble as "2"
537 }
538 ```
539
540 is turned into
541
542 ```gleam
543 pub fn wibble() {
544 use wobble <- result.map(todo)
545 function(wobble)
546 echo wobble as "2"
547 }
548 fn function(wobble: a) -> a {
549 echo wobble as "1"
550 }
551 ```
552
553 ([Gavin Morrow](https://github.com/gavinmorrow))
554
555- Fixed a bug where the JavaScript code generator could produce duplicate `let`
556 declarations when a variable was reassigned after being shadowed inside a
557 directly matching `case` branch.
558 ([Eyup Can Akman](https://github.com/eyupcanakman))
559
560- Fixed a bug where the language server would produce wrong code when triggering
561 rename of types and values with import aliases.
562 ([Andrey Kozhev](https://github.com/ankddev))
563
564- Fixed a bug where referencing qualified constructors in constant where a value
565 of the same name exists in scope would cause invalid code to be generated.
566 ([Surya Rose](https://github.com/GearsDatapacks))
567
568- Fixed a bug that would result in `gleam build` being slower than necessary
569 when finding the Gleam files of a package.
570 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
571
572- Fixed a bug where the compiler would not be able to correctly parse negative
573 numbers written in binary, octal, or hexadecimal base.
574 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
575
576- The formatter now properly formats binary operations in bit array size
577 segments.
578 ([Andrey Kozhev](https://github.com/ankddev))
579
580- Fixed a bug where after removing dependencies with `gleam remove` if a
581 removed dependency is still used the build would succeed, resulting in
582 runtime crash due to missing files.
583 ([Andrey Kozhev](https://github.com/ankddev))
584
585- The build tool will no longer panic when unable to lock the build directory.
586 ([Louis Pilfold](https://github.com/lpil))
587
588- The formatter now properly indents multiline trailing comments inside of
589 multiline lists and tuples.
590 ([0xda157](https://github.com/0xda157))
591
592- Fixed a bug where the compiler would panic on the first HTTPS request on
593 Android.
594 ([John Downey](https://github.com/jtdowney))
595
596- Fixed a bug where the language server would not show autocomplete for record
597 fields of internal types within the same package.
598 ([Surya Rose](https://github.com/GearsDatapacks))
599
600- Fixed a bug where warnings and errors in the arguments of a call to a
601 function literal would be reported multiple times.
602 ([John Downey](https://github.com/jtdowney))
603
604- Fixed a bug where pattern matching on overlapping string prefixes with guards
605 could generate incorrect JavaScript.
606 ([John Downey](https://github.com/jtdowney))
607
608- Fixed a bug where running `gleam docs build` on non-Erlang target projects
609 with a warm cache would not produce the module pages.
610 ([Matt Champagne](https://github.com/han-tyumi))
611
612- Fixed a bug where an incorrect `package-interface.json` would be generated for
613 certain type aliases.
614 ([Surya Rose](https://github.com/GearsDatapacks))