Fork of daniellemaywood.uk/gleam — Wasm codegen work
16 kB
589 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### Language server
96
97- The language server now supports go-to-definition, find-references and rename
98 for record fields. These work on the field declaration, on labelled arguments,
99 on labelled patterns, on record updates and on `record.field` accesses, both
100 within a module and across modules. For example:
101
102 ```gleam
103 pub type Person {
104 Person(name: String, age: Int)
105 }
106
107 pub fn main() {
108 let lucy = Person(name: "Lucy", age: 10)
109 lucy.name
110 // ^ Go-to-definition jumps to the `name` field, and renaming it here
111 // renames the field everywhere it is used.
112 }
113 ```
114
115 ([Alistair Smith](https://github.com/alii))
116
117- The "pattern match on value" code action can now be used to pattern match on
118 values returned by function calls. For example:
119
120 ```gleam
121 pub fn main() {
122 load_user()
123 // ^^ Triggering the code action over here
124 }
125
126 fn load_user() -> Result(User, Nil) { todo }
127 ```
128
129 Will produce the following code:
130
131 ```gleam
132 pub fn main() {
133 case load_user() {
134 Ok(value) -> todo
135 Error(value) -> todo
136 }
137 }
138 ```
139
140 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
141
142- The "remove unreachable patterns" code action can now be triggered on
143 unreachable alternative patterns of a case expression.
144 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
145
146- The language server now permits renaming type variables in functions, types,
147 and constants. For example:
148
149 ```gleam
150 pub fn twice(value: a, f: fn(a) -> a) -> a {
151 // ^ Rename to "anything"
152 f(f(value))
153 }
154 ```
155
156 Produces:
157
158 ```gleam
159 pub fn twice(value: anything, f: fn(anything) -> anything) -> anything {
160 f(f(value))
161 }
162 ```
163
164 ([Surya Rose](https://github.com/GearsDatapacks))
165
166- The language server now automatically updates imports when a Gleam module is
167 renamed. For example:
168
169 ```gleam
170 import db_users
171
172 pub fn main() -> db_users.User {
173 db_users.new("username")
174 }
175 ```
176
177 Renaming `db_users.gleam` to `database/user.gleam` would produce:
178
179 ```gleam
180 import database/user
181
182 pub fn main() -> user.User {
183 user.new("username")
184 }
185 ```
186
187 ([Surya Rose](https://github.com/GearsDatapacks))
188
189- The language server now offers a code action to generate a missing type
190 definition when an unknown type is referenced. For example, if `Wibble`
191 is not defined:
192
193 ```gleam
194 pub fn run(data: Wibble(Int)) { todo }
195 ```
196
197 The code action will generate:
198
199 ```gleam
200 pub type Wibble(a)
201
202 pub fn run(data: Wibble(Int)) { todo }
203 ```
204
205 ([Daniele Scaratti](https://github.com/lupodevelop))
206
207- The language server now has "Discard unused variable" code action to discard
208 unused variables in different places. For example,
209
210 ```gleam
211 pub type Wibble {
212 Wibble(a: Int)
213 }
214
215 pub fn go(record: Wibble) -> Nil {
216 let wibble = 0
217 // ^ Trigger code action here
218
219 case record {
220 Wibble(a:) -> Nil
221 // ^ Trigger code action here
222 }
223
224 case [0, 1, 2] {
225 [_, ..] as wobble -> Nil
226 // ^ Trigger code action here
227 [] -> Nil
228 }
229
230 Nil
231 }
232 ```
233
234 Triggering the code action in all of these places would produce following code:
235
236 ```gleam
237 pub type Wibble {
238 Wibble(a: Int)
239 }
240
241 pub fn go(record: Wibble) -> Nil {
242 let _wibble = 0
243
244 case record {
245 Wibble(a: _) -> Nil
246 }
247
248 case [0, 1, 2] {
249 [_, ..] -> Nil
250 [] -> Nil
251 }
252
253 Nil
254 }
255 ```
256
257 ([Andrey Kozhev](https://github.com/ankddev))
258
259- The language server will now better rename types and values with import
260 aliases by removing `as ...` part in case new name is same as original name of
261 item. For example:
262
263 ```gleam
264 import wibble.{type Wibble as Wobble, Wibble as Wobble}
265
266 pub fn go() -> Wobble {
267 // ^^^^^^ Rename to `Wibble`
268 Wobble
269 //^^^^^^ Rename to `Wibble`
270 }
271 ```
272
273 Will now result in this code:
274
275 ```gleam
276 import wibble.{type Wibble, Wibble}
277
278 pub fn go() -> Wibble {
279 Wibble
280 }
281 ```
282
283 ([Andrey Kozhev](https://github.com/ankddev))
284
285- The language server now supports folding of comments and documentation
286 comments. For example, this code:
287
288 ```gleam
289 //// Very useful module.
290 ////
291 //// It could be used to make interesting things
292
293 /// Function to wibble.
294 ///
295 /// Not that it wobbles when wubble is true
296 pub fn wibble() {
297 // This todo here is temporary.
298 // It will need to be removed at some moment.
299 todo
300 }
301 ```
302
303 can now be folded to:
304
305 ```gleam
306 //// Very useful module. ...
307
308 /// Function to wibble. ...
309 pub fn wibble() {
310 // This todo here is temporary. ...
311 todo
312 }
313 ```
314
315 ([Andrey Kozhev](https://github.com/ankddev))
316
317- The "Convert to function call" code action will now convert the currently
318 hovered call and not only the final one.
319 ([Andrey Kozhev](https://github.com/ankddev))
320
321- When using the "Extract function" code action on statements whose values are
322 unused, the extracted function will return the last statement. For example:
323
324 ```gleam
325 fn main() {
326 //↓ start selection here
327 echo "line 2"
328 echo "line 3"
329 // ↑ end selection here
330 echo "line 4"
331 }
332 ```
333
334 will be turned into
335
336 ```gleam
337 fn main() {
338 function()
339 echo "line 4"
340 }
341
342 fn function() -> String {
343 echo "line 2"
344 echo "line 3"
345 }
346 ```
347
348 ([Gavin Morrow](https://github.com/gavinmorrow))
349
350- The language server now offers a code action to fix the new deprecated pipeline
351 syntax.
352 ([Surya Rose](https://github.com/GearsDatapacks))
353
354- The language server can now find references for and rename items when
355 triggered from an import statement:
356
357 ```gleam
358 import wibble.{type Wibble}
359 // ^^^^^^ Trigger find references or rename here
360
361 pub fn main() {
362 let _ = Wibble
363 }
364 ```
365
366 ([Gavin Morrow](https://github.com/gavinmorrow))
367
368- The language server now has "Convert to documentation comment" and
369 "Convert to regular comment" code actions. For example:
370
371 ```gleam
372 // Module description.
373 // Code action available here.
374
375 // Comment before function.
376 // Another code action here.
377 pub fn wibble() {
378 // No code action here.
379 todo
380 }
381
382 /// Doc comment.
383 /// Another code action here.
384 pub fn wobble () {
385 todo
386 }
387 ```
388
389 Triggering the code actions in all of these places will result in:
390
391 ```gleam
392 //// Module description.
393 //// Code action available here.
394
395 /// Comment before function.
396 /// Another code action here.
397 pub fn wibble() {
398 // No code action here.
399 todo
400 }
401
402 // Doc comment.
403 // Another code action here.
404 pub fn wobble () {
405 todo
406 }
407 ```
408
409 ([Daniel Venable](https://github.com/DanielVenable))
410
411### Formatter
412
413- Performance of the formatter has been improved.
414 `gleam format` has been measured to be up to 13% faster on projects like
415 `lustre`, with a 10% smaller peak memory footprint.
416 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
417
418- Formatter now removes import aliases if the aliased name is the
419 same as the original name. For example,
420
421 ```gleam
422 import wibble.{Wibble as Wibble}
423 ```
424
425 becomes
426
427 ```gleam
428 import wibble.{Wibble}
429 ```
430
431 ([Daniel Venable](https://github.com/DanielVenable))
432
433### Bug fixes
434
435- Fixed a bug where the generated Erlang `.app` file's `modules` list would only
436 contain the modules recompiled by the latest build, becoming empty on a warm
437 rebuild where nothing changed.
438 ([Charlie Tonneslan](https://github.com/c-tonneslan))
439
440- When using the language server to extract a function from within an anonymous
441 function, the return value of the extracted function is respected.
442
443 For example,
444
445 ```gleam
446 fn wibble() {
447 let wobble = fn() {
448 let random_number = 4
449 random_number * 42 // <- Extracting this line
450 }
451 }
452 ```
453
454 is turned into
455
456 ```gleam
457 fn wibble() {
458 let wobble = fn() {
459 let random_number = 4
460 function(random_number)
461 }
462 }
463 fn function(random_number: Int) -> Int {
464 random_number * 42
465 }
466 ```
467
468 ([Gavin Morrow](https://github.com/gavinmorrow))
469
470- Work around an ambiguity of the language server protocol that resulted in
471 editors like Zed inserting the wrong text when accepting type completions.
472 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
473
474- Fixed a bug where the post-publish message for pushing a git commit was
475 formatted incorrectly.
476 ([Louis Pilfold](https://github.com/lpil))
477
478- Fixed a bug where the compiler would generate invalid TypeScript type
479 definitions for records with a field named `constructor`.
480 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
481
482- Fixed a bug where the compiler would generate invalid code for `let assert`
483 expression with bit array patterns.
484 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
485
486- Fixed a bug where the compiler would evaluate the numerator and denominator
487 of a division in the wrong order.
488 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
489
490- Fixed a bug where the compiler would generate Erlang code that raises further
491 warnings for unused values.
492 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
493
494- Fixed a bug where the compiler would raise a warning for truncated int
495 segments when compiling a function with a JavaScript external.
496 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
497
498- Fixed a bug where the compiler would produce a confusing error message when
499 writing a constructor with a lowercase name.
500 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
501
502- A `gleam@@compile.erl` is no longer left in the build output of
503 `gleam compile-package`.
504 ([Louis Pilfold](https://github.com/lpil))
505
506- When using the language server to extract a function from within the body of a
507 use statement, only the selected statement(s) are extracted.
508
509 For example,
510
511 ```gleam
512 pub fn wibble() {
513 use wobble <- result.map(todo)
514 echo wobble as "1" // <- Extracting this line
515 echo wobble as "2"
516 }
517 ```
518
519 is turned into
520
521 ```gleam
522 pub fn wibble() {
523 use wobble <- result.map(todo)
524 function(wobble)
525 echo wobble as "2"
526 }
527 fn function(wobble: a) -> a {
528 echo wobble as "1"
529 }
530 ```
531
532 ([Gavin Morrow](https://github.com/gavinmorrow))
533
534- Fixed a bug where the JavaScript code generator could produce duplicate `let`
535 declarations when a variable was reassigned after being shadowed inside a
536 directly matching `case` branch.
537 ([Eyup Can Akman](https://github.com/eyupcanakman))
538
539- Fixed a bug where the language server would produce wrong code when triggering
540 rename of types and values with import aliases.
541 ([Andrey Kozhev](https://github.com/ankddev))
542
543- Fixed a bug where referencing qualified constructors in constant where a value
544 of the same name exists in scope would cause invalid code to be generated.
545 ([Surya Rose](https://github.com/GearsDatapacks))
546
547- Fixed a bug that would result in `gleam build` being slower than necessary
548 when finding the Gleam files of a package.
549 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
550
551- The formatter now properly formats binary operations in bit array size
552 segments.
553 ([Andrey Kozhev](https://github.com/ankddev))
554
555- Fixed a bug where after removing dependencies with `gleam remove` if a
556 removed dependency is still used the build would succeed, resulting in
557 runtime crash due to missing files.
558 ([Andrey Kozhev](https://github.com/ankddev))
559
560- The build tool will no longer panic when unable to lock the build directory.
561 ([Louis Pilfold](https://github.com/lpil))
562
563- The formatter now properly indents multiline trailing comments inside of
564 multiline lists and tuples.
565 ([0xda157](https://github.com/0xda157))
566
567- Fixed a bug where the compiler would panic on the first HTTPS request on
568 Android.
569 ([John Downey](https://github.com/jtdowney))
570
571- Fixed a bug where the language server would not show autocomplete for record
572 fields of internal types within the same package.
573 ([Surya Rose](https://github.com/GearsDatapacks))
574
575- Fixed a bug where warnings and errors in the arguments of a call to a
576 function literal would be reported multiple times.
577 ([John Downey](https://github.com/jtdowney))
578
579- Fixed a bug where pattern matching on overlapping string prefixes with guards
580 could generate incorrect JavaScript.
581 ([John Downey](https://github.com/jtdowney))
582
583- Fixed a bug where running `gleam docs build` on non-Erlang target projects
584 with a warm cache would not produce the module pages.
585 ([Matt Champagne](https://github.com/han-tyumi))
586
587- Fixed a bug where an incorrect `package-interface.json` would be generated for
588 certain type aliases.
589 ([Surya Rose](https://github.com/GearsDatapacks))