-
Notifications
You must be signed in to change notification settings - Fork 298
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1540 +/- ##
==========================================
+ Coverage 35.76% 35.85% +0.08%
==========================================
Files 278 279 +1
Lines 10767 10800 +33
Branches 1350 1350
==========================================
+ Hits 3851 3872 +21
- Misses 6732 6744 +12
Partials 184 184
Continue to review full report at Codecov.
|
Seems like a serious endeavor, good luck! |
@bryphe might be getting carried away but thought it would be cool to use a small Icon of One issue that making plugin(s) has raised is that by using react from Oni as a dependency you cant use JSX, styling with |
} | ||
} | ||
|
||
// TODO check for prettierrc and use that if present |
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.
👍
// TODO check for prettierrc and use that if present | ||
|
||
Oni.editors.activeEditor.onBufferSaved.subscribe(async buffer => { | ||
if (config.formatOnSave && config.enabled) { |
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.
Do we need to check the buffer types here? Or is it gated somewhere else? Just wondering how its kept from running on files that might not be applicable
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.
That's definitely a concern so need to do that as you point out 👍 , just stalled on this trying to figure out how to use the cursor offset digit prettier gives us to generate a line and column number as the function does not return a line and column number which is what oni expects just a single number I assume is the index where the cursor was
}) | ||
|
||
async function applyPrettier(buffer = currentBuffer) { | ||
const arrayOfLines = await currentBuffer.getLines() |
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.
Awesome, this looks nice!
more work on cursor positioning add success and error status icons
add allowedFiletypes option to config
@bryphe I've completely stalled on this as I got the actual formatting functionality working with an associated status bar item which you can click to format and also shows success and error indicators shortly after the initial suggestion on gitter but I'm stuck trying to get the cursor to return to the exact position it was left at as prettier has a The method returns just a number which is the offset in the bufferString, converting that to and from oni's line and column has been quite tricky and whilst atm its seems to return to the right place about 60% of the time I wonder how much of a blocker to integrating this you think that will be, it wasn't part of the initial plan but I got ambitious/greedy once I read the docs on that method. |
@Akin909 Will this plugin be enabled by default? |
@TalAmuyal any chance I could pick your brain re how to use the plugin testing strategy you employed for the |
Thanks @Akin909, we need to provide some instructions on the wiki so that I and others can check it out when it get's released to the stable channel! |
Will write up some documentation for it once it's closer to being releasable, still need to try and add some tests for it 😟 and take one last stab at returning the cursor to the right position post formatting. |
You're doing a great job @Akin909! Thanks! |
💯 to that! Thanks @Akin909 for all you're contributing 😄 |
👍 , it should be off-by-default for now. It might even make sense to have it as a separate plugin at some point (once we have a plugin-install-story). |
There's a 'Vim' way to do this. We even send up this 'byte offset' in as part of our event context: oni/vim/core/oni-core-interop/plugin/init.vim Line 176 in e47434d
It also has an inverse |
add new [wip] ci test
make convertCursorPos zero base to march getCursorPos
@bryphe I dug into the highlighting issue a bit and noted a few things.
I'm noting these issues here but ideally feel like they should be tracked and resolved relating to #1838 rather than here PS: Added some CITests (for the new buffer methods and the plugin itself) |
move failing windows test to bottom to see if only that test fails
@CrossR @bryphe if either of you get a moment I'd really appreciate it if you could try running this branch locally, you will need to enable the plugin via the config option. "oni.plugins.prettier": {
enabled: true,
} If you open a |
Hey @Akin909, I've given it a try and I haven't noticed any errors yet, but I also haven't noticed it changing the code as I'd expect. Just to check I'm not missing something:
But after that point, I don't see anything change in the code, at least the semi-colon remains and what not. Is there anything I'm missing/could do to help? One odd thing I did notice was that it seemed to run repeatedly for me. That is, I saved, it ran on save, at the end of the updating, it then called Oh, and if I debug I can see the code has been prettified, its just not being set for some reason. Its possible a line ending issue since
Which I assume should be 3 lines? EDIT: Looks like its running repeatedly since the |
@CrossR thanks soo much for testing that out and for the detailed feedback that really helps 👍. I'm essentially using 0, But it does point out an assumption I made which is that prettier would return the code with platform specific newlines but actually it seems like it might always return a |
@CrossR 💯 re the syntax highlighting tbh I don't know enough about how it's applied to explain why it gets messed up somehow calling Seems a buffer update event is being triggered but I think the current strategy only tries to re-highlight conservatively 🤷♂️ not sure |
Thought it was a known issue, so at least it can be sorted in a different PR. Slight tangent, but is it possible for us (ie not @bryphe) to restart tests on AppVeyor? On Travis I see a run-build button when I'm logged in with my GitHub account, but this isn't the case for AppVeyor, which would be useful when you get errors like you have with something seemingly entirely unrelated. |
slightly excessive for now but a foundation for further tweaks in the ongoing development of this plugin
switch to function keyword to ensure applyprettier is hoisted so callback can reference it
@CrossR thanks 👍, re the AppVeyor test nope I don't get the option to re-run things would actually be really helpful (tbh I didnt have an account, I just created one and had a look but no option to rerun tests appeared) |
@bryphe not sure why the last check is failing but this is done now and shouldn't have anymore syntax hiccups (tested locally). |
Awesome! Looks like the build is good now too 👍
Ah interesting, I thought it would be like Travis - was hoping at least collaborators would be able to restart the build! It does seem like I can give permissions - but the annoying thing is its not connected with github for that. @CrossR , I had your e-mail address from the OpenCollective, so I added you - but @Akin909 , I didn't have yours handy - would you mind sending it to me on twitter/discord? I'll add you as well 👍 It would be awesome if you didn't need me to restart it, I feel bad being the bottleneck 😄 Change looks good to me, glad you got the CiTest working @Akin909 ! Thanks for your work on this! |
@bryphe @Akin909 Amazing!! I'd like to try it, is there documentation on how to setup and how it works somewhere? |
As discussed on Gitter, this is a plugin to provide
prettier
's autoformat capabilities to Oni.Todo
Status bar item
with prettier logo- stretch goals: show cross if formatting failed- At present cannot include images ?webpack setup?Check for prettierrc and give that priority if present
Setup user config for prettier, should match the prettier config opts settings
Fix cursor positioning on format
Save buffer following format otherwise buffer saves autoformats aka buffer is continuously in modified state.
Tests using @TalAmuyal's plugin testing example for Markdown preview