Giter VIP home page Giter VIP logo

glas's Introduction

Disclaimer

Glas is a personal project, the official Gleam Language Server can be found here.

glas: Gleam Language Server

A language server for the Gleam programming language. Glas tries it's best to help users write Gleam, even when there are parsing and typechecking errors!

Installation

Currently MacOS (arm64, x86), Linux (x86), Windows (x86) are supported. Other targets have to be compiled from source.

VSCode

Install the extension from VisualStudio Marketplace. Binaries are included in the extension archive.

NeoVim

require'lspconfig'.gleam.setup{
  cmd = { "glas", "--stdio" }
}

Features

  • Resilient Parsing and Type Checking
  • Completions
  • Goto Definition
  • Find References
  • Highlight Related
  • Hover Info
  • Syntax Errors
  • Semantic Highlighting
  • Show Syntax Tree
  • Rename

Motivation?

This project was primarily motivated by my personal learning about how language servers, in general, and rust-analyzer, in particular, work. Gleam caught my interest due to it's lovely and active community and the interesting niche (functional, statically typed, simple) it's trying to fill.

Goals

  • Personal Learning
  • Good UX
  • Provide only correct refactorings (if it compiles before it compiles after)
  • Robustness

Non goals

  • Aiming for 100% diagnostics (at least short / midterm)
  • Code generation

Architecture

Since the code in an actual file during development is usually in a broken state, having a specialized IDE architecture helps making sense of the code on a best-effort basis.

In a broad sense, the architecture of glas can be thought of as going from chained steps of fn(IR) -> Result(IRn, Err) to fn(IR) -> (IRn, List(Err))

Where this is particularly evident is in the parser. Instead of aborting at the first error, the parser always produces a concrete syntax tree and collects errors as it goes. This blog post by matklad provides an excellent explanation of this concept, and the parser in this project is based on the ideas presented there. To visualize the syntax tree of a file, the VSCode extension implements the "show syntax tree" command, allowing you to explore the tree as you type.

Acknowledgments

This project is heavily inspired by the exellent Nix language server and rust-analyzer.

glas's People

Contributors

maurobalbi avatar orvitpng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

glas's Issues

Improve hover ( docs, etc)

  • Function docs
  • Adt docs
  • Module docs
  • const docs
  • variant?
  • Fix Hover for qualified patterns (e.g. case expo { module.Body -> ... } )

panic!

problem

glas dies on casual editting

[Error - 7:46:14 PM] Request textDocument/semanticTokens/range failed.
  Message: Panicked in textDocument/semanticTokens/range: called `Option::unwrap()` on a `None` value
Location: crates/ide/src/ty/infer.rs:73:28
Backtrace:    0:        0x10297404c - std::backtrace::Backtrace::create::hfe9b0c8b0decb4ab
   1:        0x1026baff8 - glas::server::with_catch_unwind::{{closure}}::{{closure}}::h011b2297043d86a1
   2:        0x102980144 - std::panicking::rust_panic_with_hook::h9b82bdc13ccb171b
   3:        0x10297fed4 - std::panicking::begin_panic_handler::{{closure}}::hf609a05c98725eb7
   4:        0x10297e87c - std::sys_common::backtrace::__rust_end_short_backtrace::hea0399d584786a2b
   5:        0x10297fc88 - _rust_begin_unwind
   6:        0x1029cc8ac - core::panicking::panic_fmt::hb4d79f470bcac176
   7:        0x1029cc934 - core::panicking::panic::h200a44837950e7c1
   8:        0x1029cc830 - core::option::unwrap_failed::h99ae810f9cb8e26d
   9:        0x10292e5c8 - ide::def::hir::Local::ty::h0821ce4b439e2d67
  10:        0x1028d3628 - core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut::h8cdfbdc5c042d443
  11:        0x1028cb64c - <core::iter::adapters::filter_map::FilterMap<I,F> as core::iter::traits::iterator::Iterator>::next::hbf367b77afb14868
  12:        0x1028d1d30 - <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter::h62d39df5204a4195
  13:        0x1028d9184 - ide::ide::semantic_highlighting::highlight::hc0e959ab6636565a
  14:        0x1028c7340 - salsa::Cancelled::catch::h0d4f15666fa4a140
  15:        0x1028c15f4 - ide::ide::Analysis::syntax_highlight::hc2a0b7e89f6c2a3d
  16:        0x102731450 - glas::handler::semantic_token_range::h849fb8a2c0a5a690
  17:        0x1026ba278 - glas::server::with_catch_unwind::hc4d72faa76c3ce05
  18:        0x1026fdbb8 - tokio::runtime::task::core::Core<T,S>::poll::h0d25ebbda1e22aa2
  19:        0x1026ee3b8 - tokio::runtime::task::harness::Harness<T,S>::poll::h68c7ef79021ecf1d
  20:        0x10280bd30 - tokio::runtime::blocking::pool::Inner::run::hcb46ad0008e9644f
  21:        0x10280ed88 - std::sys_common::backtrace::__rust_begin_short_backtrace::h662079a47ac8f7d6
  22:        0x102806380 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h92f3939abd732dbd
  23:        0x102983d1c - std::sys::pal::unix::thread::Thread::new::thread_start::h028c70d4ad289ac9
  24:        0x18af26f94 - __pthread_joiner_wake

  Code: -32603 

