Crystalline - LSP server for Crystal

No, it’s not needed to have it in a location covered by the path env :wink:. Providing the absolute location in the vscode configuration option should be good enough.

Actually I just remembered that I put something about moving the binary to a folder covered by the PATH env in the readme. I’ll update to remove that part.

Small update: pre-built binaries are now available, it should greatly simplify the installation step.

3 Likes

:+1:

IMHO not installing it on system path should just make things harder (or at least less straight forward) to all other editors… i.e. require an extra step from user… because for sure every Linux distro will put this binary in a different location when crystalline start to get packaged and shipped by Linux distros.

It is not the Linux distribution that chooses the path but the maintainer of the package. So no problem on this side.

@elbywan can you please reach me in some way? I need to ask you a couple of question. Thanks!

@Acciaiodigitale Just sent you a PM :+1:.

1 Like

Hello, everyone. I’m just getting started with Crystal and managed to setup Crystalline in Emacs setting the variable lsp-clients-crystal-executable to '("/path/to/crystalline"). Just sharing in case someone is looking for this too.

3 Likes

Hello everyone.
I’ve been trying to get some autocompletion feature in vim, but the best I could get is to install YouCompleteMe (YCM) plugin, that can auto-complete already used identifiers.
I’ve found that I can use LSP server, and YCM can be configured to use certain server for a particular file type. So I’ve tried to use crystalline, but nothing actually happens. Doesn’t look like crystalline opens any ports to listen.
How is Crystalline supposed to be used?

Hey @anton7c3,

Crystalline uses standard input / output to send / receive LSP messages. Typically the editor runs it as a separate process and communicates through the STDIN/STDOUT.

I don’t know much about YCM but looking at the docs it seems like there is a config option to run the lsp server like that.

That’s right the kind of information I was looking for, thanks! I guess te following questions should go to YCM authors.

I was following YCM docs. I’ve added this to .vimrc:

let g:ycm_language_server =
  \ [
  \   {
  \     'name': 'crystal',
  \     'cmdline': [ 'crystalline', '--stdio'],
  \     'filetypes': [ 'crystal' ]
  \   }
  \ ]

I have already added vim-crystal, so ‘crystal’ is recognised as file type and syntax highlight works.
The problem remains, nothing happens. All the logs contain nothing interesting, crystalcompleter_stderr*.log is empty.

There is also CoC for vim that uses prettymuch the same config:

  "languageserver": {
    "crystal": {
      "command": "crystalline",
      "args": [
        "--stdio"
      ],
      "filetypes": [
        "crystal"
      ]
    }
  }

I guess I’ll give it a try in case YCM fails.

EDIT: Does it matter that I’m using Crystal 0.36 with the latest Crystalline?

That’s what I found in YCM support channel: looks like a communication is successfull, but Crystalline maybe needs some additional settings.
Here is a simple file I’m testing autocompletion on:

require "http/server"

server = HTTP::Server.new do |context|
  context.response.content_type = "text/plain"
  context.response.print "Hello world!"
end

spawn do
  address = server.bind_tcp 8080
  puts "Listening on http://#{address}"
  server.listen
end

sleep 1.second
server. # <-- This is where autocompletion should obviously work

loop do
  break unless server.listening?
  Fiber.yield
end

puts "Done"

And this is what I get in YCM logs: 2021-06-03 14:57:07,890 - DEBUG - No global extra conf, not calling method YcmCo - Pastebin.com
Here is what is adds if I leave it open for a longer time: 2021-06-03 14:57:07,890 - DEBUG - No global extra conf, not calling method YcmCo - Pastebin.com

I just checked with the same file and using VSCode (best scenario) it seems to be working:

I had a quick look at the logs but did not see anything weird. I guess that the YCM LSP client differs from the vscode one in terms of features and that might be the issue somehow (crystalline does not perform extensive checks to verify that the client supports specific LSP features so this might be a problem).

Whoa, that’s cool.
Is there anything specific that VSCode plugin sets up for everything to work?
YCM has some api to set up LSP server.

For VSCode there is the crystal plugin that supports LSP servers out of the box, it is just a matter of adding the crystalline path to the plugin configuration.


Hell yeah! I was able to use CoC with Crystalline 0.2 to get autocompletion. Still, this thing didn’t seem to work with latest crystalline 0.3.
Looks like crystalline 0.3 is definitely incompatible with crystal 0.36.

I’ve downgraded Crystalline to 0.2 and YCM also started to work fine.
Thanks!

1 Like

Hello again.
I’ve tested Crystalline with a simple one-file project, and it kinda works.
But it fails to show autocompletion in something more difficult. Like crystal-mysql: GitHub - crystal-lang/crystal-mysql: MySQL connector for Crystal (which is not so big or complicated).
I have tried VSCode as well, the autocompletion hardly works (the results of VSCode and vim’s YouCompleteMe/CoC are almost the same).
Is there anything I can do? Some settings? Hints?

Is there anything I can do? Some settings? Hints?

Crystalline needs a way to determine the entry point. There is a paragraph in the readme about how to configure it.

LSP tools is is a real useful tools when do development, not only VSCode, even for any editor which support it, e.g. emacs.

I use emacs for development rust, go, flutter, even ruby(use solargraph as lsp server), tough, for ruby, the most useful function is auto format use rubocop.

autocompletion, auto format before save, see document when mouse hover, syntax check on compile time, those feature is quite impressed when i start work with those modern static-type language. even, when use DAP, this is possible to debug code use breakpoint from editor directly.

But i can’t make lucky work with crystalline, i even tried in VSCode, auto-completion not work in context.

e.g. as following screenshot, when i input plain_t, there is no completion with plain_text appear.

image

  1. Following is my emacs config:
(setq lsp-clients-crystal-executable '("crystalline" "--stdio")) ;; run server with crystalline --stdio

(defun zw/lsp-crystal-common-hooks ()
  (add-hook 'before-save-hook #'lsp-format-buffer t t)
  (lsp-deferred)  ;; start lsp when open crystal file use crystal-mode
  )  

(add-hook 'crystal-mode-hook 'zw/lsp-crystal-common-hooks)
  1. Following is diff for some changes to entry.
diff --git a/.crystalline_main.cr b/.crystalline_main.cr
new file mode 100644
index 0000000..dbfbb76
--- /dev/null
+++ b/.crystalline_main.cr
@@ -0,0 +1,2 @@
+require "./src/**"
+require "./lib/**"
diff --git a/shard.yml b/shard.yml
index 7bb70f6..7533865 100644
--- a/shard.yml
+++ b/shard.yml
@@ -8,6 +8,9 @@ targets:
   app:
     main: src/magpie_code_admin_cr.cr
 
+crystalline:
+  main: .crystalline_main.cr
+
 crystal: 1.4.1

I consider lsp was started successful, but the editor was not work as expected, e.g. autocompletion, jump to definition, it seem like the only working part is, auto format code before save.

Any idea?

Sorry, some feature seem like works when i start a new project for test it use crystal init app.

e .