deepnote-python-lsp-server 0.0.0__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. deepnote_python_lsp_server-0.0.0.dist-info/METADATA +263 -0
  2. deepnote_python_lsp_server-0.0.0.dist-info/RECORD +43 -0
  3. deepnote_python_lsp_server-0.0.0.dist-info/WHEEL +6 -0
  4. deepnote_python_lsp_server-0.0.0.dist-info/entry_points.txt +24 -0
  5. deepnote_python_lsp_server-0.0.0.dist-info/licenses/LICENSE +22 -0
  6. deepnote_python_lsp_server-0.0.0.dist-info/top_level.txt +1 -0
  7. pylsp/__init__.py +33 -0
  8. pylsp/__main__.py +132 -0
  9. pylsp/_utils.py +325 -0
  10. pylsp/config/__init__.py +2 -0
  11. pylsp/config/config.py +202 -0
  12. pylsp/config/flake8_conf.py +64 -0
  13. pylsp/config/pycodestyle_conf.py +34 -0
  14. pylsp/config/source.py +88 -0
  15. pylsp/hookspecs.py +140 -0
  16. pylsp/lsp.py +115 -0
  17. pylsp/plugins/__init__.py +2 -0
  18. pylsp/plugins/_resolvers.py +132 -0
  19. pylsp/plugins/_rope_task_handle.py +106 -0
  20. pylsp/plugins/autopep8_format.py +95 -0
  21. pylsp/plugins/definition.py +84 -0
  22. pylsp/plugins/flake8_lint.py +243 -0
  23. pylsp/plugins/folding.py +210 -0
  24. pylsp/plugins/highlight.py +36 -0
  25. pylsp/plugins/hover.py +57 -0
  26. pylsp/plugins/jedi_completion.py +318 -0
  27. pylsp/plugins/jedi_rename.py +56 -0
  28. pylsp/plugins/mccabe_lint.py +56 -0
  29. pylsp/plugins/preload_imports.py +38 -0
  30. pylsp/plugins/pycodestyle_lint.py +113 -0
  31. pylsp/plugins/pydocstyle_lint.py +127 -0
  32. pylsp/plugins/pyflakes_lint.py +97 -0
  33. pylsp/plugins/pylint_lint.py +367 -0
  34. pylsp/plugins/references.py +33 -0
  35. pylsp/plugins/rope_autoimport.py +407 -0
  36. pylsp/plugins/rope_completion.py +161 -0
  37. pylsp/plugins/signature.py +81 -0
  38. pylsp/plugins/symbols.py +214 -0
  39. pylsp/plugins/yapf_format.py +199 -0
  40. pylsp/python_lsp.py +921 -0
  41. pylsp/text_edit.py +97 -0
  42. pylsp/uris.py +139 -0
  43. pylsp/workspace.py +730 -0
