r/programming • • May 10 '21

Inliner: Pull blocks of code into a single file

https://youtu.be/EenznqbW5w8
1.2k Upvotes

130 comments sorted by

192

u/tangerines95 May 10 '21

Link here: https://inliner.io

I’m currently working on a VSCode extension that inlines blocks of code so that you can navigate, understand, and write code more easily than with just definition jumping.

It’s currently only on VSCode with Python and JavaScript supported, but with more languages and editors to come. I’ve added a form that you can use to sign up to be notified if/when I add support for an editor/language.

I’m currently a CS student and I’ve been working on this outside of school. If you guys have any feedback or advice, including what I should work on next, please let me know!

50

u/salbris May 10 '21

Looks really slick and helpful! My only complaint would be that the scary thing when working on other code is the potential for side effects affecting the function call. Not sure if you do this yet but highlighting global calls/state in those inlined function blocks would help to remind programmers to watch out for them.

A stretch goal that would be insanely helpful is using the arguments passed when called to determine the actually paths of the function hit and only displaying those.

4

u/tangerines95 May 10 '21

Thanks so much for that feedback! Down the line, I'd like to add a section that lets you confirm that you want the change to propagate to its existing references

14

u/SHCreeper May 10 '21

Imo this should be done by a separate extension that handles your colors/highlighting.

24

u/thelehmanlip May 10 '21

So wait it doesn't actually inline the code into your file, it just peeks into the definition so you can change it without changing windows?

45

u/Acalme-se_Satan May 10 '21 edited May 10 '21

It seems it's exactly that.

VSCode already does this, except it's a much smaller peeking area and it doesn't recurse. This thing here looks like an evolution of the VSCode peek.

39

u/tangerines95 May 10 '21

I think you captured it perfectly. VSCode's peek is great, but it's often a small window and it's limited to only a single peek depth. I think with a greater depth you can limit the need to switch files by a ton

7

u/thelehmanlip May 10 '21

Yes this looks like a really good improvement if all it's doing is peeking. VS (not code)'s peek feature is way too slow and intrusive for me to find it useful, but if it worked like OP it'd be amazing!

39

u/KrazyKirby99999 May 10 '21

Can you upload to https://open-vsx.org/ so that vscodium users can use your extension?

6

u/[deleted] May 10 '21

Yes please.

8

u/Acalme-se_Satan May 10 '21

This is a pretty cool extension.

Just a suggestion, maybe there could be the possibility of doing the reverse path as well (go upwards in the call stack, so instead of opening the function definition, it opens the places where it is called)? Of course, when moving upwards, there are multiple possibilities, but maybe it could let you choose between them with two arrows on the top of the view.

4

u/HolyGarbage May 10 '21

I would love this if it had support for C++.

2

u/John_Lawn4 May 11 '21

I'm confused, can you get this now in the VSCode marketplace? The website seems to only take suggestions

1

u/obvithrowaway34434 May 11 '21

The very concept of this is flawed. You don't edit code by pulling in bits and pieces of your code and making a Frankenstein monster. Each bit of code exists in its context as part of the whole program. Every edit you make requires that you understand this overall structure and relationship between the units. That requires you to view and understand how the function/class fits in and interacts with other functions. The only thing this will do is promote some very bad habits and introduce hard to debug errors because people thought they were being productive by randomly editing sections of code without context.

-9

u/Reddit-Book-Bot May 11 '21

Beep. Boop. I'm a robot. Here's a copy of

Frankenstein

Was I a good bot? | info | More Books

127

u/F4R3LL04 May 10 '21

Cool stuff. Can it be done also for Intellij?

109

u/tangerines95 May 10 '21

If there's enough interest I'd love to build a plugin for Intellij as well

50

u/mpinnegar May 10 '21

I would be happy to donate/crowdfund.

20

u/tangerines95 May 10 '21

Thank you so much for all your support!

11

u/mpinnegar May 10 '21

Just hit me up if you open up a patreon or something.

https://www.patreon.com/godotengine

7

u/Kah-Neth May 10 '21

I would happily pay for a plug-in like this that works for python and c++ in Jetbrains products.

4

u/E418 May 10 '21

I want it, no - I need it !

7

u/[deleted] May 10 '21

I’ll donate to this

2

u/drfisk May 12 '21

IntelliJ definitely needs this!

1

u/cZ_alyun May 11 '21

I'd pay for this too!!

14

u/[deleted] May 10 '21

Of course it can be done, the question is who will do the work

18

u/[deleted] May 10 '21

Not me

2

u/vladmashk May 10 '21

Just use ctrl+click

-2

u/gnuban May 10 '21

IntelliJ already has built-in inlining, ctrl+alt+N

2

u/andrei9669 May 10 '21

How are you supposed to use it tho? I see the shortcut but can't seem to figure out how to use it.

Edit, found out. yeah, that is totally different thing. This inline shortcut just reverses the extraction, not just displays it.

1

u/GhostNULL May 11 '21

Which barely works for PHP unfortunately, only static method are supported.

40

u/kakamiokatsu May 10 '21

Will you consider supporting intellij too? I would gladly pay for such a plugin..

19

u/LeCrushinator May 10 '21 edited May 10 '21

Does IntelliJ not having something like this? I'm using Rider (also from JetBrains) and you can open up code like this (albeit in a popup above your code instead of inline), and make changes to it. In Rider it's called "Quick Definition".

EDIT: It seems that IntelliJ has this as well: https://www.jetbrains.com/help/idea/viewing-reference-information.html

13

u/tangerines95 May 10 '21

Hi and thanks for the reply! I wanted to make something that would allow you to inline multiple levels deep, as well as multiple branches.

I’ve personally used the preview feature on VSCode, but it only allows you to preview one function at a time one level deep.

2

u/LeCrushinator May 10 '21

Yea I think that it will be quite useful, and other IDEs should allow for preview windows to be opened within preview windows.

2

u/kakamiokatsu May 10 '21

That's new to me, are you sure it's not some plugin or a specific feature of Rider? You can easily jump to a file but I never saw the ability to inline view and edit a subset of a file. Super duper that it's recursive and you can open up another definition inside the same preview!

3

u/LeCrushinator May 10 '21

I just added some links for Rider and IntelliJ to my original comment, those may help. It doesn't appear to work recursively though.

3

u/kakamiokatsu May 10 '21

Thanks! Learning something new every day..

2

u/Kah-Neth May 10 '21

This is a pretty big point, recursive and navigable with keyboard only.

1

u/LeCrushinator May 10 '21

Rider does have a shortcut for it, which can be changed. But yea, not recursive.

1

u/kakamiokatsu May 10 '21

Just saw the edit, it really seems you can! I need to try this now

4

u/tangerines95 May 10 '21

Thank you so much, I'd love to work on something similar for Intellij! If you have some time I'd love to talk to you and learn more :)

2

u/kakamiokatsu May 10 '21

Just dropped a DM!

72

u/habitue May 10 '21

This is really cool. I can't tell you how rare it is to see somebody doing original thinking like this in the IDE. We need a lot more of this!

9

u/tangerines95 May 10 '21

Thank you so much!

5

u/CJKay93 May 10 '21

Doesn't VS Code already do this? I swear I do this all the time.

12

u/tangerines95 May 10 '21

it does one level of peeking, not deeper than that

2

u/willstealyourpillow May 10 '21

It does, yes, though as far as I know you cannot do nested references like this.

2

u/AyrA_ch May 10 '21

Have you maybe used visual studio? Because there it definitely does expand over multiple levels, although it's not as pretty.

2

u/CJKay93 May 10 '21

No, I haven't used Visual Studio in years.

10

u/KaiAusBerlin May 10 '21

Nice work.

11

u/vattenpuss May 10 '21

Cool stuff!

As a grumpy old Smalltalker it’s always fun to see other IDEs play catch-up.

Have you checked out Code Bubbles? http://www.andrewbragdon.com/codebubbles_site.asp

5

u/PPatBoyd May 10 '21

Does the "go to" link hover the file path? For the cases where generated or copied files are not the source files you need to edit. May even be better to just have the file path and line #s as the "go to" link? Since you already have the function name in the peek

5

u/Leprecon May 10 '21
  • Gut reaction: oh yeah, lets just put all the code in one file to make it easier...

  • Thought for more than a second: I want this

2

u/[deleted] May 11 '21

It's cool visually, but I'm unsure value is gained over an IDE that has a "click to open location" "go to previous location" buttons/shortcuts.

1

u/bwaxxlo May 16 '21

You clearly dont have ADHD :P. I open files and suddenly 30mins later I've forgotten what I was trying to do with 20 tabs open.

4

u/B_M_Wilson May 10 '21

That’s really cool! I don’t use VS Code but it’s something that I would definitely use if I did

14

u/AttackOfTheThumbs May 10 '21

I guess I don't understand the use case when I can just jump to the definition?

36

u/GrandMasterPuba May 10 '21

It's jump to definition but maintains context - and depth > 1.

7

u/Dimasdanz May 10 '21

