r/ZedEditor • • 3d ago

sorting code elements (functions, classes, etc)

i have looked but haven't found anything that does this. i'm not sure if i'm prepared to put the effort into writing it myself as an extension but i'm curious if anyone has already done it before i seriously consider doing it.

i frequently work on projects with a large amount of small functions, likely a common situation in development. often thousands or tens of thousands of them, separated into files depending on their purpose (a file for filesystem access, a file for authentication, a file for password recovery, etc). from an organizational perspective, it would be good to have a way to sort these functions to make them easier to find quickly. yes, you can certainly use the navigation to find a particular function but it would be easier if, for example, you could just sort them alphabetically.

i currently do that by running a shell script but it's messy and put together in a rush years ago. not to mention not nearly as convenient as being able to do it from within the editor instead of having to use a terminal.

i'm not sure if there's anything out there written to sort functions, classes, etc in various languages. i work primarily with php and javascript so those are the two i'm particularly interested in if it exists.

7 Upvotes

6 comments sorted by

1

u/Greenforest_27 3d ago

Tree-sitter?

1

u/Intrepid-Ad-2306 2d ago

yes, i might have to resort to that but it doesn't play nicely with remote editing within zed so it becomes another manual setup issue.

1

u/Greenforest_27 2d ago

I know u mentioned you would prefer not to use the terminal. But honestly you could prob easily find a cli that uses tree-sitter and has a flag for type and sorting and pipe/save to file. It’s just outputs a list to a file and you then can open that in a buffer no? zed has the run actions for terminal commands too and it can be a keybind

1

u/Intrepid-Ad-2306 1d ago

i have no problem with terminal commands for lots of things but the issue is remote development. i work on a lot of different projects and each has its own development server with its own environment. that means any command-line tools i use have to then be implemented across all of them. which also makes it difficult to do something like “sort all functions alphabetically on save if they’re not in order”.

1

u/freefallfreddy 2d ago

I don't understand the question: you want to have an alphabetical list of all symbols (functions and classes) in a project? But then what: you're gonna scroll through thousands of them? Unlikely. So then it's search: https://zed.dev/docs/finding-navigating#go-to-symbol

1

u/Intrepid-Ad-2306 2d ago

i mean within each file, not the entire project all in a single list. it would be helpful to be able to, when scrolling through the files, to have the symbols in alphabetical order to be able to scroll back and forth without having to keep searching for things.

every function is short. no more than five or six lines in almost all cases. scrolling through a hundred or two isn’t a long list when they’re collapsed. but it’s far easier if you can just look where you expect it to be in the alphabet.