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