-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add kind filter for Goto Symbol command #2330
Conversation
I'd rather not introduce a breaking change... |
I found a workaround to keep the current key bindings working (actually the logic is a bit more straightforward now). But there is still a bug in case you add custom binding with the {
"keys": ["primary+r"],
"command": "lsp_document_symbols",
"args": {"kind": 5},
"context": [{"key": "lsp.session_with_capability", "operand": "documentSymbolProvider"}]
}, It works fine if this kind exists in the response, but otherwise there will be an infinite loop. I'll take a look later. I've reverted the item formatting to be similar as before now, with only one details line. The sorting bug I mentioned above is not really a bug; it is just that ST reorders the items according to fuzzy matching when you type something in the input - but this is also the case with the quick panel which is currently used, and afaik there is no way to prevent that. And I've noticed that the colored region box highlighting on main is even buggy when there are only some items in the response which have the corresponding |
I think everything should be fixed now. It is now possible to use the optional For example for kind "Class": {
"keys": ["primary+r"],
"command": "lsp_document_symbols",
"args": {"kind": 5},
"context": [{"key": "lsp.session_with_capability", "operand": "documentSymbolProvider"}]
}, I have one remaining question; is "All Kinds" a good name for the default label, or would "Any Kind" or maybe even just "Any" be better? |
I think it works now. BTW. When testing, I thought it would be nice to be able to exclude certain kinds like "Variable" and "Constant" while including all other but it might be impossible with how list handlers work, I suppose. I will do a bit more testing and spend some time on looking at the code before accepting but it looks nice. |
I did think about this too, and my approach would be to use an array like When you look at the source code you will see that the implementation is a bit of an hack, where the command calls itself a second time and saves state between those calls, but this is necessary due to the async nature of the request/response to fetch the results for the list input panel, which is not a consideration in the ST if not window:
return None because then it would accidentally run the same request a second time. But it should still be safe to not end up in an infinite loop, because it cannot call the command again another time after the response, when there is no more window. Not sure if this description was somewhat understandable or if you were still able to follow, but in other words I didn't find anymore bugs when testing and I think that the logic should be good now. In general the implementation is a complete rewrite of the LspDocumentSymbolsCommand, but I think especially the code to convert from LSP response to ST list items is quite a bit simpler now. |
Closes #2055.
I removed the colored region box highlighting for now, because I don't really like it personally and ST's built-in Goto Symbol doesn't have something like that. But it could be added back easily.
The implementation is a bit hacky, and there is one significant drawback: a user key binding for this command would need to be adjusted in the following way:
Otherwise it won't work due to the input handlers in the command palette. I'm unsure if this breaking change would be acceptable. Maybe I can find a workaround to make it work with the former key binding too.
Other than that I think it's pretty cool and very practical to use.
Preview video:
preview.webm
"All Kinds" will be selected by default, so that the behavior if you just want to run the command and navigate the unfiltered results is the same as before. Oh and there seems to be still a bug with the sorting sometimes, I'll see if I can fix that.