r/ZedEditor • • 1d 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.

6 Upvotes

5 comments sorted by

1

u/Greenforest_27 23h ago

Tree-sitter?

1

u/Intrepid-Ad-2306 18h 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 1h 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/freefallfreddy 9h 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 5h 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.