Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Docs to additional language support #66

Open
everson opened this issue May 11, 2018 · 5 comments
Open

Docs to additional language support #66

everson opened this issue May 11, 2018 · 5 comments

Comments

@everson
Copy link

everson commented May 11, 2018

Hi, I would like to add Scala support for this plugin as a pull request. I would appreciate if you could give some notes of what needs to be done in order to achieve that.

@Ruin0x11
Copy link
Owner

Ruin0x11 commented May 11, 2018

Hello. Thank you for offering to contribute.

Here are some thoughts on adding language support:

  • The IntelliJ IDEA plugin for Scala support will need to be brought in as a plugin dependency in the setPlugins call in build.gradle.kts and in plugin.xml. The case of the plugin name matters on platforms like Linux, so ensure it is properly capitalized. Here is the plugin declaration for the Scala support plugin, so add the appropriate depends entry to plugin.xml.
  • Lots of the logic that implements LSP features is based on using classes from IDEA. Basically, the thought process I use when trying to implement something is this:
    • Using Search Everywhere to search for a class in the Java/Kotlin plugin sources that sounds like it might have the needed feature.
    • Placing breakpoints in various places in the class.
    • Running the IDE in debug mode and trying to trigger the behavior.
    • Stepping through the execution, thinking about how to extract the functionality, and writing a new subclass of DocumentCommand or ProjectCommand to implement the feature for LSP.
  • Sometimes reflection or outright copying and modifying functionality might be needed to gain access to just one private variable/method, but try to avoid it as much as possible.
  • Currently the logical cases for Java and Kotlin are shared in the same Command object. A dispatcher based on language might be needed to keep the code well organized per language if the functionality is specific to the language. IDEA has language-agnostic interfaces for many common commands, so the code is shared in many places. If things differ too greatly to augment the behavior of a Command, it might be better to place it in a separate subclass of Command and dispatch to it if Scala is detected.
  • There are test cases for both Java and Kotlin wherever possible. Right now the code uses fixtures for testing, so check the examples in the projects for an example of what to add. Again, we might want to organize tests by language and create java, kotlin and scala directories.

So, to summarize:

  1. Pick some method of LSP to implement, like Find Definition.
  2. Add a branching case or new subclass of DocumentCommand or ProjectCommand for Scala support.
  3. Determine how IntelliJ obtains the information needed to execute the command.
  4. Transplant that logic into the chosen Command subclass.
  5. Start the IDE in debug mode with the Run configuration from a host copy of IDEA and the LSP client. Import a Scala project to test into the debug IDEA instance, then use the LSP client to visit a Scala file tracked by that project. The client may need to be modified to start the LSP connection if a Scala file is visited (like Emacs). If the connection succeeds the debug IDEA instance should become hidden.
  6. Check the output of idea.log and standard error in your host copy of IDEA for any errors while testing.
  7. Add test cases and appropriate fixtures. (I was working on support for tests without fixtures entirely in order to remove the dependency of external files, if it works then the testing process will become simpler.)

Hopefully this should be a good amount of info. If you have any questions, please let me know.

@everson
Copy link
Author

everson commented May 11, 2018

This is indeed a very good amount of info. I will report on progress after I have started. Thank you very much!

@everson
Copy link
Author

everson commented May 12, 2018

So,

The good news is that preliminary support for scala already exists. Just having the scala plugin installed/setup on the project and running the command lsp-intellij-enable, many features work out of the box. This is great. I am still trying to understand the benefit of having language specific branches. I would expect that intellij would take care of that.

On other news, would you be able to tell me why I getting this green background on the whole class?
screen shot 2018-05-12 at 09 34 34

If you have not seen this, it Ok, it might be a misconfiguration on my end and I was wondering if you knew before I spend more time trying to figure it out.

@Ruin0x11
Copy link
Owner

The green background indicates the thing at point is runnable with lsp-run-at-point. I guess I should add something in the README for that so it isn't confusing.

@everson
Copy link
Author

everson commented May 12, 2018

Thanks for the clarification. Would you be able to point me to where in the code that is happening? I would like to be able to turn it off. I searched for it and didn't find.

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

No branches or pull requests

2 participants