FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
vscode-python/pythonFiles/runJediLanguageServer.py at main · bobwalker99/vscode-python · GitHub
bobwalker99
/
vscode-python
Public
forked from
microsoft/vscode-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
vscode-python
/
pythonFiles
/
runJediLanguageServer.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
91 lines (72 loc) · 2.92 KB
Breadcrumbs
vscode-python
/
pythonFiles
/
runJediLanguageServer.py
Copy path
File metadata and controls
91 lines (72 loc) · 2.92 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import
sys
import
os
# Add the lib path to our sys path so jedi_language_server can find its references
EXTENSION_ROOT
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
sys
.
path
.
insert
(
0
,
os
.
path
.
join
(
EXTENSION_ROOT
,
"pythonFiles"
,
"lib"
,
"python"
))
import
pygls
.
protocol
try
:
unicode
except
Exception
:
unicode
=
str
def
is_json_basic_type
(
obj
):
"""Checks if the object is an int, float, bool, or str."""
if
isinstance
(
obj
, (
int
,
float
,
bool
,
str
)):
return
True
return
sys
.
version_info
<
(
3
,)
and
isinstance
(
obj
,
unicode
)
def
handle_null_fields
(
obj
,
obj_field_name
=
None
):
"""Removes fields with a 'None' value.
The LS Client in VS Code expects optional fields that are not needed
to be omitted. Unfortunately, pygls uses 'null' in these instances.
"""
# This is a temporary workaround to address the following issues:
# https://github.com/microsoft/vscode-languageserver-node/issues/740#issuecomment-773967897
# https://github.com/pappasam/jedi-language-server/issues/60
# https://github.com/openlawlibrary/pygls/issues/145
# https://github.com/microsoft/vscode-languageserver-node/issues/740
if
is_json_basic_type
(
obj
):
return
elif
isinstance
(
obj
,
list
):
for
o
in
obj
:
handle_null_fields
(
o
,
obj_field_name
)
return
elif
isinstance
(
obj
,
dict
):
for
k
,
v
in
obj
.
items
():
handle_null_fields
(
v
,
k
)
important_attribute
=
lambda
x
:
not
x
.
startswith
(
"_"
)
and
not
callable
(
getattr
(
obj
,
x
)
)
for
attr
in
filter
(
important_attribute
,
dir
(
obj
)):
member
=
getattr
(
obj
,
attr
)
if
member
is
None
:
# This is a special condition to handle VersionedTextDocumentIdentifier object.
# See issues:
# https://github.com/pappasam/jedi-language-server/issues/61
# https://github.com/openlawlibrary/pygls/issues/146
#
# The version field should either use `0` or the value received from `client`.
# Seems like using `null` or removing this causes VS Code to ignore
# code actions.
if
(
attr
==
"version"
and
obj_field_name
==
"textDocument"
and
"uri"
in
dir
(
obj
)
):
setattr
(
obj
,
"version"
,
0
)
else
:
delattr
(
obj
,
attr
)
elif
is_json_basic_type
(
member
):
continue
else
:
handle_null_fields
(
member
,
attr
)
def
patched_without_none_fields
(
resp
):
"""Monkeypatch for `JsonRPCResponseMessage.without_none_fields` to remove `None` results."""
if
resp
.
error
is
None
:
del
resp
.
error
if
hasattr
(
resp
,
"result"
):
handle_null_fields
(
resp
.
result
)
else
:
del
resp
.
result
return
resp
pygls
.
protocol
.
JsonRPCResponseMessage
.
without_none_fields
=
patched_without_none_fields
from
jedi_language_server
.
cli
import
cli
sys
.
exit
(
cli
())
Back
|
FazBrowse Home
|
New Git URL