faster lookup, i can tell that those who read over engineered DRYed code base would helped a lot. i.e one function call other 3-5 function

2

u/AyrA_ch May 10 '21

If you use regular Visual Studio. Alt+F12 will do the same as this extension.

0

u/[deleted] May 10 '21

[deleted]

17

u/gigastack May 10 '21

With a large enough codebase, anyone can get lost.

6

u/brulerieelixir May 10 '21

This is pretty cool. I wonder if I'll ever ditch emacs. My friend told me the other day that "Nobody uses emacs anymore"... Are the days of console-based editors numbered?

4

u/eyal0 May 10 '21

I'm still using emacs and I don't find it lacking but maybe there are features that I didn't even know that I need!

If anything, I've been using emacs more lately, and not less, because my code is rarely on my own computer anymore. The storage is in the cloud and the compiler is there, too. I'm not sure how well the visual IDEs work with remote code but it's critical to me. emacs+tramp+lsp is my solution so far.

2

u/Devian50 May 10 '21

VSCode at least supports editing over ssh, and it creates a headless editor "server" on the host and does all the actual work there with its own extensions and such. You could do everything you would on the command line inside VSCode, including the integrated terminal. It even supports ssh port forwarding. Idk how well it'd fit in with your workflow, but it's quite expandable.

-1

u/_tskj_ May 10 '21

What kind of programming do you do where your code isn't local? Hope latency isn't too bad!

2

u/eyal0 May 11 '21

It's pretty common. I write code that needs to run in the cloud or on multiple GPUs. It's faster to compile it on that beefy server. So since I'm already doing everything there, might as well code there. However, I don't want to run emacs on that remote server because there will be more lag and it won't have all my coding configuration.

So I tell emacs to load a file like /ssh:eyal0@server:/tmp/foo and it fetches it for work and then saves it back when I save.

I haven't tried it with LSP yet but it ought to work. This is what LSP was made for!

1

u/_tskj_ May 11 '21

Oh okay I was imagining some kind of ssh-send-every-key-press kind of scheme, that doesn't sound so bad! That seems pretty cool actually, and I'm kind of surprised no other editor can support this, like VS Code?

1

u/eyal0 May 11 '21

VS Code might do it, too, I don't know.

2

u/Aminumbra May 10 '21

Depends on what you do and why. It is simply wrong to say that "nobody uses Emacs anymore". However, you cannot use Emacs the same way as any other text editor/IDE. That being said, if you are willing to spend time learning it, Emacs can definitely be as powerful as any other IDE for programming, while being infinitely more customizable and extensible (and do a lot of things waaaaay better than IDE when it is not purely programming stuff: note-taking, Git, doing things over SSH, not taking 3 minutes to start up and use 2GB or RAM to load an empty file ...)

1

u/tester346 May 11 '21

not taking 3 minutes to start up and use 2GB or RAM to load an empty file ...)

HDD, 2GB RAM and Windows XP?

3

u/dedededede May 10 '21

Really cool idea! I think it comes especially handy when you know the code base already a little and you want to fiddle around.

I guess it's also really nice when you debug. Is it possible to set breakpoints in the expanded snippets?

3

u/burntcandy May 10 '21

OMG this looks amazing

2

u/Kah-Neth May 10 '21

That is so cool!!! I hope you can do the same in JetBrains products like Pycharm.

2

u/eyal0 May 10 '21

Cool stuff. Does it work for code that is remote?

1

u/[deleted] May 11 '21

Yes, it also works for code in the future you haven't written yet.

2

u/FormalWolf5 May 10 '21

I've been wondering for some time when someone would finally do something like this. Cool stuff 👀😎

2

u/PotatooFace May 10 '21

How is that gonna work with vim ?

2

u/anarkopsykotik May 10 '21

thats genius mate

2

u/Itchy_Total_3055 May 10 '21

This is very cool!

2

u/RuzgarEken May 11 '21

Damn it is totally great idea

2

u/reifactor May 11 '21

I like this in visual studio--you can pop up an inline "peek" window and if you do it again in the window it basically makes tabs that you can move back and forth in.

2

u/[deleted] May 11 '21

That’s gonna be useful as hell man!

1

u/Sevni May 10 '21

I think this has a potential of getting merged into the main editor, have you ever considered making a pull request?

1

u/[deleted] May 10 '21

If this isn't open source/popular then I won't be able to use it at work. Security on things that read the code and all that..

Though I would love to try it for personal project use, this would really help me as I often get lost in tabs upon tabs

1

u/Hyperian May 10 '21

