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

Improve development experience for LSP and Debug Adapter #200

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

TheCrether
Copy link

@TheCrether TheCrether commented Dec 18, 2024

Hi Steven,

this pull requests add options to the LSP and Debug Adapter so that they can run on a socket (port 5007 and 5008 respectively). This makes it possible to start the LSP/Debug Adapter in your IDE of choice and interactively debug it there.

LSP

In order to use a LSP running on a socket in VS Code, you can use the following serverOptions when creating a new LanguageClient

serverOptions = (): Promise<vscodeLanguageClient.StreamInfo> => `{laun`
  const socket = net.connect({ port: 5007 });
  return Promise.resolve({
    writer: socket,
    reader: socket,
  });
};

Debug Adapter (launch.json)

Using the Debug Adapter through a socket is done by specifying debugServer in a launch configuration.

{
  "type": "magik",
  "name": "Socket debugging",
  "request": "attach",
  "debugServer": 5008,
  "connect": {
    "host": "localhost",
    "port": 32000,
    "path_mapping": []
  }
}

add options for using sockets for the LSP and debug adapter
add MagikLanguageClient interface for future use (LSP notifications)
@TheCrether TheCrether marked this pull request as ready for review December 18, 2024 10:11
@TheCrether TheCrether changed the title Improve development for LSP and Debug Adapter Improve development experience for LSP and Debug Adapter Dec 18, 2024
@StevenLooman
Copy link
Owner

Thank you for this PR @TheCrether. Can you elaborate why this would be needed? I.e., do you use an IDE which does not support communication through stdin/stdout?

Also, if this would be applied, the used ports should be configurable.

import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.*;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't do this. This hides the used imports and is perhaps a sign of too much "complexity" in one file.

Copy link
Author

@TheCrether TheCrether Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this happens when I commit in my Java IDE (IntelliJ), I didn't pay it much mind since it's just imports 😅. I can refactor my PRs if you want?

}

/**
* Get the {@link LanguageClient}.
*
* @return Language client.
*/
public LanguageClient getLanguageClient() {
public MagikLanguageClient getLanguageClient() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? It is not used anywhere.

Copy link
Author

@TheCrether TheCrether Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was used while I was testing custom notifications sent from the server but I left it here since it could be useful in the future and would be less of a hassle to refactor later on. I can of course remove it though

I misread this, I use this in other parts of my code which I have not created a PR for.

@TheCrether
Copy link
Author

Hi, I use the communication over sockets when I'm testing changes and debugging the LSP/debug adapter (I start the LSP in Debug mode in IntelliJ and hot reload files, it's faster to rebuild etc.)

When I'm not changing anything, I use it over stdin/stdout.

I'll make the used port configurable 👍

@StevenLooman
Copy link
Owner

StevenLooman commented Dec 19, 2024

One more thing. Do you actually own the IP to these changes, and not your employer? In The Netherlands, lots of IT-related companies claim ownership of all and any IP written in the employee-contract, on and off the job. Whether this is actually lawful is questionable, although I'm sure this depends on the country.

I don't want any hassle regarding IP in case I want to do any commercially with this project later on.

@StevenLooman
Copy link
Owner

StevenLooman commented Dec 19, 2024

Hi, I use the communication over sockets when I'm testing changes and debugging the LSP/debug adapter (I start the LSP in Debug mode in IntelliJ and hot reload files, it's faster to rebuild etc.)

When I'm not changing anything, I use it over stdin/stdout.

I'll make the used port configurable 👍

Using VSCode I can also attach to the LSP/debug adapter. The process is started with the jdwp-agent, see https://github.com/StevenLooman/magik-tools/blob/develop/magik-language-server/client-vscode/client/src/language-client.ts#L46. Isn't this usable?

@TheCrether
Copy link
Author

Hi, I use the communication over sockets when I'm testing changes and debugging the LSP/debug adapter (I start the LSP in Debug mode in IntelliJ and hot reload files, it's faster to rebuild etc.)
When I'm not changing anything, I use it over stdin/stdout.
I'll make the used port configurable 👍

Using VSCode I can also attach to the LSP/debug adapter. The process is started with the jdwp-agent, see https://github.com/StevenLooman/magik-tools/blob/develop/magik-language-server/client-vscode/client/src/language-client.ts#L46. Isn't this usable?

Thank you, I didn't know about this. I will try this tomorrow.

@TheCrether
Copy link
Author

One more thing. Do you actually own the IP to these changes, and not your employer? In The Netherlands, lots of IT-related companies claim ownership of all and any IP written in the employee-contract, on and off the job. Whether this is actually lawful is questionable, although I'm sure this depends on the country.

I don't want any hassle regarding IP in case I want to do any commercially with this project later on.

I have no direct clauses regarding ownership of IP in my employment contract, though I was allowed to work on this during work hours.

The only clause I could find, is in the collective agreement for the IT branch (Austria thing), regarding patent rights on inventions made while working for the company. So I am not sure on how to handle this since this code isn't really an invention which can be patented (or can it?).

All in all, I am not sure how to proceed with my current and future changes.

@TheCrether
Copy link
Author

Hi, I use the communication over sockets when I'm testing changes and debugging the LSP/debug adapter (I start the LSP in Debug mode in IntelliJ and hot reload files, it's faster to rebuild etc.)
When I'm not changing anything, I use it over stdin/stdout.
I'll make the used port configurable 👍

Using VSCode I can also attach to the LSP/debug adapter. The process is started with the jdwp-agent, see https://github.com/StevenLooman/magik-tools/blob/develop/magik-language-server/client-vscode/client/src/language-client.ts#L46. Isn't this usable?

Thank you, I didn't know about this. I will try this tomorrow.

So, I've thought about the change and remembered why I chose to add the socket functionality. The main reason being: building a JAR and copying it takes longer than just running the application in the IDE.

@StevenLooman
Copy link
Owner

I'm sure it does, as you can skip running the tests. You can skip running the tests from maven by adding the -DskipTests or -Dmaven.test.skip=true parameters.

I foresee several potential problems with adding the socket option, such as:

  • Will it listen on IPv4 or IPv6? How will the client of the language server know which one to use?
    • Should the user be able to specify the IP to listen on?
  • What about firewalls, or any messages from the OS that something started listening on a socket (Windows)?

@StevenLooman
Copy link
Owner

The only clause I could find, is in the collective agreement for the IT branch (Austria thing), regarding patent rights on inventions made while working for the company.

I would suggest you ask your employer about this.

So I am not sure on how to handle this since this code isn't really an invention which can be patented (or can it?).

There are software patents, so I wouldn't state parts of this project cannot be patented.

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

Successfully merging this pull request may close these issues.

2 participants