Skip to content
This repository has been archived by the owner on Feb 1, 2019. It is now read-only.

langserver.py: Update to use jsonrpc #32

Merged
merged 2 commits into from
May 12, 2018
Merged

Conversation

ksdme
Copy link
Member

@ksdme ksdme commented Mar 26, 2018

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

Closes #27

@gaocegege
Copy link
Member

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

@ksdme
Copy link
Member Author

ksdme commented Mar 27, 2018

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
@gaocegege
Copy link
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
Copy link
Member Author

ksdme commented Mar 28, 2018

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.

README.md Outdated
@@ -13,7 +13,7 @@ A visual studio code plugin working via [Language Server Protocol (LSP)](https:/

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
Member

Choose a reason for hiding this comment

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

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Noted.

README.md Outdated
@@ -24,7 +24,7 @@ export function activate(context: ExtensionContext) {
}
```

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
Member

Choose a reason for hiding this comment

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

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
Member Author

Choose a reason for hiding this comment

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

Noted.


log = logging.getLogger(__name__)
Copy link
Member

Choose a reason for hiding this comment

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

call this logger

def start(self):
self._jsonrpc_stream_reader.listen(self._endpoint.consume)

# def handle(self, _id, request):
Copy link
Member

Choose a reason for hiding this comment

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

we dont want commented out code.

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

Copy link
Member Author

Choose a reason for hiding this comment

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

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

params = {
'uri': 'file://{0}'.format(path),
'diagnostics': _diagnostics,
'diagnostics': [] if diagnostics is None else diagnostics,
Copy link
Member

Choose a reason for hiding this comment

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

this seems to be a pointless change

@@ -0,0 +1,35 @@
# Copyright 2018 Palantir Technologies, Inc.
Copy link
Member

Choose a reason for hiding this comment

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

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
Member Author

Choose a reason for hiding this comment

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

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


@given('the LangServer instance')
def step_impl(context):
context.f = tempfile.TemporaryFile()
context.langServer = LangServer(conn=TCPReadWriter(context.f, context.f))
context.file = tempfile.TemporaryFile()
Copy link
Member

Choose a reason for hiding this comment

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

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
Member Author

Choose a reason for hiding this comment

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

'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
Member Author

Choose a reason for hiding this comment

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

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

Copy link
Member

Choose a reason for hiding this comment

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

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

"""
PY3K = sys.version_info >= (3, 0)

if PY3K:
Copy link
Member

Choose a reason for hiding this comment

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

See #35

server = socketserver.TCPServer((bind_addr, port), wrapper_class)
except Exception as e:
log.fatal("Exception: %s", str(e))
exit(1)
Copy link
Member

Choose a reason for hiding this comment

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

sys.exit?

Copy link
Member Author

Choose a reason for hiding this comment

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

Noted.


from .jsonrpc import JSONRPC2Connection, ReadWriter, TCPReadWriter
from .log import log
Copy link
Member

Choose a reason for hiding this comment

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

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
Member Author

Choose a reason for hiding this comment

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

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
@@ -108,7 +108,11 @@ def start_tcp_lang_server(bind_addr, port, handler_class):
{'DELEGATE_CLASS': handler_class}
)

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

Choose a reason for hiding this comment

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

This change should be a new PR.

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

# s = LangServer(conn=ReadWriter(sys.stdin, sys.stdout))
# s.listen()
pass
stdin, stdout = _binary_stdio()
Copy link
Member

Choose a reason for hiding this comment

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

move this code out to a PR for #48

@jayvdb
Copy link
Member

jayvdb commented Apr 4, 2018

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.

@gaocegege
Copy link
Member

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

class ThreadingTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
pass
class _StreamHandlerWrapper(socketserver.StreamRequestHandler, object):
"""A wrapper class that is used to construct a custom handler class."""

Choose a reason for hiding this comment

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

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
 

self.write_response(request['id'], resp)

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

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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)

@gitmate-bot
Copy link

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.

@gitmate-bot
Copy link

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

Line is longer than allowed. (85 > 79)

Origin: LineLengthBear, Section: linelength.

@gitmate-bot
Copy link

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
Member

Choose a reason for hiding this comment

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

trailing comma

'capabilities': {},
},
'id': 1,
'jsonrpc': '2.0'
Copy link
Member

Choose a reason for hiding this comment

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

trailing comma

Copy link
Member

Choose a reason for hiding this comment

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

still not done?

wrapper_class = type(
handler_class.__name__ + 'Handler',
(_StreamHandlerWrapper,),
{'DELEGATE_CLASS': handler_class}
Copy link
Member

Choose a reason for hiding this comment

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

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

log('Fatal Exception: {}'.format(e))
sys.exit(1)
try:
log('Serving {} on ({}, {})'.format(
Copy link
Member

Choose a reason for hiding this comment

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

log isnt useful inside the try.

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

Copy link
Member Author

@ksdme ksdme May 11, 2018

Choose a reason for hiding this comment

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

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
Member

Choose a reason for hiding this comment

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

new log call, also redundant.

Copy link
Member Author

Choose a reason for hiding this comment

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

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
Member

Choose a reason for hiding this comment

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

ok.

@gitmate-bot
Copy link

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')

@gitmate-bot
Copy link

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.

@gitmate-bot
Copy link

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.

@gitmate-bot
Copy link

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

Line is longer than allowed. (82 > 79)

Origin: LineLengthBear, Section: linelength.

@gitmate-bot
Copy link

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

Line is longer than allowed. (83 > 79)

Origin: LineLengthBear, Section: linelength.

wrapper_class = type(
handler_class.__name__ + 'Handler',
(_StreamHandlerWrapper,),
{'DELEGATE_CLASS': handler_class, }
Copy link
Member

Choose a reason for hiding this comment

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

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
Member

Choose a reason for hiding this comment

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

ok.

'capabilities': {},
},
'id': 1,
'jsonrpc': '2.0'
Copy link
Member

Choose a reason for hiding this comment

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

still not done?

def start(self):
self._jsonrpc_stream_reader.listen(self._endpoint.consume)

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

Choose a reason for hiding this comment

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

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

return {
'capabilities': {
'textDocumentSync': 1
}
}

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

Choose a reason for hiding this comment

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

likewise use **params to avoid changes below

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

Closes coala#27
@jayvdb
Copy link
Member

jayvdb commented May 12, 2018

ack bd12657

@jayvdb
Copy link
Member

jayvdb commented May 12, 2018

ack de0098b

@jayvdb
Copy link
Member

jayvdb commented May 12, 2018

@gitmate-bot ff

@gitmate-bot
Copy link

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 ⚠️

@gitmate-bot gitmate-bot merged commit bd12657 into coala:master May 12, 2018
@gitmate-bot
Copy link

Automated fastforward with GitMate.io was successful! 🎉

@gaocegege
Copy link
Member

🎉

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