I can imagine with my code, one click and it tries to show 500 lines

1

u/TryingT0Wr1t3 May 10 '21

One more vote for Intellij (and CLion).

I am curious if there's a way to work around the linecount but my guess is the line count cannot hold arbitrary line numbers.

1

u/Ignisss0012 May 10 '21

Scratch except for real programmers?

1

u/naeads May 11 '21

I need this...

1

u/tester346 May 11 '21

In visual studio you can jump to class/method implementation and then to another, another

and then use "go backward" to jump to the previous cursor position (iirc), so basically you perform deep dive, and then go back to the original place, very handy.

1

u/Luca_Di_Felice May 11 '21

Cool ( ͡° ͜ʖ ͡°)

0

u/Synor May 11 '21

How about solving the root problem of why the files have so many lines of code?

-1

u/Accomplished_End_138 May 11 '21

So I never have seen the purpose of this. I write functionally and I do that just so I don't have this code. And instead I have nicely named functions telling me what they are doing.

-5

u/obvithrowaway34434 May 11 '21 edited May 11 '21

Nope. This basically encourages people to blindly edit code without understanding how a function or class fits with the overall program structure. One of the many reasons for so much shitty and buggy code out there.

-38

u/futlapperl May 10 '21

Neat! Consider implementing it for a programming language next.

4

u/DefinitionOfTorin May 10 '21

?_?

5

u/futlapperl May 11 '21

I am apparently not funny when I'm drunk.

-64

u/Curmudgeon1836 May 10 '21

You invented #include?

M4, C & C++ compilers, & a host of other tools already do this.

Help me understand what's new here ...

https://www.gnu.org/software/m4/manual/m4-1.4.15/html_node/Include.html

https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html

37

u/Substantial-Career12 May 10 '21

What are you talking about? Clearly, the innovation here is the user experience?

-47

u/Curmudgeon1836 May 10 '21

Ok, then that should be the focus, not "including files inline" which most editors & many command line tools already do.

25

u/random_runner May 10 '21

I suspect you didn't actually watch the video but went by title alone? It's more of a sneak view rather than pulling the code in. To be fair, I thought something similar until I saw it.

15

u/deja-roo May 10 '21

What are you talking about?

Are you criticizing what he's done here without having a single clue what he did? Did you watch the video? Even the first ten seconds?

-15

u/Curmudgeon1836 May 10 '21

I didn't criticize although everyone else seems quite quick to jump on criticizing me.

I asked a question: Help me understand what's new here.

It's not really that complicated. What he's done is not novel or unique. Tons of editors support what he's doing here. For example, here's the documentation for this feature in Atom:

https://atom.io/packages/goto-definition

So please, Mr. Pot, tell Mr. Kettle more about what he did wrong ...

3

u/deja-roo May 10 '21

I asked a question: Help me understand what's new here.

Yeah, the thing here is that the question should have been really obvious if you had watched the video. It has literally nothing to do with compiling or pre-processor or library includes.

If you don't understand that, then I guess that leads to the question: have you still not watched the video?

-3

u/Curmudgeon1836 May 10 '21

I've watched it. There's nothing new here. Many editors support this functionality. See link above for Atom for example.

6

u/deja-roo May 10 '21

If you watched it, how did you get to this:

You invented #include?

M4, C & C++ compilers, & a host of other tools already do this.

16

u/abc_wtf May 10 '21

It's just a visual thing to help editing a function (which might be in some other file) that a piece of code is calling.

1

u/[deleted] May 10 '21

[removed] — view removed comment

1

u/Kimbernator May 11 '21

Yes, but nested and it allows editing the source of the functions you peek at

2

u/[deleted] May 11 '21

[removed] — view removed comment

2

u/Kimbernator May 11 '21

I am seeing that it indeed does allow editing like you said (good to know) but nesting doesn't appear to be working for me; peeking at a method call in an inline window fully opens the source file of that method.

In any case you're not wrong about this new plugin not being a groundbreaking addition, but at least it looks a bit prettier.

-20

u/[deleted] May 10 '21

[removed] — view removed comment

8

u/[deleted] May 10 '21

I'm sorry, what? What large projects don't call functions that call functions that call functions (and so on)? I literally don't think it's possible to avoid this.

-13

u/[deleted] May 10 '21

[removed] — view removed comment

5

u/[deleted] May 10 '21

You're misunderstanding the tool then, because what I said is the scenario it's used for

-8

u/[deleted] May 10 '21

[removed] — view removed comment

2

u/[deleted] May 10 '21 edited May 11 '21

I have no idea what your point is here