Workspace
- class pygls.workspace.TextDocument(uri, source=None, version=None, language_id=None, local=True, sync_kind=TextDocumentSyncKind.Incremental, position_codec=None)
- Parameters:
- apply_change(change)
Apply a text change to a document, considering TextDocumentSyncKind
Performs either
Incremental
,Full
, or no synchronization based on both the client request and server capabilities.Incremental
versusFull
synchronizationEven if a server accepts
Incremantal
SyncKinds, clients may request aFull
SyncKind. In LSP 3.x, clients make this request by omitting both Range and RangeLength from their request. Consequently, the attributes “range” and “rangeLength” will be missing fromFull
content update client requests in the pygls Python library.- Parameters:
change (Union[TextDocumentContentChangeEvent_Type1, TextDocumentContentChangeEvent_Type2]) –
- Return type:
None
- offset_at_position(client_position)
Return the character offset pointed at by the given client_position.
- word_at_position(client_position, re_start_word=re.compile('[A-Za-z_0-9]*$'), re_end_word=re.compile('^[A-Za-z_0-9]*'))
Return the word at position.
The word is constructed in two halves, the first half is found by taking the first match of
re_start_word
on the line up untilposition.character
.The second half is found by taking
position.character
up until the last match ofre_end_word
on the line.re.findall()
is used to find the matches.- Parameters:
position – The line and character offset.
re_start_word (Pattern[str]) – The regular expression for extracting the word backward from position. The default pattern is
[A-Za-z_0-9]*$
.re_end_word (Pattern[str]) – The regular expression for extracting the word forward from position. The default pattern is
^[A-Za-z_0-9]*
.client_position (Position) –
- Returns:
The word (obtained by concatenating the two matches) at position.
- Return type:
- class pygls.workspace.Workspace(root_uri, sync_kind=TextDocumentSyncKind.Incremental, workspace_folders=None, position_encoding=PositionEncodingKind.Utf16)
- Parameters:
sync_kind (TextDocumentSyncKind) –
workspace_folders (Optional[List[WorkspaceFolder]]) –
position_encoding (Optional[Union[PositionEncodingKind, str]]) –
- get_notebook_document(*, notebook_uri=None, cell_uri=None)
Return the notebook corresponding with the given uri.
If both
notebook_uri
andcell_uri
are given,notebook_uri
takes precedence.- Parameters:
- Returns:
The requested notebook document if found,
None
otherwise.- Return type:
Optional[NotebookDocument]
- get_text_document(doc_uri)
Return a managed document if-present, else create one pointing at disk.
See https://github.com/Microsoft/language-server-protocol/issues/177
- Parameters:
doc_uri (str) –
- Return type:
- put_text_document(text_document, notebook_uri=None)
Add a text document to the workspace.
- Parameters:
text_document (TextDocumentItem) – The text document to add
notebook_uri (Optional[str]) – If set, indicates that this text document represents a cell in a notebook document