Continue refactor.
@@ -2,21 +2,12 @@ import neovim
import os, subprocess
import json
-@neovim.plugin
-class LanguageServerClient:
-
- def __init__(self, nvim):
- self.nvim = nvim
- self.server = subprocess.Popen(
- ["/bin/bash", "/opt/rls/wrapper.sh"],
- # ["cargo", "run", "--manifest-path=/opt/rls/Cargo.toml"],
- # ['langserver-go', '-trace', '-logfile', '/tmp/langserver-go.log'],
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- universal_newlines=True)
+class RPC:
+ def __init__(self, infile, outfile):
+ self.infile = infile
+ self.outfile = outfile
- def rpc(self, method, params):
+ def call(self, method, params):
payload = {
"jsonrpc": "2.0",
"id": 0,
@@ -28,23 +19,39 @@ class LanguageServerClient:
"Content-Length: {}\r\n\r\n"
"{}".format(len(payload), payload)
)
- self.server.stdin.write(message)
- self.server.stdin.flush()
+ self.outfile.write(message)
+ self.outfile.flush()
+
+ def serve(self):
+ while True:
+ line = self.infile.readline()
+ if line:
+ print(line)
+ break
+
+@neovim.plugin
+class LanguageServerClient:
+ def __init__(self, nvim):
+ self.nvim = nvim
+ self.server = subprocess.Popen(
+ ["/bin/bash", "/opt/rls/wrapper.sh"],
+ # ["cargo", "run", "--manifest-path=/opt/rls/Cargo.toml"],
+ # ['langserver-go', '-trace', '-logfile', '/tmp/langserver-go.log'],
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ universal_newlines=True)
+ self.rpc = RPC(self.server.stdout, self.server.stdin)
@neovim.command('GetDocumentation')
def GetDocumentation(self):
- self.rpc('initialize', {
+ self.rpc.call('initialize', {
"processId": os.getpid(),
"rootPath": "/private/tmp/sample-rs",
"capabilities":{},
"trace":"verbose"
})
-
- while True:
- line = self.server.stdout.readline()
- if line:
- print(line)
- break
+ self.rpc.serve()
def test_LanguageServerClient():
client = LanguageServerClient(None)