All extension's requests fail due to panic

System: Ubuntu 22, rustc 1.75.0

This is the extension output example:

thread 'tokio-runtime-worker' panicked at /cargo/registry/src/index.crates.io-6f17d22bba15001f/salsa-0.17.0-pre.2/src/input.rs:106:32:
no value set for FileSourceRootQuery(FileId(0))
stack backtrace:
   0: rust_begin_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:72:14
   2: <salsa::input::InputStorage<Q> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
   3: <DB as ide::base::SourceDatabase>::file_source_root::__shim
   4: ide::def::scope::module_scope_with_map_query
   5: salsa::runtime::Runtime::execute_query_implementation
   6: salsa::derived::slot::Slot<Q,MP>::read_upgrade
   7: salsa::derived::slot::Slot<Q,MP>::read
   8: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
   9: salsa::QueryTable<Q>::get
  10: <DB as ide::def::DefDatabase>::module_scope_with_map
  11: salsa::runtime::Runtime::execute_query_implementation
  12: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  13: salsa::derived::slot::Slot<Q,MP>::read
  14: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
  15: <DB as ide::def::DefDatabase>::module_source_map::__shim
  16: ide::def::semantics::find_container
  17: ide::ide::hover::hover
  18: salsa::Cancelled::catch
  19: ide::ide::Analysis::hover
  20: glas::handler::hover
  21: glas::server::with_catch_unwind
  22: tokio::runtime::task::core::Core<T,S>::poll
  23: tokio::runtime::task::harness::Harness<T,S>::poll
  24: tokio::runtime::blocking::pool::Inner::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

[Error - 17:17:12] Request textDocument/hover failed.
  Message: Panicked in textDocument/hover: no value set for FileSourceRootQuery(FileId(0))
