FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-language-server/pyls/plugins/yapf_format.py at develop · deepnote/python-language-server · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
deepnote
/
python-language-server
Public
forked from
palantir/python-language-server
Notifications
You must be signed in to change notification settings
Fork
6
Star
3
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
python-language-server
/
pyls
/
plugins
/
yapf_format.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (45 loc) · 1.64 KB
Breadcrumbs
python-language-server
/
pyls
/
plugins
/
yapf_format.py
Copy path
File metadata and controls
56 lines (45 loc) · 1.64 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
# Copyright 2017 Palantir Technologies, Inc.
import
logging
import
os
from
yapf
.
yapflib
import
file_resources
from
yapf
.
yapflib
.
yapf_api
import
FormatCode
from
pyls
import
hookimpl
log
=
logging
.
getLogger
(
__name__
)
@
hookimpl
def
pyls_format_document
(
document
):
return
_format
(
document
)
@
hookimpl
def
pyls_format_range
(
document
,
range
):
# pylint: disable=redefined-builtin
# First we 'round' the range up/down to full lines only
range
[
'start'
][
'character'
]
=
0
range
[
'end'
][
'line'
]
+=
1
range
[
'end'
][
'character'
]
=
0
# From Yapf docs:
# lines: (list of tuples of integers) A list of tuples of lines, [start, end],
# that we want to format. The lines are 1-based indexed. It can be used by
# third-party code (e.g., IDEs) when reformatting a snippet of code rather
# than a whole file.
# Add 1 for 1-indexing vs LSP's 0-indexing
lines
=
[(
range
[
'start'
][
'line'
]
+
1
,
range
[
'end'
][
'line'
]
+
1
)]
return
_format
(
document
,
lines
=
lines
)
def
_format
(
document
,
lines
=
None
):
new_source
,
changed
=
FormatCode
(
document
.
source
,
lines
=
lines
,
filename
=
document
.
filename
,
style_config
=
file_resources
.
GetDefaultStyleForDir
(
os
.
path
.
dirname
(
document
.
path
)
)
)
if
not
changed
:
return
[]
# I'm too lazy at the moment to parse diffs into TextEdit items
# So let's just return the entire file...
return
[{
'range'
: {
'start'
: {
'line'
:
0
,
'character'
:
0
},
# End char 0 of the line after our document
'end'
: {
'line'
:
len
(
document
.
lines
),
'character'
:
0
}
},
'newText'
:
new_source
}]
Back
|
FazBrowse Home
|
New Git URL