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

Kotlin Language Support #1581

Closed
mustafaozhan opened this issue Aug 20, 2017 · 24 comments · Fixed by #2186

Comments

@mustafaozhan
Copy link

commented Aug 20, 2017

Hello,

I use geany for my all works and after i move from Java to Kotlin for Android. I realized that Geany do not have a support Kotlin language syntax can you add this support please ?

@mustafaozhan mustafaozhan changed the title Kotlin Languange Support Kotlin Language Support Aug 20, 2017
@elextr elextr added the enhancement label Aug 25, 2017
@esotericpig

This comment has been minimized.

Copy link

commented Jul 13, 2018

+1 I'd like this feature as well :)

@mustafaozhan

This comment has been minimized.

Copy link
Author

commented Jul 13, 2018

I wanna move back the Geany again 🙏

@elextr

This comment has been minimized.

Copy link
Member

commented Jul 13, 2018

Feel free to post a pull request with a custom filetype file, maybe based on Java.

Note that if Kotlin needs specific highlighting and symbols support those need to be added to the Scintilla and UCtags first before the integration into Geany.

@esotericpig

This comment has been minimized.

Copy link

commented Jul 15, 2018

I went to the Scintilla website, but the documentation is pretty bad (IMO) for adding a new language. Is there an example or documentation available for how to add a new language? And also for making a pull request? (Wish it was on GitHub.)

I'd like to also add Groovy.

I also don't know what to do for UCtags. Grateful for any help. Thanks.

@elextr

This comment has been minimized.

Copy link
Member

commented Jul 15, 2018

@esotericpig I'm not aware of any better docs than those projects own resources, maybe you could ask there (they are both totally separate projects from Geany, we just use their products).

Maybe its not clear from the post above, but you can (actually must) use the lexer of an existing filetype and the parser of a possibly different existing filetype with a custom filetype. Thats probably the first thing to try, you may find existing ones are "good enough". I suggested Java, but I don't know how close Kotlin is, you could try any of the built-in languages.

@esotericpig

This comment has been minimized.

Copy link

commented Jul 16, 2018

I forked the project on SourceForge, but seems like a lot of work, don't know if I will get around to doing it (as I have other projects I'm working on).

I found this:
https://www.scintilla.org/Lexer.txt

Basically, you would need to copy this file as LexKotlin.cxx:
https://github.com/geany/geany/blob/master/scintilla/lexers/LexCPP.cxx
https://sourceforge.net/p/scintilla/code/ci/default/tree/lexers/LexCPP.cxx

Then add the new keywords and syntax that Kotlin has, such as object (lower-case), data class, sealed class, fun, then, etc. I think you'd probably also want to remove parsing of the ternary operator a ? b : c and add parsing for the elvis operator a ?: b.

You can also look at this project that is adding the Rust language:
https://sourceforge.net/u/dobkeratops/scintilla/ci/default/tree/

Here are other open source projects that have added Kotlin support for help as well:
https://github.com/vkostyukov/kotlin-sublime-package
https://github.com/nishtahir/language-kotlin

@esotericpig

This comment has been minimized.

Copy link

commented Jul 16, 2018

I opened up a feature request:

https://sourceforge.net/p/scintilla/feature-requests/1224/

So maybe someone with more knowledge of Scintilla will do it properly, or at least help guide how to do it.

@elextr

This comment has been minimized.

Copy link
Member

commented Jul 16, 2018

I opened up a feature request:

Yes, you are better off engaging directly with Scintilla.

@b4n

This comment has been minimized.

Copy link
Member

commented Jul 16, 2018

@esotericpig from what you mention it sounds like it'd be easy to create a custom filetype just adding a few keywords, at least for the highlighting part, if the syntax is basically C++.

For extracting symbols (the Universal-CTags part) it might actually require some extra work if there is different syntax for defining classes or such, as then it's not merely tokenizing but parsing.

@elextr

This comment has been minimized.

Copy link
Member

commented Jul 16, 2018

@esotericpig while you are waiting for Scintilla and Uctags, did you actually try making a custom filetype using an existing lexer and parser?

@esotericpig

This comment has been minimized.

Copy link

commented Jul 16, 2018

Thanks, that's probably the best way.

I made ~/.config/geany/filedefs/filetypes.kotlin:

[styling=Java]

[keywords=Java]
# https://kotlinlang.org/docs/reference/keyword-reference.html
primary=as as? fun in !in object typealias val var when by constructor delegate dynamic field file get init param property receiver set setparam where actual annotation companion const crossinline data expect external infix inline inner internal lateinit noinline open operator out reified sealed suspend tailrec vararg field it
# https://kotlinlang.org/docs/reference/basic-types.html
secondary=Double Float Long Int Short Byte NaN
# documentation keywords for javadoc
doccomment=
typedefs=

[lexer_properties=Java]

[settings=Java]
extension=kt
mime_type=text/x-kotlin

[build_settings]
# For this to work, the main class should be the same name as the file
compiler=kotlinc "%f"
run_cmd=kotlin "%e"

# If you usually use Kotlin as a scripting lang, use this instead
#compiler=
#run_cmd=kotlin -script "%f"

Then, in filetype_extensions.conf I added:

Kotlin=*.kt;*.kts;

[Groups]
Programming=Arduino;Clojure;CUDA;Cython;Genie;Scala;Kotlin

I assume I need to do something more? Where should I specify filetypes.kotlin?
Thanks

@elextr

This comment has been minimized.

Copy link
Member

commented Jul 16, 2018

