These are chat archives for ensime/ensime-atom

Aug 2016
hi everyone
is it possible to implement something like this in Atom?

I want to be able to write

if foo == bar <then>

and get it replaced with

if (foo == bar) // <--- added parantheses
    | // <-- cursor here
the <then> is a placeholder, it could either be written or provided as some kind of autocomplete
not sure if that needs server support, it could just add the parens between if and the (imagined) then
(but it only should offer the then-completion if an if was "opened")
Viktor Hedefalk
Aug 18 2016 08:00
@soc Yeah, I think it's definitely possible, but maybe doesn't belong in ensime-atom. Have you looked at :
yes, looked at it. I also had a look at the existing scala-specific snippets
the language that describes what is supposed to happen is not expressive enough for what I want
they all require that you select a snippet ahead of time
in my case, I just want to allow people to start writing code and let the editor fix things when they are done.
btw, is it possible to show text in the editor that "isn't there" and is not selectable/copyable?
(e.g. inferred semicola)
Viktor Hedefalk
Aug 18 2016 18:07
I guess anything is possible, you just gotta write the code :)
And what you describe is not on my list… And it's not really anything ensime-server will help with in any case so I don't think it belongs in ensime-atom…
I think it could profit from some help from ensime-server. is there a way to get the tokens from ensime-server?
basically the look-behind for "are we in an unclosed if"?
could implement that manually, but imho it would be ridiculous to handle all the corner cases like "if" in a string etc. when the compiler already has all the information
Aug 18 2016 18:17
The pc only really works when your code is well formed.
Otherwise regex is better for this
I think the token stream would be fine, i don't need anything typechecked, I just need to be able to recognize an if token
Viktor Hedefalk
Aug 18 2016 20:51

is there a way to get the tokens from ensime-server?

I think the answer is no :) @fommil Do you mean it would also be really really hard to implement in ensime-server because pc doesn't provide it?

Anyway, I think the use-case is SO much easier implemented in simple grammar based client code anyways. But of course, if it was possible to get the token stream from server, it could make a fun exercise…
Aug 18 2016 21:01
Pc doesn't do tokens, you're thinking of scala.meta
Emacs also provides (very basic) tokens ;-)
Pc only provides ast access, and that only works when the code kind of looks right. Some things will totally confuse it, like if you forget to put an equals sign before a method body.