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