You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having an issue with lines being removed due to `isort`, probably related.
Test file:
importnumpyasnpfromAimportBimportC
Output if I use conform.format() (works as expected):
importCimportnumpyasnpfromAimportB
Output if I use conform.format({range = {start={1, 0}, ["end"]={4,8}}}) (whole file as range):
importC
I tracked it down to apply_format, in particular indices_in_rangehere is evaluating to false, so it does the deletion but not the insertion, shown in the lack of a second text edit for the call with a range. If I bypass that line (just saying if true for this test), it works exactly as expected.
trace for no range (conform.format()):
15:06:37[DEBUG] Running formatters on ~/test.py: { "isort" }
15:06:37[INFO] Run isort on ~/test.py
15:06:37[TRACE] Input lines: { "import numpy as np", "", "from A import B", "import C" }
15:06:37[DEBUG] Run command: { "isort", "--stdout", "--filename", "~/test.py", "-" }
15:06:38[DEBUG] isort exited with code 0
15:06:38[TRACE] Output lines: { "import C", "import numpy as np", "from A import B" }
15:06:38[TRACE] Applying formatting to ~/test.py
15:06:38[TRACE] Comparing lines { "import numpy as np", "", "from A import B", "import C" } and { "import C", "import numpy as np", "from A import B" }
15:06:38[TRACE] Diff indices { { 1, 3, 0, 0 }, { 4, 0, 2, 2 } }
15:06:38[TRACE] Applying text edits: { {
newText = "",
range = {
["end"] = {
character = 0,
line = 3
},
start = {
character = 0,
line = 0
}
}
}, {
newText = "import numpy as np\nfrom A import B",
range = {
["end"] = {
character = 0,
line = 4
},
start = {
character = 0,
line = 4
}
}
} }
15:06:38[TRACE] Done formatting ~/test.py
trace with a range (conform.format({range = {start={1, 0}, ["end"]={4,8}}})):
15:06:33[DEBUG] Running formatters on ~/test.py: { "isort" }
15:06:33[INFO] Run isort on ~/test.py
15:06:33[TRACE] Input lines: { "import numpy as np", "", "from A import B", "import C" }
15:06:33[DEBUG] Run command: { "isort", "--stdout", "--filename", "~/test.py", "-" }
15:06:33[DEBUG] isort exited with code 0
15:06:33[TRACE] Output lines: { "import C", "import numpy as np", "from A import B" }
15:06:33[TRACE] Applying formatting to ~/test.py
15:06:33[TRACE] Comparing lines { "import numpy as np", "", "from A import B", "import C" } and { "import C", "import numpy as np", "from A import B" }
15:06:33[TRACE] Diff indices { { 1, 3, 0, 0 }, { 4, 0, 2, 2 } }
15:06:33[TRACE] Applying text edits: { {
newText = "",
range = {
["end"] = {
character = 0,
line = 3
},
start = {
character = 0,
line = 0
}
}
} }
15:06:33[TRACE] Done formatting ~/test.py
This is likely not related to the other issue, so I've moved it to a new issue.
I added some docs under advanced topics that explain the range formatting a little more. As a general rule, the "aftermarket" range formatting that conform offers when a formatter doesn't support it natively is a "best effort" operation and will never be perfect. In this particular case I was able to find a small change that improves the formatting results, but just as a warning this sort of thing can still happen in the future.
Test file:
Output if I use
conform.format()
(works as expected):Output if I use
conform.format({range = {start={1, 0}, ["end"]={4,8}}})
(whole file as range):I tracked it down to
apply_format
, in particularindices_in_range
here is evaluating to false, so it does the deletion but not the insertion, shown in the lack of a second text edit for the call with a range. If I bypass that line (just sayingif true
for this test), it works exactly as expected.trace for no range (
conform.format()
):trace with a range (
conform.format({range = {start={1, 0}, ["end"]={4,8}}})
):Originally posted by @milisims in #98 (comment)
The text was updated successfully, but these errors were encountered: