GithubHelp home page GithubHelp logo

monaco-python-lsp's Introduction

Monaco Editor LSP

该项目是基于 monaco-editor 以及 python-languageserver 开发的带有 intellisense、auto-complete 等 LSP 能力(language server protocol)的编辑器。

项目分为 client 和 server 两端:

  • client:基于 express 运行的 nodejs 服务,提供编辑器页面
  • server:基于 tornado 的 python web server,通过 pyls-jsonrpc 提供 LSP 服务

client 和 server 之间的连接方式是 websocket,通过 typefox 的 monaco-languageclient 包向 server 发送补全求情,在收到补全信息后,monaco-languageclient 会在 monaco 内展示补全内容。


本地调试开发教程:

  1. 安装 python 依赖(python 3.4+)
pip install tornado python-jsonrpc-server

| 安装依赖的时候使用python-jsonrpc-server,调用的时候用pyls_jsonrpc的包名 (出处

  1. 运行脚本
python python-server/langserver_ext.py
  1. 访问http://localhost:3001/python(默认启动端口,可自己修改),若有"Can "Upgrade" only to "WebSocket"."的文字提示,即服务其成功启动

  2. 启动 expres

安装依赖

yarn

编译 ts 代码

yarn prepare

启动 express

yarn start:ext
  1. 访问http://localhost:3002/(默认启动端口,可自己修改),能看到带语法高亮、输入 python 代码有自动补全,即运行成功

monaco-python-lsp's People

Contributors

agangdi avatar wiihame avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

monaco-python-lsp's Issues

我按照文档说明运行工程里的example出错了,执行命令 'python3 python-server/langserver_ext.py' 出错

mERROR:tornado.application:Uncaught exception GET /python (::1)
HTTPServerRequest(protocol='http', host='localhost:3004', method='GET', uri='/python', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tornado/websocket.py", line 954, in _accept_connection
    open_result = handler.open(*handler.open_args, **handler.open_kwargs)
  File "/Users/tielan/workspace/Monaco-python-lsp/python-server/langserver_ext.py", line 22, in open
    proc = process.Subprocess(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tornado/process.py", line 240, in __init__
    self.proc = subprocess.Popen(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 966, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 1842, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'pyls'
ERROR:tornado.application:Uncaught exception GET /python (::1)
HTTPServerRequest(protocol='http', host='localhost:3004', method='GET', uri='/python', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tornado/websocket.py", line 954, in _accept_connection
    open_result = handler.open(*handler.open_args, **handler.open_kwargs)
  File "/Users/tielan/workspace/Monaco-python-lsp/python-server/langserver_ext.py", line 22, in open
    proc = process.Subprocess(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tornado/process.py", line 240, in __init__
    self.proc = subprocess.Popen(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 966, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 1842, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'pyls'
^CTraceback (most recent call last):
  File "/Users/tielan/workspace/Monaco-python-lsp/python-server/langserver_ext.py", line 56, in <module>
    ioloop.IOLoop.current().start()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tornado/platform/asyncio.py", line 199, in start
    self.asyncio_loop.run_forever()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 595, in run_forever
    self._run_once()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 1845, in _run_once
    event_list = self._selector.select(timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/selectors.py", line 562, in select
    kev_list = self._selector.control(None, max_ev, timeout)
KeyboardInterrupt

image

pyls_jsonrpc 这个包不存在

rt
目前有个需求,用monaco做一个python自动补全的编辑器,目前能找到类似的,貌似只有这个库,但是本地跑不起来,
pip install pyls_jsonrpc 报错,然后我去搜这个包,不存在
所以来问下,这个问题有办法解决么?
万分感谢🙏

How to implement custom completion items through pyi scripts?

非常感觉您的项目, 正是我需要的. 然后我还有另外一项功能, 不知道该怎么实现了. 您有空帮忙看看.

我想实现内置一些class, function, variable到编辑器中, 这些都需要是动态注入的,可能经常变化. 而且没有实现,只有声明.

我能想到的是使用 .pyi 文件来做这件事. 但是不知道该怎么把我自定义的文件注入到pyls/lsp/jedi

ex: ide.pyi

class Person:
    def study(self) -> None: ...
    def play(self) -> None: ...

当我写如下代码时, 第一行的Person, 第二行的study 都能够自动提示出来

p = Person()
p.study()

安装monaco-pytho-lsp之后在执行python language_ext.py时报错No such file or directory: 'pyls'

Uncaught exception GET /python (xx.xx.xxx.x)
HTTPServerRequest(protocol='http', host='xx.xx.xxx.x:3001', method='GET', uri='/python', version='HTTP/1.1', remote_ip='xx.xx.xxx.x')
Traceback (most recent call last):
File "/usr/local/python3/lib/python3.9/site-packages/tornado/websocket.py", line 942, in _accept_connection
open_result = handler.open(*handler.open_args, **handler.open_kwargs)
File "/root/code/Monaco-python-lsp/python-server/langserver_ext.py", line 22, in open
proc = process.Subprocess(
File "/usr/local/python3/lib/python3.9/site-packages/tornado/process.py", line 240, in init
self.proc = subprocess.Popen(*args, **kwargs)
File "/usr/local/python3/lib/python3.9/subprocess.py", line 951, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/python3/lib/python3.9/subprocess.py", line 1821, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'pyls'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.