Why got crystal --browser removed?

This seemed to be a really cool feature

I’m not sure what you’re referring to? Do you mean the playground in your browser feature?

1 Like

There was once the command parameter --browser like in crystal foo.cr --browser. I don’t know when it was removed, but in 0.5.0 for example it’s still in. And I think it’s really extremely cool (and probably useful, and something I haven’t seen before for any other language).

It showed your code in your browser, with coloured syntax, and you could hover over variables or methods and see their types or could kinda click through where your application would be going (actually, if you don’t know it, I really recommend you, to try it - no need to overwrite your current install, just use the precompiled stuff from github - it’s really nice!)

1 Like

I think we removed it because it required an http server and we didn’t want to include that in the compiler. Of course then we added the playground anyway, so…

I still don’t know how useful it was. I think it was mainly nice, something to show off, but not very useful.

1 Like

It definitely works to show off - I was immediately impressed.

I think it could be useful for debugging, or whenever one tries to understand foreign code.

1 Like

Yes, I saw the introduction of this feature in this blog below written by @asterite

I am wonder why we move this, it should quite useful.

Is there any discuss about why remove this? anyway, web server never be a issue.

1 Like

When and what would you use it for?

1 Like

Is there a demo of what this flag did and looked like?

I’d probably use it to examine local shards downloaded in my myproj/lib directory - I currently use vim for this, but having the typing info would be more helpful than the print-debugging I’m currently doing :)

From the blog post, it sounds like this browser feature would provide type information for everything in the file - could that be exported to another file / structure or something? I’m thinking of a static code analyzer for crystal that goes deeper than just ameba (statically generate control flow graphs, data flow graphs, etc.).

1 Like

When and what would you use it for?

see the type of variables and navigate methods.

though i don’t know how to check the type of variable on Crystal 0.5.0.

@tsornson , probably --browser is what you want, following code example:

class Foo
  def foo

class Bar < Foo
  def foo

class Baz < Bar; end
class Qux < Bar; end

case rand
when .> 0.2
  obj = Foo.new
when .> 0.4
  obj = Bar.new
when .> 0.6
  obj = Baz.new

Will expanded into this. (Test on Crystal 0.5.0)

you can see the case statement get expanded, when you click on rand, new, will see the source code of them.

But i really don’t know how to print out the type of variable, @asterite , how to do that?

From my point of view, maybe no enough time to improve it, but i consider we don’t need remove it anyway.

1 Like

Right, but that’s impossible to do with browser. The way browser works is:

  • you give it an input file
  • the tool will type that file and any required files
  • the tool will let you navigate only the subset of code that was typed

So to explore a shard you’d have to call every method in the shard with every possible type allowed by the shard.

That’s why I think the tool is a bit useless. It’s much better to use the interpreter for that, as you can play around with the code at the same time.

puts typeof(var)
1 Like

Yes, interpreter is better, though, maybe still not so stable?

But i really don’t know how to print out the type of variable, @asterite , how to do that?

What I’m asking is, how do I do this when with --browser, assume input file include two variable, x = 100, y = “hello”, if we can see types of both of them when run with --browser?

It probably can’t be done? The tool was removed from the compiler because it was incomplete and unused.

I think it’s better to spend time working on the interpreter instead of the browser.


Yes, interperter mode is more useful anyway. though, i consider the feature click on method name to see the method source code is still really useful when use --browser because we still can’t do it in interpreter mode, right? you know, as $ in Pry.

[1] pry(main)> help $
$                  Alias for `show-source`
[2] pry(main)> require 'rbconfig'
[3] pry(main)> $ RbConfig.ruby

From: /home/common/.rvm/rubies/ruby-3.1.0/lib/ruby/3.1.0/x86_64-linux/rbconfig.rb:340:
Owner: #<Class:RbConfig>
Visibility: public
Signature: ruby()
Number of lines: 6

def RbConfig.ruby
    RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"]
[4] pry(main)> 

Is it possible to implement this feature in interpreter mode in the future? @asterite

In my view,it partially worked as a language server, except it’s running respectively at a http window. Therefore, I think its functions a still useful, not for showing, but for directing , quering, and linting.

I’ve been writing crystal with few hints and completions. Often I open the docs in browser, peek the methods, and turn back to my editor,write a sentense, and turn again. There are some language servers for crystal(I tried scry and crystallinge), but they just didn’t work well, or misses something. Compilation needs to restart many times because I have to fix a typo or a type mismatch once for each run, before the real compiling starts.

It would be a good relief if I could code with hints, completions and checks. It would be better if these functions get implemented as a language server. After all,nobody knows more about the syntax and standard library than core developers.

1 Like