Compare commits
No commits in common. "d3e015a51a60ec0656f4285481d02a28012b2fdb" and "3bd200808be960c7a3cd4c922967f79aa67c9bf8" have entirely different histories.
d3e015a51a
...
3bd200808b
20
README.md
20
README.md
|
@ -6,21 +6,7 @@ Minimal Python language server, based on [Jedi][jedi] and [pygls][pygls].
|
|||
[jedi]: https://jedi.readthedocs.io/en/latest/index.html
|
||||
[pygls]: https://pygls.readthedocs.io/en/latest/index.html
|
||||
|
||||
WIP! ⚠ 👷🚧
|
||||
|
||||
Supported features:
|
||||
|
||||
| LSP method | Description |
|
||||
|---------------------------|---------------|
|
||||
| `textDocument/completion` | Completions |
|
||||
| `textDocument/hover` | Documentation |
|
||||
|
||||
|
||||
|
||||
Install
|
||||
-------
|
||||
|
||||
TODO
|
||||
WIP.
|
||||
|
||||
|
||||
|
||||
|
@ -48,7 +34,3 @@ HA!
|
|||
Take the string “Is this a Star Wars reference?” Language Server, compress it to
|
||||
`ITASWRLS` and expand it back to Italian Swirls. Italian dishes are made of few
|
||||
elements that work well together. Enough questions!
|
||||
|
||||
### License
|
||||
|
||||
GPLv3.
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
import logging
|
||||
|
||||
from jedi import Script
|
||||
from pygls.lsp.methods import COMPLETION, HOVER, INITIALIZE
|
||||
from pygls.lsp.methods import COMPLETION, INITIALIZE
|
||||
from pygls.lsp.types import (CompletionItem, CompletionItemKind,
|
||||
CompletionList, CompletionOptions,
|
||||
CompletionParams, Hover, InsertTextFormat,
|
||||
Position, TextDocumentPositionParams)
|
||||
CompletionParams, InsertTextFormat, Position)
|
||||
from pygls.server import LanguageServer
|
||||
from pygls.workspace import Document
|
||||
|
||||
|
@ -51,16 +50,14 @@ async def do_initialize(*args):
|
|||
|
||||
|
||||
@LS.feature(COMPLETION, CompletionOptions(trigger_characters=["."]))
|
||||
async def do_completion(
|
||||
server: LanguageServer,
|
||||
params: CompletionParams,
|
||||
) -> CompletionList:
|
||||
async def do_completion(server: LanguageServer, params: CompletionParams):
|
||||
"""Return completion items."""
|
||||
document_uri = params.text_document.uri
|
||||
document = server.workspace.get_document(document_uri)
|
||||
script = get_jedi_script(document)
|
||||
jedi_position = get_jedi_position(params.position)
|
||||
jedi_completions = script.complete(*jedi_position)
|
||||
LOG.debug(f"Completions: {jedi_completions}")
|
||||
|
||||
completion_items = []
|
||||
for jedi_completion in jedi_completions:
|
||||
|
@ -81,35 +78,5 @@ async def do_completion(
|
|||
)
|
||||
|
||||
|
||||
@LS.feature(HOVER)
|
||||
async def do_hover(
|
||||
server: LanguageServer,
|
||||
params: TextDocumentPositionParams,
|
||||
) -> Hover:
|
||||
"""Provide "hover", which is documentation of a symbol.
|
||||
|
||||
Jedi provides a list of names with information, usually only one. We handle
|
||||
them all and concatenate them, separated by a horizontal line. For
|
||||
simplicity, the text is mostly provided untouched.
|
||||
"""
|
||||
document_uri = params.text_document.uri
|
||||
document = server.workspace.get_document(document_uri)
|
||||
script = get_jedi_script(document)
|
||||
jedi_position = get_jedi_position(params.position)
|
||||
jedi_help_names = script.help(*jedi_position)
|
||||
|
||||
help_texts = []
|
||||
for jedi_name in jedi_help_names:
|
||||
text = f"`{jedi_name.full_name}`"
|
||||
if sigs := jedi_name.get_signatures():
|
||||
text += "\n" + "\n".join(f"`{sig.to_string()}`" for sig in sigs)
|
||||
if docstring := jedi_name.docstring(raw=True):
|
||||
text += "\n\n" + docstring
|
||||
help_texts.append(text)
|
||||
|
||||
hover_text = "\n\n---\n\n".join(help_texts)
|
||||
return Hover(contents=hover_text) # TODO range
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
LS.start_io()
|
||||
|
|
Loading…
Reference in a new issue