crystal-lang-tools / emacs-crystal-mode Goto Github PK
View Code? Open in Web Editor NEWA minimal crystal mode for emacs, based on ruby-mode.
Home Page: https://melpa.org/#/crystal-mode
License: GNU General Public License v3.0
A minimal crystal mode for emacs, based on ruby-mode.
Home Page: https://melpa.org/#/crystal-mode
License: GNU General Public License v3.0
It would be great to have this available on https://melpa.org. Then people can install it using package-install or use-package.
So, given two files, for example:
lib/x.cr
class X
end
require "./x/y"
lib/x/y.cr
class Y < X
end
It seems I can't jump to the definition of X
I get undefined constant X
.
I'm not sure how that could be resolved, how do i tell it what my top level entry file is?
def twice
yield
yield
end
twice do
puts "hello!"
end
Bad string error occurs when calling crystal-beginning-of-block
and crystal-end-of-block
in a block(twice
).
Crystal 0.24.1 (2017-12-22)
LLVM: 4.0.0
Default target: x86_64-unknown-linux-gnu
It would be nice to have this include yasnippets for commonly used patterns like
module ModuleName
end
class ClassName
end
etc
Please check following example:
macro included
def hello
puts "hello"
end
end
The end in the last line not get indent correct.
I don't sure this issue caused by flycheck or crystal-flycheck.el, so create issue here first.
Thank you.
class MineralC
def initialize
@callbacks = [] of ->
p typeof(@callbacks) # <= this line indent wrong
end
end
Thank you.
emacs 29.1 will be getting native tree-sitter support and a number of major modes are currently being converted to utilize exactly that.
It would be awesome to have both tree-sitter support for crystal and a crystal-ts-mode
to make use of it.
I don't realistically think I will have time to do it, but I would love to get it going....
Indented by crystal mode:
a = Array.new(String)
a << "b"
if a[0] == "b"
puts "hi"
elsif a.[0]? == "b"
puts "hi"
elsif a[0]? == "b"
puts hi
end
Indenting with crystal tool format
works.
Hi, my emacs is getting stuck whenever I run crystal-beginning-of-block
and crystal-end-of-block
.
Indentation of two dimensional arrays works fine if not type hint is given for the internal arrays. But if you try to indent two dimensional arrays with type hints it all goes wrong. It especially renders a code with hard-coded large two dimensional arrays unreadable the behavior is as shown below.
[[1,2,3,4],
[5,5,6,7]]
[[1, 2, 3] of UInt8,
[4, 5, 6] of UInt8]
i've got a macro def similar to this:
class Form
def self.whatever
{% for var in @type.instance.instance_vars %}
# do things here
{% end %}
end
end
but crystal-mode parses the {% end %}
tag as just a normal end
keyword, leading to it thinking the final end
(for the class) is extra and a syntax error
This is failing to format following code properly: https://gist.github.com/greenbigfrog/62f3de6ab0b9cda161c2a2dad2851b02
crystal tool format
does it correctly though.
Plese check following code:
def self.get_user_by_auth_token(auth_token)
decoded_open_id = decoded["open_id"]?
if decoded_auth_token_salt.nil?
return nil
end
user
end
When the cursor is upon the def, after pressing C-M-F
, What we expected is to jump to the last line after end.
But, the actual behavior is: (cursor is I)
def self.get_user_by_auth_token(auth_token)
decoded_open_id = decoded["open_id"]?
if decoded_auth_token_salt.nil?
return nil
endI
user
end
the jumped position is after the end of if
.
It seems the variable is removed as of emacs 25.1. The jump to def function seems to be using it.
( Can't reopen #12 )
unless ENV["TIPBOT_ENV"]? == "test"
puts "No Config File specified! Exiting!" if ARGV.size == 0
Formats correctly with tool...
Example input:
%{ if flag?(:foo) %}
bar
%{ end %}
When I move the cursor to the "b" in bar or the two white spaces before it, it throws the following error:
Debugger entered--Lisp error: (search-failed "{%")
re-search-backward("{%")
...
crystal-smie--backward-token()
smie--opener/closer-at-point()
smie--matching-block-data(#f(compiled-function (&rest args) #<bytecode -0x1d15d4b1af694f36>))
apply(smie--matching-block-data #f(compiled-function (&rest args) #<bytecode -0x1d15d4b1af694f36>) nil)
#f(advice-wrapper :around #f(compiled-function (&rest args) #<bytecode -0x1d15d4b1af694f36>) smie--matching-block-data)()
show-paren-function()
apply(show-paren-function nil)
timer-event-handler([t 0 0 125000 t show-paren-function nil idle 0 nil])
It also moves the cursor, which means you have to disable crystal-mode if you want to edit.
My current workaround is to modify the function crystal-smie--backward-token
:
emacs-crystal-mode/crystal-mode.el
Line 693 in ea2da3c
Putting a ignore-errors
around the body suppresses the error and cursor doesn't jump. I don't know if that is a good solution (to try it out I created a PR: #53).
Crystal mode is indenting abstract def
as if it needed an end
(abstract methods have no actual definition and therefore no need for end
)
e.g. following code when indent with emacs builtin ruby-mode (without LSP enabled), it will indent like this:
# test.rb, it correct.
result = (42..47).to_a # (1) => [42, 43, 44, 45, 46, 47]
.sort { |n, m| m <=> n } # (2) => [47, 46, 45, 44, 43, 42]
.reject { |n| n.odd? } # (3) => [46, 44, 42]
.map { |n| n * n } # (4) => [2116, 1936, 1764]
.select { |n| n % 4 == 0 } # (5) => [2116, 1936, 1764]
.tap { |arr| puts "#{arr.inspect}" } # (6) => [2116, 1936, 1764]
.sort! # (7) => [1764, 1936, 2116]
.any? { |num| num > 2000 } # (8) => true
but, if switch to crystal-mode, it indent like this:
# test1.cr, indent not correct
result = (42..47).to_a # (1) => [42, 43, 44, 45, 46, 47]
.sort { |n, m| m <=> n } # (2) => [47, 46, 45, 44, 43, 42]
.reject { |n| n.odd? } # (3) => [46, 44, 42]
.map { |n| n * n } # (4) => [2116, 1936, 1764]
.select { |n| n % 4 == 0 } # (5) => [2116, 1936, 1764]
.tap { |arr| puts "#{arr.inspect}" } # (6) => [2116, 1936, 1764]
.sort! # (7) => [1764, 1936, 2116]
.any? { |num| num > 2000 } # (8) => true
But, if remove the those comment from line ending, it indent correct again.
# test2.cr, indent correct.
result = (42..47).to_a
.sort { |n, m| m <=> n }
.reject { |n| n.odd? }
.map { |n| n * n }
.select { |n| n % 4 == 0 }
.tap { |arr| puts "#{arr.inspect}" }
.sort!
.any? { |num| num > 2000 }
Have you any idea about to upgrade this plugin to new release of Emacs?
The in
statement inside a case block doesnt indent properly
It should be flush with the case
, like the when
keyword, but instead indents by 4 or 2 spaces, depending on how many are present.
smartparens crystal support, you can try it.
How do you generally use flycheck-crystal
? I find that it's basically useless for lots of perfectly fine code because compiling the source file you're editing on its own can give errors about missing namespaces or namespaces that are incorrectly loaded as modules when they should be classes.
This is not an issue for real-world compilation as the compilation targets (such as bin/something
or spec/something_test.cr
) usually follow a pattern of calling a main module/class file (e.g. src/something.cr
) which loads everything and does so in the correct order.
I thought about extending the call to flycheck-define-checker
to also compile spec/spec_helper.cr
if it exists, but that's not so clean since a lot of projects use it to set up mocks and other things.
struct Test
DB.mapping({
test: String,
})
end
The example above gets indented correctly with the tool format, not in emacs though.
abstract class Shape
abstract def area
abstract def perim
end
Will indent to:
abstract class Shape
abstract def area
abstract def perim
end
Thank you.
I need the support for the abstract
syntax
Current indent behavior is
abstract class Bra
abstract def hoge
abstract def fuga
abstract def hoga
...
end
Right now when requiring a file it completes the full path to the file, including the .cr
extension. Using completion-at-point-functions
it should be possible to make this complete just the filename and not the extension.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.