|
1 | 1 | # Copyright 2017 Palantir Technologies, Inc. |
2 | | -from distutils.version import LooseVersion |
3 | 2 | import functools |
4 | 3 | import inspect |
5 | 4 | import logging |
@@ -140,18 +139,34 @@ def format_docstring(contents): |
140 | 139 | """ |
141 | 140 | contents = contents.replace('\t', u'\u00A0' * 4) |
142 | 141 | contents = contents.replace(' ', u'\u00A0' * 2) |
143 | | - if LooseVersion(JEDI_VERSION) < LooseVersion('0.15.0'): |
144 | | - contents = contents.replace('*', '\\*') |
145 | 142 | return contents |
146 | 143 |
|
147 | 144 |
|
148 | 145 | def clip_column(column, lines, line_number): |
149 | | - # Normalise the position as per the LSP that accepts character positions > line length |
150 | | - # https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#position |
| 146 | + """ |
| 147 | + Normalise the position as per the LSP that accepts character positions > line length |
| 148 | +
|
| 149 | + https://microsoft.github.io/language-server-protocol/specification#position |
| 150 | + """ |
151 | 151 | max_column = len(lines[line_number].rstrip('\r\n')) if len(lines) > line_number else 0 |
152 | 152 | return min(column, max_column) |
153 | 153 |
|
154 | 154 |
|
| 155 | +def position_to_jedi_linecolumn(document, position): |
| 156 | + """ |
| 157 | + Convert the LSP format 'line', 'character' to Jedi's 'line', 'column' |
| 158 | +
|
| 159 | + https://microsoft.github.io/language-server-protocol/specification#position |
| 160 | + """ |
| 161 | + code_position = {} |
| 162 | + if position: |
| 163 | + code_position = {'line': position['line'] + 1, |
| 164 | + 'column': clip_column(position['character'], |
| 165 | + document.lines, |
| 166 | + position['line'])} |
| 167 | + return code_position |
| 168 | + |
| 169 | + |
155 | 170 | if os.name == 'nt': |
156 | 171 | import ctypes |
157 | 172 |
|
|
0 commit comments