openlawlibrary / pygls

A pythonic generic language server
https://pygls.readthedocs.io/en/latest/
Apache License 2.0
568 stars 103 forks source link

Reading full context #343

Open djtech-dev opened 1 year ago

djtech-dev commented 1 year ago

Hi, I'm working on an LSP Server and right now I'm implementing the Completations.

I wanted to ask how to read the full context (like the actual line of code or the lines of code previous to the current buffer) from CompletionParams.

Thanks.

tombh commented 1 year ago

Hey, welcome. So I assume by saying "full", you mean that the existing completionContext isn't enough? It certainly doesn't contain the lines of code previous to the location at which the cursor triggered the completion.

So getting more context about the current buffer is actually something that's shown in our quickstart in the README. We have things like this:

document = server.workspace.get_document(params.text_document.uri)
# `params.position` is the current cursor position
current_line = document.lines[params.position.line].strip()

Does that give you some inspiration for exploring getting more context?