Location: /cargo/registry/src/index.crates.io-6f17d22bba15001f/salsa-0.17.0-pre.2/src/input.rs:106:32
Backtrace:    0:     0x7fe5f48367fe - std::backtrace_rs::backtrace::libunwind::trace::h7d9d6777fb8bb20d
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7fe5f48367fe - std::backtrace_rs::backtrace::trace_unsynchronized::hf7cc901404488615
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fe5f48367fe - std::backtrace::Backtrace::create::hd75710cb70a42f36
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/backtrace.rs:331:13
   3:     0x7fe5f4836740 - std::backtrace::Backtrace::force_capture::h7402a920a98228b8
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/backtrace.rs:312:9
   4:     0x7fe5f452ec03 - glas::server::with_catch_unwind::{{closure}}::{{closure}}::h067ed652390b6a61
   5:     0x7fe5f4842b36 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::ha49528d6bb122ccd
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/boxed.rs:2029:9
   6:     0x7fe5f4842b36 - std::panicking::rust_panic_with_hook::hc412fca92650d4b2
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:783:13
   7:     0x7fe5f4842882 - std::panicking::begin_panic_handler::{{closure}}::hf6e9952ead3e2c54
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:657:13
   8:     0x7fe5f4841056 - std::sys_common::backtrace::__rust_end_short_backtrace::h1410a9c85ac94b3e
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/sys_common/backtrace.rs:171:18
   9:     0x7fe5f48425e0 - rust_begin_unwind
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5
  10:     0x7fe5f448c885 - core::panicking::panic_fmt::h2838d0515af9b2ed
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:72:14
  11:     0x7fe5f479292b - <salsa::input::InputStorage<Q> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch::he0b0e02df5dc779d
  12:     0x7fe5f47a90fa - <DB as ide::base::SourceDatabase>::file_source_root::__shim::h478deda2930e308f
  13:     0x7fe5f477b177 - ide::def::scope::module_scope_with_map_query::h164de293526c30f2
  14:     0x7fe5f478679a - salsa::runtime::Runtime::execute_query_implementation::h05e08b4b824059dd
  15:     0x7fe5f47b3ba9 - salsa::derived::slot::Slot<Q,MP>::read_upgrade::h4143b2c7eab33d8d
  16:     0x7fe5f47d15d4 - salsa::derived::slot::Slot<Q,MP>::read::hec8921686c06954d
  17:     0x7fe5f4771735 - <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch::hddad7f0d0b967ae0
  18:     0x7fe5f47861de - salsa::QueryTable<Q>::get::h7f23c23d63a8012f
  19:     0x7fe5f473981f - <DB as ide::def::DefDatabase>::module_scope_with_map::h88856ee117664130
  20:     0x7fe5f47869cb - salsa::runtime::Runtime::execute_query_implementation::h06add4c949ed1ddc
  21:     0x7fe5f47b51dc - salsa::derived::slot::Slot<Q,MP>::read_upgrade::h540d66a3b5fb77d0
  22:     0x7fe5f47ceb3d - salsa::derived::slot::Slot<Q,MP>::read::h796e06c36b726a60
  23:     0x7fe5f476e284 - <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch::h10f43a3e12f3071f
  24:     0x7fe5f479a94a - <DB as ide::def::DefDatabase>::module_source_map::__shim::h31266f8d959614d0
  25:     0x7fe5f4737c52 - ide::def::semantics::find_container::h83283511dd339c32
  26:     0x7fe5f4797155 - ide::ide::hover::hover::hf436f79a802db256
  27:     0x7fe5f47885b5 - salsa::Cancelled::catch::he9c8286c27095da6
  28:     0x7fe5f4738a10 - ide::ide::Analysis::hover::ha716ef33cd2f8e9c
  29:     0x7fe5f45522fc - glas::handler::hover::h34f9551c5c5d20fb
  30:     0x7fe5f44f42d0 - glas::server::with_catch_unwind::h688c6907f203d18b
  31:     0x7fe5f456bbf5 - tokio::runtime::task::core::Core<T,S>::poll::h5512e2189bd18e90
  32:     0x7fe5f4518b16 - tokio::runtime::task::harness::Harness<T,S>::poll::h9dfbf7e146c85fc3
  33:     0x7fe5f46a953c - tokio::runtime::blocking::pool::Inner::run::h97622e1faf281135
  34:     0x7fe5f46b8fa4 - std::sys_common::backtrace::__rust_begin_short_backtrace::h00e99ec19de4aaad
  35:     0x7fe5f46b99a9 - core::ops::function::FnOnce::call_once{{vtable.shim}}::hd46e71c8ef512c30
  36:     0x7fe5f4847f05 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h0c19c267a854c212
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/boxed.rs:2015:9
  37:     0x7fe5f4847f05 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc50bf08128f952fb
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/boxed.rs:2015:9
  38:     0x7fe5f4847f05 - std::sys::unix::thread::Thread::new::thread_start::ha18af1a028ebd29e
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/sys/unix/thread.rs:108:17

  Code: -32603 

Improve completion

  • Add types completion, with trigger char ':'
  • Fix pattern completion (only show constructors)
  • Fix aliased imported modules

Text gets appended instead of replaces

for example (| is the cursor)

import gleam/|
// this will autocomplete to `gleam/io`, `gleam/otp`...

when i select gleam/io, i'd expect it to have result like this

import gleam/io

instead it gives me this

import gleam/gleam/io

Syntax error in hexadecimal representation with letters

Hi, thanks for this extension, it really helps learning the language!

I don't know if it's Gleam LSP or glas, but this code is throwing syntax errors when there are letters in the hex values:

import gleam/io

fn dbg(i: Int) {
  io.debug(i)
}

pub fn main() {
  io.println("Hello from glas_test!")
  dbg(0x0)
  dbg(0x00112233)
  dbg(0x0a)
  dbg(0xa0)
  dbg(0xaa)
  dbg(0xAA)
  dbg(0xAABBCCDD)
}

image

The program compiles and runs just fine, it's not a big problem for me.
The official gleam extension doesn't show this error, but it's too early to use it.

My setup:

  • Windows 10
  • VSCode 1.88.1
  • Gleam 1.0.0
  • glas v0.2.3

v1

Fixes / Features RC:

Prio 1

Prio 2

  • Add signature help
  • semantic highlight
  • Add Inlay - Hints ?
  • Add rename assists!
  • call diagnostics / arguments
  • completion expr.use, maybe more?
  • #12

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.