add additional exports to public API#2910
Conversation
|
There are probably various other utility functions from https://github.com/sublimelsp/LSP-Tinymist/blob/5173ee56e777e3587f4823ef82107905e7445cd5/plugin.py#L22-L25 If we want to export more of them in the public API, perhaps it would be useful to reconsider some of the names, because there is a bit of inconsistency. A few function names are in the form "X_to_Y" ( Also the |
|
I think for backwards compatibility with packages that import @deprecated('Use TextPosition instead')
class Point(TextPosition):
pass |
Did that but not using new name in the code as I don't want to make things more difficult for @rwols. Can be renamed internally at later time. As for other utility functions and their inconsistent names, perhaps we could group those into some classes with just static functions. But then we'd have to come up with some logical grouping and naming which will probably take some time. |
Ok. But I think you still need to update a few references to the Point class inside of the TextPosition class itself. I would also rename the parameter in And as far as I can tell, the basic purpose of this class is to make the LSP Position comparable (by defining >>> from typing import TypedDict
>>> from typing import NamedTuple
>>> class Position(TypedDict):
... line: int
... character: int
...
>>> class TextPosition(NamedTuple):
... row: int
... col: int
... @classmethod
... def from_lsp(cls, position: Position) -> TextPosition:
... return TextPosition(position['line'], position['character'])
... def to_lsp(self) -> Position:
... return {'line': self.row, 'character': self.col}
...
>>> p1 = TextPosition.from_lsp({'line': 3, 'character': 5})
>>> p2 = TextPosition.from_lsp({'line': 3, 'character': 10})
>>> p1 < p2
True
>>> p1.to_lsp()
{'line': 3, 'character': 5}
>>> p1.row
3
>>> p3 = TextPosition.from_lsp({'line': 3, 'character': 5})
>>> p1 == p3
True |
|
That wouldn't have int coercion on init but I guess we don't really need that. Also it would pass Subclassing wouldn't work correctly for NamedTuple, though, I believe. |
|
It can be a dataclass with a caveat that comparing >>> from LSP.plugin.core.protocol import Point, TextPosition
>>> a = Point(1,1)
>>> b = TextPosition(1,1)
>>> a==b
False |
position_to_offsetPointLocationPickerLspExecuteCommandfirst_selection_regionpositionregion_to_rangetext_document_identifierpoint_to_offsettext_document_position_paramsI might keep this open for a while while I'm finding more things that should be public.