I assume I need to do something more?

To read the docs more closely I'm afraid :)

You have the filename wrong, you havn't specified the lexer_filetype and you havn't specified the tags parser, see for example Cython

@esotericpig

This comment has been minimized.

Copy link

commented Jul 16, 2018

Okay, I got it working. File name has to be filetypes.Kotlin.conf.

~/.config/geany/filedefs/filetypes.Kotlin.conf:

[styling=C]

[keywords]
# https://kotlinlang.org/docs/reference/keyword-reference.html
primary=abstract assert break case catch class const continue default do else enum extends final finally for goto if implements import instanceof interface native new package private protected public return static strictfp super switch synchronized this throw throws transient try volatile while true false null as fun in object typealias val var when by constructor delegate dynamic field file get init param property receiver set setparam where actual annotation companion const crossinline data expect external infix inline inner internal lateinit noinline open operator out reified sealed suspend tailrec vararg field it
# https://kotlinlang.org/docs/reference/basic-types.html
secondary=Double Float Long Int Short Byte NaN Void
# documentation keywords for javadoc
doccomment=author deprecated exception param return see serial serialData serialField since throws todo version
typedefs=

[lexer_properties=C]

[settings]
lexer_filetype=C
tag_parser=C
extension=kt
mime_type=text/x-kotlin

[build-menu]
FT_00_LB=_Compile Kotlin Class
FT_00_CM=kotlinc "%f"
FT_00_WD=

EX_00_LB=_Execute Kotlin Class
EX_00_CM=kotlin "%eKt"
EX_00_WD=

EX_01_LB=Execute Kotlin _Script
EX_01_CM=kotlinc -script "%f"
EX_01_WD=
@medavox

This comment has been minimized.

Copy link

commented Sep 7, 2018

What the status of this feature? has it made its way into a release yet?

I've used Scintilla-based editors for years,
and would love support for my new favourite language in my favourite editor :)

@elextr

This comment has been minimized.

Copy link
Member

commented Sep 7, 2018

What the status of this feature? has it made its way into a release yet?

AFAIK nobody has made a pull request so its unlikely to be in any release.

and would love support for my new favourite language in my favourite editor :)

Feel free to contribute it.

@ntrel

This comment has been minimized.

Copy link
Member

commented May 31, 2019

filetypes.Kotlin.conf

@esotericpig Is this custom filetype good enough to distribute with Geany, have you or others tested it with much Kotlin code?

@diegogarromolina

This comment has been minimized.

Copy link

commented Jun 11, 2019

You can add support by yourself, I made a tutorial for this. See the video at

https://www.youtube.com/watch?v=C0eWBMTu4LU

@esotericpig

This comment has been minimized.

Copy link

commented Jun 12, 2019

filetypes.Kotlin.conf

@esotericpig Is this custom filetype good enough to distribute with Geany, have you or others tested it with much Kotlin code?

It's not perfect, but it's better than nothing I think. I use it in my projects fine.

@esotericpig

This comment has been minimized.

Copy link

commented Jun 12, 2019

You can add support by yourself, I made a tutorial for this. See the video at

https://www.youtube.com/watch?v=C0eWBMTu4LU

I mean that's great that you did this, but why wouldn't you just make a text comment here instead of a 14min video? It seems like you just want view counts on your YT video. I don't have time to watch a 14min video. Text is much faster to follow IMO.

@ntrel

This comment has been minimized.

Copy link
Member

commented Jun 13, 2019

@esotericpig Thanks, I've made a pull to add this: #2186.

I'd like to also add Groovy.

I'm happy to merge that if done as a custom filetype.

@esotericpig

This comment has been minimized.

Copy link

commented Jun 13, 2019

@esotericpig Thanks, I've made a pull to add this: #2186.

I'd like to also add Groovy.

I'm happy to merge that if done as a custom filetype.

Thank you.

I tried to make one, but it's a bit more difficult. Specifically stuff like this:

println "${string_interop}"
println '''My
  String'''
println """My
  String"""
println $/My
  String
/$
double money = 12_345_132.12

http://docs.groovy-lang.org/docs/next/html/documentation/#_groovy_language_specification

For now, I just use this in filetype_extensions.conf:

Java=*.java;*.jsp;*.groovy;*.gradle;
@ntrel

This comment has been minimized.

Copy link
Member

commented Jun 13, 2019

I tried to make one, but it's a bit more difficult

Thanks, I've made a start using the C lexer with properties set for dollar identifiers and triple quoted """strings""":
https://github.com/ntrel/geany/commits/groovy-ft

The other strings aren't supported by Scintilla's LexCPP AFAIK.

@ntrel

This comment has been minimized.

Copy link
Member

commented Jun 13, 2019

@esotericpig I've added a few things for Groovy and made a WIP pull: #2188. Please test it and advise on what the build commands should be.

@diegogarromolina

This comment has been minimized.

Copy link

commented Jun 21, 2019

You can add support by yourself, I made a tutorial for this. See the video at
https://www.youtube.com/watch?v=C0eWBMTu4LU

I mean that's great that you did this, but why wouldn't you just make a text comment here instead of a 14min video? It seems like you just want view counts on your YT video. I don't have time to watch a 14min video. Text is much faster to follow IMO.

The video is just to show that everything works and to make it look more clearly, I do not gain anything with the views of my video, it was just to help. It took me several hours to find the correct way to configure the files, 14 minutes is not much compared to what it took me

@ntrel ntrel closed this in #2186 Jul 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.