Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add Scala support #188

Open
jsatk opened this issue Apr 27, 2022 · 3 comments
Open

Feature request: Add Scala support #188

jsatk opened this issue Apr 27, 2022 · 3 comments

Comments

@jsatk
Copy link

jsatk commented Apr 27, 2022

Great plugin.

I primarily work in Scala these days however and I miss being able to use this plugin.

Namely I often have cause to turn this:

def f(a: Int, b: Int, c: Int): Int = ???

into...

def f(
  a: Int,
  b: Int,
  c: Int,
): Int = ???

or the reverse.

I forked & cloned this repo myself and have started poking around. I have some very basic Scala support going but still can't quite accomplish this. I'm okay at regex but I don't know I quite have the chops for some of what you do in here.

Would it be possible for me to open a WIP PR and get feedback from you or other contributors to realize some basic Scala support?

Thanks Andrew!

@jsatk
Copy link
Author

jsatk commented Apr 27, 2022

To expand on the above. I've been reading through your files for various other languages I know but am still a bit stumped. I think the = in function definitions is throwing things off in my regex.

@AndrewRadev
Copy link
Owner

AndrewRadev commented Apr 27, 2022

If you'd like to submit a WIP PR, I'd be happy to take a look and suggest fixes 👍

I think the = in function definitions is throwing things off in my regex.

For something like splitting the contents of a function definition, I think you could use an argparser instead of a single regex, something like this:

let items = sj#ParseJsonObjectBody(from + 1, to - 1)
if empty(items)
return 0
endif
if sj#settings#Read('trailing_comma')
let body = start."\n".join(items, ",\n").",\n".end
else
let body = start."\n".join(items, ",\n")."\n".end
endif
call sj#ReplaceMotion('Va'.start, body)

So, something like "search backwards for a def \k\+(, then save the starting point of the ( and normal! % to the closing )". With a start and end position, you could try parsing the individual arguments via sj#ParseJsonObjectBody.

There might be complications with types, not sure, you could also take a look at https://github.com/AndrewRadev/splitjoin.vim/blob/main/autoload/sj/argparser/rust.vim for a custom parser implementation used for Rust struct definitions.

@jsatk
Copy link
Author

jsatk commented Apr 27, 2022

Thanks so much @AndrewRadev. I'll try to get a WIP PR out this week for basic support. Appreciate the kind reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants