-
-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Respect indentation for visually selected ":Prettier" #78
Conversation
Hi @sudavid4 , That's awesome! Thank you so much for submitting this PR! Will test it as soon as I land some fixes for |
Thanks for submitting this PR, it seems that your fix was only applied to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this moment the fix is only applied to synchronous formatting, we should also support asynchronous formatting.
fixed this, moved the code into s:Apply_Prettier_Format |
Awesome!! Will test this out tomorrow then if all is good will merge it! thank you so much |
Hi @sudavid4, Tried testing this, but i think this behaviour may not be always what we want. An example: this output with visual selection: function a () {
const a = 123; } would create this: function a() {
const a = 123;
} I think introducing something like this would make |
Please see if this is better, taking into account added (or subtracted for that matter) lines in buffer to calculate line end |
hi @sudavid4, Been thinking about it, I think this sort of API would make sense to even be included in formatting this fixture with this hypothetical command 1
2 const b
3 = 2;
4 function a() {
5 const d = (blah) => { return 3 + 5 }; return d;
6 } could then output: 1
2 const b
3 = 2;
4 function a() {
5 const d = blah => {
6 return 3 + 5;
7 };
8 return d;
9 } formatting just the selected area. I think this feature makes more sense to be implemented in prettier itself since they can better understand surrounding code and better chose spacing/formatting with all contexts involved. I am happy to contribute this feature for Any thoughts around it ? |
Saying that, will test this PR today as it is since that is not a blocker and we could get this merged. We can always revisit this workaround implementation later in favor of the prettier CLI args if they can implemented in there. |
Prettier already supports |
demo.js const b
= 2;
function a() {
const d = (blah) => { return 3 + 5 }; return d;
} command prettier demo.js --range-start 32 --range-end 84 stdout const b
= 2;
function a() {
const d = blah => {
return 3 + 5;
};
return d;
} |
@ikatyang calculating the range on |
Sorry still haven't found time to test this PR will try to do that tonight! Apologies for the delay! |
We could try to use the API mentioned by @ikatyang using vim |
Will experiment with this as soon as i get some free time |
I have been pretty busy lately but will get back in this PR next week and make sure it will get merged in some form! |
Hi @docwhat We could try to do this for 1.0 using I have been toying around with a helper for getting bytes range: " Returns [start, end] byte range
function! s:getByteRange() abort
let l:range = []
let l:start = getpos("'<")
let l:end = getpos("'>")
call add(l:range, line2byte(l:start[1]) + l:start[2] - 1)
call add(l:range, line2byte(l:end[1]) + l:end[2] - 1)
return l:range
endfunction The above works well for normal so running the visual selection on the above snippet would generate Also if that is something you would want to tackle or have interest feel free to let me know |
on
|
This is an example of implementation that made that work https://github.com/farazdagi/vim-go-ide/blob/master/bundle/pristine/vim-go/autoload/go/oracle.vim#L65 |
I'm not sure that you should be converting to bytes, since the documentation for For the visual selection, can't you just use |
Thanks for that info @docwhat, Do you know a better way on |
Fix this on branch 1.x (ec6ede9) Important notes:
Details: let g:prettier#partial_format=1 I also created 2 helper commands
|
fixes #75