FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

langserver.py: Update to use jsonrpc by ksdme · Pull Request #32 · coala/coala-vs-code · GitHub

This repository was archived by the owner on Feb 1, 2019. It is now read-only.
/ coala-vs-code Public archive

langserver.py: Update to use jsonrpc - #32

Merged
gitmate-bot merged 2 commits into
coala:masterfrom
ksdme:jsonrpc-dev
May 12, 2018
Merged

langserver.py: Update to use jsonrpc#32
gitmate-bot merged 2 commits into
coala:masterfrom
ksdme:jsonrpc-dev

Conversation

ksdme commented Mar 26, 2018
edited
Loading

Copy link
Copy Markdown
Member

Updates coala-vs-code to use jsonrpc module from python-language-server (palantir/python-language-server#32).

Closes #27

Copy link
Copy Markdown
Member

Thanks for your contribution! Could you please fix the test failures?

ksdme commented Mar 27, 2018

Copy link
Copy Markdown
Member Author

I am already working on it.

ksdme added a commit to ksdme/coala-vs-code that referenced this pull request Mar 28, 2018
The jsonrpc behave tests are updated. The test has
remained unchanged.

Related to coala#27,
coala#32

Copy link
Copy Markdown
Member

Please follow the contribution guide here #31 (comment)

ksdme added a commit to ksdme/coala-vs-code that referenced this pull request Mar 28, 2018
The jsonrpc behave tests have been updated. The scope
of the test has remained unchanged.

Related to coala#27,
coala#32
ksdme added a commit to ksdme/coala-vs-code that referenced this pull request Mar 28, 2018
The behave tests have been updated to reflect
the new jsonrpc handling mechanism. The scope
of the tests remains unchanged.

Related to coala#27,
coala#32

ksdme commented Mar 28, 2018

Copy link
Copy Markdown
Member Author

I have only updated the tests as of now, I am working on improving the coverage and fix a minor logging issue during running testing.

Comment thread README.md Outdated
You'll need python version 3.5 or greater, run `pip3 install -r requirements.txt` to install the requirements, and run `python3 langserver-python.py --mode=tcp --addr=2087` to start a local languager server listening at port 2087.

Then you should update the `./vscode-client/src/extension.ts` to make client in TCP mode.
Then you should update the `./vscode-client/src/extension.ts` to make client in TCP mode.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

discard this change. create a newcomer bug about adding style linting rules for this file.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Noted.

Comment thread README.md Outdated
```

To try it in [Visual Studio Code](https://code.visualstudio.com), open ./vscode-client in VS Code and turn to debug view, launch the extension.
To try it in [Visual Studio Code](https://code.visualstudio.com), open ./vscode-client in VS Code and turn to debug view, launch the extension. If the langserver fails try disabling the GitCommitBear.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Create a newcomer issue about this, and remove it from your PR. it has nothing to do with jsonrpc.

Also a change like this should be done by adding a new line, so the origin of existing line doesnt change unnecessarily.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Noted.

Comment thread coala_langserver/diagnostic.py Outdated
import json
import logging

log = logging.getLogger(__name__)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

call this logger

Comment thread coala_langserver/langserver.py Outdated
def start(self):
self._jsonrpc_stream_reader.listen(self._endpoint.consume)

# def handle(self, _id, request):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

we dont want commented out code.

If there is extra stuff to be done, create an issue after this is merged

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

A clean up issue, I just wanted to have a reference to the previous code to cross verify.

Comment thread coala_langserver/langserver.py Outdated
params = {
'uri': 'file://{0}'.format(path),
'diagnostics': _diagnostics,
'diagnostics': [] if diagnostics is None else diagnostics,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

this seems to be a pointless change

Comment thread coala_langserver/jsonrpc/dispatchers.py Outdated
@@ -0,0 +1,35 @@
# Copyright 2018 Palantir Technologies, Inc.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I would prefer that we did not copy other code into the repository. For example, I can not easily check to see if you modified a line from the origin.

While there are some additional dependencies at https://github.com/palantir/python-language-server/blob/develop/setup.py#L34 , could we not require that it is installed, and then use the jsonrpc they provide? If that is not possible, maybe we can coordinate with @palantir to split that out into a sharable library.

This tool is still a prototype, so it can have additional install steps , and keeping the origin of source code clear.

It also means that additional tests for the jsonrpc would be contributed to https://github.com/palantir/python-language-server , so everyone benefits.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I will follow your recommendations, python-lang-server will be added as a dependency.

def step_impl(context):
context.f = tempfile.TemporaryFile()
context.langServer = LangServer(conn=TCPReadWriter(context.f, context.f))
context.file = tempfile.TemporaryFile()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

why does it need renaming from f to file? It causes all sorts of other unnecessary changes to appear in this PR, slowing down the review.

is that related to the issue that this PR is intending to solve.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

'f' didn't seem to be a semantic name. My intention was to improve readability, retaining such occurrences could indicate tolerance for those practices and could even mean encouragement.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think the re-naming is justified, do you still recommend this particular change?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Of course I do. it is not related to using jsonrpc. Create a new PR for other changes you wish to make.

Comment thread coala_langserver/langserver.py Outdated
"""
PY3K = sys.version_info >= (3, 0)

if PY3K:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

See #35

Comment thread coala_langserver/langserver.py Outdated
server = socketserver.TCPServer((bind_addr, port), wrapper_class)
except Exception as e:
log.fatal("Exception: %s", str(e))
exit(1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

sys.exit?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Noted.

import logging

from .jsonrpc import JSONRPC2Connection, ReadWriter, TCPReadWriter
from .log import log

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

removing this (and other logging enhancements) should be done as a separate PR. I've assigned #36 to you, as you've already done a lot of this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Noted.

ksdme added a commit to ksdme/coala-vs-code that referenced this pull request Apr 3, 2018
The jsonrpc behave tests have been updated. The scope
of the test has remained unchanged.

Related to coala#27,
coala#32
ksdme added a commit to ksdme/coala-vs-code that referenced this pull request Apr 3, 2018
The behave tests have been updated to reflect
the new jsonrpc handling mechanism. The scope
of the tests remains unchanged.

Related to coala#27,
coala#32
)

server = socketserver.TCPServer((bind_addr, port), wrapper_class)
try:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This change should be a new PR.

Ideally create a new issue showing why this change is needed.

Comment thread coala_langserver/langserver.py Outdated
# s = LangServer(conn=ReadWriter(sys.stdin, sys.stdout))
# s.listen()
pass
stdin, stdout = _binary_stdio()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

move this code out to a PR for #48

jayvdb commented Apr 4, 2018

Copy link
Copy Markdown
Member

As far as I can see, after removing all the unrelated features, there should only be one commit in this PR. fwiw, updating tests should be part of the atomic change of modifying the code.

Copy link
Copy Markdown
Member

@ksdme Thanks for your contribution! I think we could try to add some tests.

Comment thread coala_langserver/langserver.py Outdated
class ThreadingTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
pass
class _StreamHandlerWrapper(socketserver.StreamRequestHandler, object):
"""A wrapper class that is used to construct a custom handler class."""

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

You do not use the preferred quotation marks.

Origin: QuotesBear, Section: python.

The issue can be fixed by applying the following patch:

--- a/tmp/tmp_evza00r/coala_langserver/langserver.py
+++ b/tmp/tmp_evza00r/coala_langserver/langserver.py
@@ -14,7 +14,7 @@
 
 
 class _StreamHandlerWrapper(socketserver.StreamRequestHandler, object):
-    """A wrapper class that is used to construct a custom handler class."""
+    '""A wrapper class that is used to construct a custom handler class.""'
 
     delegate = None
 

Comment thread coala_langserver/langserver.py Outdated
self.write_response(request['id'], resp)

def serve_initialize(self, request):
#TODO: didChange

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

E265 block comment should start with '# '

Origin: PycodestyleBear (E265), Section: autopep8.

from pyls.jsonrpc.endpoint import Endpoint
from pyls.jsonrpc.dispatchers import MethodDispatcher
from pyls.jsonrpc.streams import JsonRpcStreamReader
from pyls.jsonrpc.streams import JsonRpcStreamWriter

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

You do not use the preferred quotation marks.

Origin: QuotesBear, Section: python.

The issue can be fixed by applying the following patch:

--- a/tmp/tmp7wx9j6yx/coala_langserver/langserver.py
+++ b/tmp/tmp7wx9j6yx/coala_langserver/langserver.py
@@ -111,7 +111,7 @@
     try:
         server = socketserver.TCPServer((bind_addr, port), wrapper_class)
     except Exception as e:
-        log("Fatal Exception: {}".format(e))
+        log('Fatal Exception: {}'.format(e))
         sys.exit(1)
     try:
         log('Serving %s on (%s, %s)', handler_class.__name__, bind_addr, port)

Copy link
Copy Markdown

Comment on f253090.

Shortlog of the HEAD commit contains 60 character(s). This is 10 character(s) longer than the limit (60 > 50).

Origin: GitCommitBear, Section: commit.

Copy link
Copy Markdown

Comment on 45df0f8, file coala_langserver/langserver.py, line 126.

Line is longer than allowed. (85 > 79)

Origin: LineLengthBear, Section: linelength.

jayvdb changed the title Updated to use jsonrpc langserver.py: Update to use jsonrpc May 11, 2018
Increases the codecov target to 95%.

Related to coala#27

Copy link
Copy Markdown

Comment on de0098b, file tests/server.features/steps/jsonrpc_steps.py, line 63.

The code does not comply to PEP8.

Origin: PEP8Bear, Section: autopep8.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpc942a8vq/tests/server.features/steps/jsonrpc_steps.py
+++ b/tmp/tmpc942a8vq/tests/server.features/steps/jsonrpc_steps.py
@@ -60,7 +60,8 @@
 @given('the JSONRPC2Connection instance')
 def step_impl(context):
     context.f = tempfile.TemporaryFile()
-    context.jsonConn = JSONRPC2Connection(conn=TCPReadWriter(context.f, context.f))
+    context.jsonConn = JSONRPC2Connection(
+        conn=TCPReadWriter(context.f, context.f))
 
 
 @when('I write a request to the JSONRPC2Connection with id')

Copy link
Copy Markdown

Comment on de0098b, file tests/server.features/steps/jsonrpc_steps.py, line 10.

E501 line too long (82 > 79 characters)

Origin: PycodestyleBear (E501), Section: autopep8.

Copy link
Copy Markdown

Comment on de0098b, file tests/server.features/steps/jsonrpc_steps.py, line 63.

E501 line too long (83 > 79 characters)

Origin: PycodestyleBear (E501), Section: autopep8.

Copy link
Copy Markdown

Comment on de0098b, file tests/server.features/steps/jsonrpc_steps.py, line 10.

Line is longer than allowed. (82 > 79)

Origin: LineLengthBear, Section: linelength.

Copy link
Copy Markdown

Comment on de0098b, file tests/server.features/steps/jsonrpc_steps.py, line 63.

Line is longer than allowed. (83 > 79)

Origin: LineLengthBear, Section: linelength.

'capabilities': {},
},
'id': 1,
'jsonrpc': '2.0'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

trailing comma

'capabilities': {},
},
'id': 1,
'jsonrpc': '2.0'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

trailing comma

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

still not done?

Comment thread coala_langserver/langserver.py Outdated
wrapper_class = type(
handler_class.__name__ + 'Handler',
(_StreamHandlerWrapper,),
{'DELEGATE_CLASS': handler_class}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

trailing comma ; not likely to be needed any time soon, but likely doesnt hurt

Comment thread coala_langserver/langserver.py Outdated
log('Fatal Exception: {}'.format(e))
sys.exit(1)
try:
log('Serving {} on ({}, {})'.format(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

log isnt useful inside the try.

but, it is a new log call, and redundant due to existing Accepting TCP connections .. log

ksdme May 11, 2018
edited
Loading

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I have to retain this log compared to the other one because the tests watch this log call to trigger sending requests.


@enforce_signature
def start_io_lang_server(handler_class: LangServer, rstream, wstream):
log('Starting {} IO language server'.format(handler_class.__name__))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

new log call, also redundant.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

For the reasons mentioned in the previous change request and maintaining uniformity I think I'll have to retain this log and remove the other redundant log call.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

ok.

Copy link
Copy Markdown

Comment on de0098b, file tests/server.features/steps/jsonrpc_steps.py, line 63.

The code does not comply to PEP8.

Origin: PEP8Bear, Section: autopep8.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpc942a8vq/tests/server.features/steps/jsonrpc_steps.py
+++ b/tmp/tmpc942a8vq/tests/server.features/steps/jsonrpc_steps.py
@@ -60,7 +60,8 @@
 @given('the JSONRPC2Connection instance')
 def step_impl(context):
     context.f = tempfile.TemporaryFile()
-    context.jsonConn = JSONRPC2Connection(conn=TCPReadWriter(context.f, context.f))
+    context.jsonConn = JSONRPC2Connection(
+        conn=TCPReadWriter(context.f, context.f))
 
 
 @when('I write a request to the JSONRPC2Connection with id')

Copy link
Copy Markdown

Comment on de0098b, file tests/server.features/steps/jsonrpc_steps.py, line 10.

E501 line too long (82 > 79 characters)

Origin: PycodestyleBear (E501), Section: autopep8.

Copy link
Copy Markdown

Comment on de0098b, file tests/server.features/steps/jsonrpc_steps.py, line 63.

E501 line too long (83 > 79 characters)

Origin: PycodestyleBear (E501), Section: autopep8.

Copy link
Copy Markdown

Comment on de0098b, file tests/server.features/steps/jsonrpc_steps.py, line 10.

Line is longer than allowed. (82 > 79)

Origin: LineLengthBear, Section: linelength.

Copy link
Copy Markdown

Comment on de0098b, file tests/server.features/steps/jsonrpc_steps.py, line 63.

Line is longer than allowed. (83 > 79)

Origin: LineLengthBear, Section: linelength.

Comment thread coala_langserver/langserver.py Outdated
wrapper_class = type(
handler_class.__name__ + 'Handler',
(_StreamHandlerWrapper,),
{'DELEGATE_CLASS': handler_class, }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

no, a trailing comma is for allowing new additions without modifications to exiting lines. hence this , is not a trailing comma.

{'DELEGATE_CLASS': handler_class},


@enforce_signature
def start_io_lang_server(handler_class: LangServer, rstream, wstream):
log('Starting {} IO language server'.format(handler_class.__name__))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

ok.

'capabilities': {},
},
'id': 1,
'jsonrpc': '2.0'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

still not done?

Comment thread coala_langserver/langserver.py Outdated
def start(self):
self._jsonrpc_stream_reader.listen(self._endpoint.consume)

def m_initialize(self, rootUri=None, rootPath=None, **kargs):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

def m_initialize(self, **params)

then nothing below needs to be modified, except removal of params = request['params']

sorry I didnt notice this earlier.

this helps show the similarities of the two jsonrpc's , making differences more clear

Comment thread coala_langserver/langserver.py Outdated
}

def serve_did_save(self, request):
def m_text_document__did_save(self, textDocument=None, **kargs):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

likewise use **params to avoid changes below

This updates the project to use jsonrpc
module from python-language-server.

Closes coala#27

jayvdb commented May 12, 2018

Copy link
Copy Markdown
Member

ack bd12657

jayvdb commented May 12, 2018

Copy link
Copy Markdown
Member

ack de0098b

jayvdb commented May 12, 2018

Copy link
Copy Markdown
Member

@gitmate-bot ff

Copy link
Copy Markdown

Hey! I'm GitMate.io! This pull request is being fastforwarded automatically. Please DO NOT push while fastforward is in progress or your changes would be lost permanently ⚠️

Copy link
Copy Markdown

Automated fastforward with GitMate.io was successful! 🎉

Copy link
Copy Markdown
Member

🎉

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL