Giter Club home page Giter Club logo

Comments (4)

flother avatar flother commented on August 22, 2024

Thanks for creating an issue for this. It's always a pleasure to hear that people are using things I make.

Blake shells out to a Black process within an editor.onWillSave() callback. The Nova docs say that:

If the callback performs modifications to the editor within the callback (such as with edit()), they will be applied in such a way as to include them in the pending save operation. If a callback registered using this method takes too long to perform operations, any edits enqueued may be deferred until after the save operation, or discarded entirely. (source)

Blake does alter the document using an edit() callback, as the docs suggest, and so Blake's edits should be included in save operations. But, as you've noticed, they aren't: as well as the mismatch with Flake8 issues, the document is also marked as unsaved after Black's changes have been applied.

There's no mention of how long is "too long", but I think the process of running Black within a shell is taking too long to return, and so the edits are being deferred. I'll have to rethink how I'm running Flake8 and Black on save, perhaps try and run them synchronously one after the other, using Black's output as input to Flake8.

from blake.novaextension.

Anton-2 avatar Anton-2 commented on August 22, 2024

And thanks for creating this...

I've tried to make the black round-trip faster, by using blackd and just POST'ing a request, but this is still not fast enough.
I suspect that anything doing IO will take "too long"...

To implement a true "format before save" option, we need to have a way in nova's API to defer save until all edits are done. I've asked Panic support about this.

from blake.novaextension.

edwardloveall avatar edwardloveall commented on August 22, 2024

I don't think it's the time it takes to run black. From the Nova docs for onWillSave:

the runtime guarantees that it will allow at least 5 seconds for all extensions to perform their operations.

Black is definitely not taking that long! 😅

The problem is that onWillSave needs to return a Promise if you want it to wait:

This method may return a Promise object to denote to the runtime that changes need to be performed asynchronously.

Right now, the onWillSave callback doesn't return anything. The BlackProcess does its work in the background and when it completes without any errors, it alters the document. But by the time this has happened, onWillSave is already done since it didn't know to wait.

I've been understanding this through an extension I'm working on and I'd be happy to take a crack at making it work here. However, playing around with the code a little, I believe it will be a significant refactor of at least BlackProcess and likely to Formatter as well so I didn't want to give it a go without checking first.

from blake.novaextension.

edwardloveall avatar edwardloveall commented on August 22, 2024

I ended up making these changes in #4. Even if they don't get merged, we can at least see what it might look like.

from blake.novaextension.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.