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

Integrate Python Language Server to Monaco Editor (Closes #1908, #571) #1910

Open
wants to merge 43 commits into
base: master
Choose a base branch
from

Conversation

umesh-timalsina
Copy link
Contributor

@umesh-timalsina umesh-timalsina commented Sep 17, 2020

To run this PR locally. Checkout the branch:

  1. Do a docker build for the language server json file:
$ docker build -t langServers:latest -f docker/Dockerfile.langservers . 
  1. Update components.json to add the following key:
"LanguageServers" : {
  "hostName": "http://localhost:5000",
  "servers": {
    "python": {
      "command": "Microsoft.Python.LanguageServer",
      "init": {
        "interpreter": {
          "properties": {
            "InterpreterPath": "/opt/conda/bin/python3"
          },
          "code": "import func",
          "item": "functools"
        }
      },
      "workspace": "/tmp/python-models/"
    }
  }
}
  1. Spin up the container for language servers:
$ docker run -p 5000:5000 -it langServers:latest 
  1. Run npm start:
$ npm start

@umesh-timalsina umesh-timalsina marked this pull request as draft September 17, 2020 21:52
@umesh-timalsina umesh-timalsina marked this pull request as ready for review September 23, 2020 16:29
Copy link
Contributor

@brollb brollb left a comment

Choose a reason for hiding this comment

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

Nice work. I read through the code and provided some feedback. I still have to test it more thoroughly but figured I would provide my initial feedback first and then post any other comments after playing with it more.

environment.server.yml Outdated Show resolved Hide resolved
TextEditorWidget.prototype._initializeLanguageClient = function () {
this.languageClient = new DeepforgeLanguageClient(
this.editor,
`${LANGAUGE_SERVER_HOST}/${this.language}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

LANGAUGE -> LANGUAGE

config.extensions.languageServers = {
host: process.env.DEEPFORGE_LANGUAGE_SERVER_HOST,
servers: getAvailableLanguageServers(),
workspaceURIs: getWorkspaceURIs(),
Copy link
Contributor

Choose a reason for hiding this comment

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

After looking at how this is used, maybe this should be called rootURIs or rootWorkspaceURIs? When I first read it, I was concerned that all users may be sharing the same workspace (which I don't think will be an issue).

@@ -6,3 +6,4 @@ dependencies:
- matplotlib==3.2.2
- simplejson
- plotly
- python-language-server==0.25.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above.

'./lib/reconnecting-websocket.min',
], function (
vscodeWSJSONRpc,
LangaugeClient,
Copy link
Contributor

Choose a reason for hiding this comment

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

Langauge -> Language

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad on the typos. Sorry.


const SERVERS_YML = path.join(__dirname, '..', 'language-servers.yml');

function getAvailableLanguageServers () {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am a little wary about this. It seems to be assuming that any servers defined in language-servers.yml are available but since that file is checked in to git, it seems likely that this will end up with invalid language servers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. can it be solved by moving language-servers.yml to the deployment directory and using the config in production mode only?

@@ -23,6 +27,18 @@ define([
MonacoLanguages = JSON.parse(MonacoLanguages);

const AVAILABLE_KEYBINDINGS = ['default', 'vim'];
const LANGAUGE_SERVER_HOST = gmeConfig.extensions.languageServers.host || getDefaultServerURL();
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure that we should have a default hard coded here. I was imagining that, if no language server is specified in the config, it will run without any language servers enabled (rather than assuming it is running on port 5000). Maybe this is what you were referring to when we were talking earlier. If so, my bad - I didn't realize you were referring to hardcoding the port here.

Since language servers are not required for use, it should proceed without one if none are specified.

Copy link
Contributor Author

@umesh-timalsina umesh-timalsina Sep 23, 2020

Choose a reason for hiding this comment

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

Agreed will change it to not use language servers if no host name available.

@umesh-timalsina
Copy link
Contributor Author

I have changed this PR to use microsoft's python language server. This still needs some changes to the TextEditorWidget code.

Copy link
Contributor

@brollb brollb left a comment

Choose a reason for hiding this comment

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

A couple little comments. I am spinning it up now and will comment with any other issues I encounter!

@@ -5,9 +5,13 @@ The script `deploy-deepforge` is used for standard deployment of deepforge using

Additionally, this contains a file with customizations to the standard docker-compose.yml file which allows us to modify the entrypoint and install a version of tensorflow [compatible with the CPU of the deployment machine](https://github.com/deepforge-dev/deepforge/issues/1561).

The deployment is updated by first creating the custom docker compose file using [yaml-merge](https://github.com/alexlafroscia/yaml-merge):
Moreover, we also a proxy server with that spins up different language servers that we provide for
intelligent syntax
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like some odd line breaking...

The deployment is updated by first creating the custom docker compose file using [yaml-merge](https://github.com/alexlafroscia/yaml-merge):
Moreover, we also a proxy server with that spins up different language servers that we provide for
intelligent syntax
highlighting in deepforge's browser. For more information checkout the language server's docker [file](../docker/Dockerfile.langservers)
Copy link
Contributor

Choose a reason for hiding this comment

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

"in deepforge's browser" -> "in DeepForge"

environment.server.yml Outdated Show resolved Hide resolved
@@ -0,0 +1,18 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be in utils? It seems deployment specific

Copy link
Contributor

Choose a reason for hiding this comment

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

(and only used by docker files)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. This could be moved to .deployment but the problem is .deployment is in our .dockerignore. Not sure where to put this file.

@brollb
Copy link
Contributor

brollb commented Oct 2, 2020

Hmm... I am seeing some errors when trying to build the docker image:
DeepinScreenshot_xterm_20201002164821

@brollb
Copy link
Contributor

brollb commented Jan 8, 2021

Have you seen this error before while building the docker container?
DeepinScreenshot_select-area_20210108094424

@umesh-timalsina
Copy link
Contributor Author

No, I have not, but I will have a look.

@umesh-timalsina
Copy link
Contributor Author

I think the issue had to do with js-yaml safeDump function being removed from the latest release. I have fixed it. I have also deployed the branch at dev.deepforge.org. Should be good to go for testing in few minutes.

@brollb
Copy link
Contributor

brollb commented Jan 20, 2021

Nice. That fixed it for me - thanks! Now I can check out the rest of it :)

@brollb
Copy link
Contributor

brollb commented Jan 21, 2021

Overall, this looks good. A couple issues (I already mentioned them in slack but putting them here, too):

  • performance is pretty bad currently and probably won't scale. It would be good to investigate this further and make sure this is disabled for editor.deepforge.org.
  • Make sure the GitHub action is reverted so it isn't building on this branch

After ensuring it is disabled for editor.deepforge.org and the GitHub action is reverted, feel free to go ahead and merge it!

@umesh-timalsina
Copy link
Contributor Author

umesh-timalsina commented Jan 21, 2021

In verbose mode, using the ConsoleWindow, we are getting the following error message:

DeepForge Language Client: Error: The task was cancelled.
    at https://dev.deepforge.org/extlib/src/visualizers/widgets/TextEditor/lib/vscode-ws-jsonrpc.min.js:1:8642
    at https://dev.deepforge.org/extlib/src/visualizers/widgets/TextEditor/lib/vscode-ws-jsonrpc.min.js:1:8936
    at https://dev.deepforge.org/extlib/src/visualizers/widgets/TextEditor/lib/vscode-ws-jsonrpc.min.js:1:9295
    at https://dev.deepforge.org/extlib/src/visualizers/widgets/TextEditor/lib/vscode-ws-jsonrpc.min.js:8:24724
    at p (https://dev.deepforge.org/extlib/src/visualizers/widgets/TextEditor/lib/vscode-ws-jsonrpc.min.js:8:24839)
    at a (https://dev.deepforge.org/extlib/src/visualizers/widgets/TextEditor/lib/vscode-ws-jsonrpc.min.js:8:24197)

This might be at the root of performance issue as new client gets instantiated as soon as this error is encountered. The minified files have no source maps, It might be good to investigate this further.

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