Introduction
Gleam continues to push the envelope with its latest release, version 1.18.0. Designed for the Erlang virtual machine and JavaScript environments, Gleam stands out for its static type safety and scalability. This update further strengthens these features with significant enhancements to the language server, making development more streamlined and efficient.
Record Field Support
One of the major additions in this release is the full support for record fields in the language server. This includes features like 'go-to-definition', 'find-references', and 'rename' for record fields. Whether in a field declaration, a labeled argument, a labeled pattern, a record update, or a record field access, all these operations now work seamlessly, both within a module and across different modules.
Concrete Example
Consider the Person type example:
``gleam pub type Person { Person(name: String, age: Int) } pub fn main() { let lucy = Person(name: "Lucy", age: 10) lucy.name // ^ Go-to-definition jumps to the name field, and renaming it here // renames the field everywhere it is used. } ``
Record field support enables quick and safe global modifications, thus boosting developer productivity.
Type Variable Renaming
Similarly, the language server now allows renaming type variables in functions, types, and constants. This simplifies refactoring and avoids potential errors associated with manual type handling.
Renaming Example
``gleam pub fn twice(value: a, f: fn(a) -> a) -> a { f(f(value)) } ``
Can be renamed to:
``gleam pub fn twice(value: anything, f: fn(anything) -> anything) -> anything { f(f(value)) } ``
Updating Imports for Renamed Modules
Another handy feature is the automatic updating of imports for renamed modules. This prevents developers from having to manually find and modify every instance of a renamed module, thus reducing the risk of errors and time loss.
Code Action for Pattern Matching
Flow control in Gleam is done through pattern matching. The language server now offers a code action that quickly inserts a case expression, allowing developers to easily add their logic.
Pattern Matching Example
``gleam pub fn main() { case load_user() { Ok(value) -> todo Error(value) -> todo } } ``
Improved JavaScript Performance
Finally, Gleam continues to optimize its JavaScript output by producing straightforward and efficient code, ensuring performance comparable to that of manually written code.
Conclusion
Gleam v1.18.0 is a major update that significantly enhances the developer experience. Whether you're an experienced developer or a newcomer, the improvements in this update will make your work more efficient and enjoyable.
Let's discuss your project in 15 minutes.