pylsp/text_edit.py ADDED
@@ -0,0 +1,97 @@
1
+ # Copyright 2017-2020 Palantir Technologies, Inc.
2
+ # Copyright 2021- Python Language Server Contributors.
3
+
4
+
5
+ def get_well_formatted_range(lsp_range):
6
+ start = lsp_range["start"]
7
+ end = lsp_range["end"]
8
+
9
+ if start["line"] > end["line"] or (
10
+ start["line"] == end["line"] and start["character"] > end["character"]
11
+ ):
12
+ return {"start": end, "end": start}
13
+
14
+ return lsp_range
15
+
16
+
17
+ def get_well_formatted_edit(text_edit):
18
+ lsp_range = get_well_formatted_range(text_edit["range"])
19
+ if lsp_range != text_edit["range"]:
20
+ return {"newText": text_edit["newText"], "range": lsp_range}
21
+
22
+ return text_edit
23
+
24
+
25
+ def compare_text_edits(a, b):
26
+ diff = a["range"]["start"]["line"] - b["range"]["start"]["line"]
27
+ if diff == 0:
28
+ return a["range"]["start"]["character"] - b["range"]["start"]["character"]
29
+
30
+ return diff
31
+
32
+
33
+ def merge_sort_text_edits(text_edits):
34
+ if len(text_edits) <= 1:
35
+ return text_edits
36
+
37
+ p = len(text_edits) // 2
38
+ left = text_edits[:p]
39
+ right = text_edits[p:]
40
+
41
+ merge_sort_text_edits(left)
42
+ merge_sort_text_edits(right)
43
+
44
+ left_idx = 0
45
+ right_idx = 0
46
+ i = 0
47
+ while left_idx < len(left) and right_idx < len(right):
48
+ ret = compare_text_edits(left[left_idx], right[right_idx])
49
+ if ret <= 0:
50
+ # smaller_equal -> take left to preserve order
51
+ text_edits[i] = left[left_idx]
52
+ i += 1
53
+ left_idx += 1
54
+ else:
55
+ # greater -> take right
56
+ text_edits[i] = right[right_idx]
57
+ i += 1
58
+ right_idx += 1
59
+ while left_idx < len(left):
60
+ text_edits[i] = left[left_idx]
61
+ i += 1
62
+ left_idx += 1
63
+ while right_idx < len(right):
64
+ text_edits[i] = right[right_idx]
65
+ i += 1
66
+ right_idx += 1
67
+ return text_edits
68
+
69
+
70
+ class OverLappingTextEditException(Exception):
71
+ """
72
+ Text edits are expected to be sorted
73
+ and compressed instead of overlapping.
74
+ This error is raised when two edits
75
+ are overlapping.
76
+ """
77
+
78
+
79
+ def apply_text_edits(doc, text_edits):
80
+ text = doc.source
81
+ sorted_edits = merge_sort_text_edits(list(map(get_well_formatted_edit, text_edits)))
82
+ last_modified_offset = 0
83
+ spans = []
84
+ for e in sorted_edits:
85
+ start_offset = doc.offset_at_position(e["range"]["start"])
86
+ if start_offset < last_modified_offset:
87
+ raise OverLappingTextEditException("overlapping edit")
88
+
89
+ if start_offset > last_modified_offset:
90
+ spans.append(text[last_modified_offset:start_offset])
91
+
92
+ if len(e["newText"]):
93
+ spans.append(e["newText"])
94
+ last_modified_offset = doc.offset_at_position(e["range"]["end"])
95
+
96
+ spans.append(text[last_modified_offset:])
97
+ return "".join(spans)
pylsp/uris.py ADDED
@@ -0,0 +1,139 @@
1
+ # Copyright 2017-2020 Palantir Technologies, Inc.
2
+ # Copyright 2021- Python Language Server Contributors.
3
+
4
+ """A collection of URI utilities with logic built on the VSCode URI library.
5
+
6
+ https://github.com/Microsoft/vscode-uri/blob/e59cab84f5df6265aed18ae5f43552d3eef13bb9/lib/index.ts
7
+ """
8
+
9
+ import re
10
+ from urllib import parse
11
+
12
+ from pylsp import IS_WIN
13
+
14
+ RE_DRIVE_LETTER_PATH = re.compile(r"^\/[a-zA-Z]:")
15
+
16
+
17
+ def urlparse(uri):
18
+ """Parse and decode the parts of a URI."""
19
+ scheme, netloc, path, params, query, fragment = parse.urlparse(uri)
20
+ return (
21
+ parse.unquote(scheme),
22
+ parse.unquote(netloc),
23
+ parse.unquote(path),
24
+ parse.unquote(params),
25
+ parse.unquote(query),
26
+ parse.unquote(fragment),
27
+ )
28
+
29
+
30
+ def urlunparse(parts):
31
+ """Unparse and encode parts of a URI."""
32
+ scheme, netloc, path, params, query, fragment = parts
33
+
34
+ # Avoid encoding the windows drive letter colon
35
+ if RE_DRIVE_LETTER_PATH.match(path):
36
+ quoted_path = path[:3] + parse.quote(path[3:])
37
+ else:
38
+ quoted_path = parse.quote(path)
39
+
40
+ return parse.urlunparse(
41
+ (
42
+ parse.quote(scheme),
43
+ parse.quote(netloc),
44
+ quoted_path,
45
+ parse.quote(params),
46
+ parse.quote(query),
47
+ parse.quote(fragment),
48
+ )
49
+ )
50
+
51
+
52
+ def to_fs_path(uri):
53
+ """Returns the filesystem path of the given URI.
54
+
55
+ Will handle UNC paths and normalize windows drive letters to lower-case. Also
56
+ uses the platform specific path separator. Will *not* validate the path for
57
+ invalid characters and semantics. Will *not* look at the scheme of this URI.
58
+ """
59
+ # scheme://netloc/path;parameters?query#fragment
60
+ scheme, netloc, path, _params, _query, _fragment = urlparse(uri)
61
+
62
+ if netloc and path and scheme == "file":
63
+ # unc path: file://shares/c$/far/boo
64
+ value = "//{}{}".format(netloc, path)
65
+
66
+ elif RE_DRIVE_LETTER_PATH.match(path):
67
+ # windows drive letter: file:///C:/far/boo
68
+ value = path[1].lower() + path[2:]
69
+
70
+ else:
71
+ # Other path
72
+ value = path
73
+
74
+ if IS_WIN:
75
+ value = value.replace("/", "\\")
76
+
77
+ return value
78
+
79
+
80
+ def from_fs_path(path):
81
+ """Returns a URI for the given filesystem path."""
82
+ scheme = "file"
83
+ params, query, fragment = "", "", ""
84
+ path, netloc = _normalize_win_path(path)
85
+ return urlunparse((scheme, netloc, path, params, query, fragment))
86
+
87
+
88
+ def uri_with(
89
+ uri, scheme=None, netloc=None, path=None, params=None, query=None, fragment=None
90
+ ):
91
+ """Return a URI with the given part(s) replaced.
92
+
93
+ Parts are decoded / encoded.
94
+ """
95
+ old_scheme, old_netloc, old_path, old_params, old_query, old_fragment = urlparse(
96
+ uri
97
+ )
98
+ path, _netloc = _normalize_win_path(path)
99
+ return urlunparse(
100
+ (
101
+ scheme or old_scheme,
102
+ netloc or old_netloc,
103
+ path or old_path,
104
+ params or old_params,
105
+ query or old_query,
106
+ fragment or old_fragment,
107
+ )
108
+ )
109
+
110
+
111
+ def _normalize_win_path(path):
112
+ netloc = ""
113
+
114
+ # normalize to fwd-slashes on windows,
115
+ # on other systems bwd-slaches are valid
116
+ # filename character, eg /f\oo/ba\r.txt
117
+ if IS_WIN:
118
+ path = path.replace("\\", "/")
119
+
120
+ # check for authority as used in UNC shares
121
+ # or use the path as given
122
+ if path[:2] == "//":
123
+ idx = path.index("/", 2)
124
+ if idx == -1:
125
+ netloc = path[2:]
126
+ else:
127
+ netloc = path[2:idx]
128
+ path = path[idx:]
129
+
130
+ # Ensure that path starts with a slash
131
+ # or that it is at least a slash
132
+ if not path.startswith("/"):
133
+ path = "/" + path
134
+
135
+ # Normalize drive paths to lower case
136
+ if RE_DRIVE_LETTER_PATH.match(path):
137
+ path = path[0] + path[1].lower() + path[2:]
138
+
139
+ return path, netloc