madskristensen / JavaScriptPrettier

A Visual Studio extension
Other
157 stars 30 forks source link

Only update lines that have changed #26

Open neoGeneva opened 5 years ago

neoGeneva commented 5 years ago

At the moment if there's a single change made by prettier in a file then the whole files text is replaced, that means every line is shown as changed in VS, and for large files the syntax highlighting takes a little while to re-parse the file which can be a little jarring.

It'd be better if only the changed lines were updated, if possible.

tommck commented 5 years ago

That would be a really difficult optimization to make. Prettier doesn't give the information we would need to do this, so we'd have to format with prettier, then diff the current contents with that (using some other diff tool) to figure out what lines changed and then swap out those lines.

I like the idea. Sounds like it would be painful to implement

On Sun, Jan 27, 2019, 5:21 PM Philip Cox <notifications@github.com wrote:

At the moment if there's a single change made by prettier in a file then the whole files text is replaced, that means every line is shown as changed in VS, and for large files the syntax highlighting takes a little while to re-parse the file which can be a little jarring.

It'd be better if only the changed lines were updated, if possible.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/madskristensen/JavaScriptPrettier/issues/26, or mute the thread https://github.com/notifications/unsubscribe-auth/AA77xaqXijlAzlT2Nt-kHmK06XVxIX_cks5vHiZmgaJpZM4aU-TV .

neoGeneva commented 5 years ago

Well there's certainly plenty of diffing libraries in NuGet, though it might be a bit of work figuring out which one performs the best, and produces the best results. There's lots on NPM as well, it might turn out it's easier to do the diff on the Node side of things.

I am unsure of how you'd apply the changes back into the VS text editor, I'm no very familiar with it, but I'm assuming there's a cursor you can use to use to select and delete / change code.

Though maybe I'm oversimplifying the problem, I might give fork this repo and see what happens.

neoGeneva commented 5 years ago

So here's a quick proof on concept, I haven't tested it with many edge cases (single line files or whatever), and I just picked the first NuGet package without any weird dependencies, and I'm guessing doing a bunch of TextBuffer.CreateEdit() / Apply() isn't super efficient.

But I don't think it'd take much to finish it up if others think there's value in it.

https://github.com/neoGeneva/JavaScriptPrettier/commit/df890855302f7e49c170bbb44e4e2eb3fd2b91e0

tommck commented 5 years ago

I don't know those editor apis, but they might still work fine. No idea.

On Sun, Jan 27, 2019, 9:45 PM Philip Cox <notifications@github.com wrote:

So here's a quick proof on concept, I haven't tested it with many edge cases (single line files or whatever), and I just picked the first NuGet package without any weird dependencies, and I'm guessing doing a bunch of TextBuffer.CreateEdit() / Apply() isn't super efficient.

But I don't think it'd take much to finish it up if others think there's value in it.

neoGeneva@df89085 https://github.com/neoGeneva/JavaScriptPrettier/commit/df890855302f7e49c170bbb44e4e2eb3fd2b91e0

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/madskristensen/JavaScriptPrettier/issues/26#issuecomment-457983150, or mute the thread https://github.com/notifications/unsubscribe-auth/AA77xQtCz6lrU1aCRvFaxOsyh1QIWscSks5vHmRkgaJpZM4aU-TV .

tommck commented 5 years ago

@madskristensen would you be cool adding reference to a 3rd party library like in @neoGeneva's code referenced above?

ruffin-- commented 4 years ago

Okay, I know bumps aren't kosher, but it's been a year, so @madskristensen whaddya think?