Added support for documentSymbolProvider and workspaceSymbolProvider #22
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Most of the code is in the newly added file symbols.jai, which does the nitty gritty. To have this not be slow, I did a couple of things:
2 acceleration structures were added to Program_File. One of them contains json-serialized workspace symbols, because profiling showed that json serialization took about 98% of the response time. To be able to properly use the cached serialized symbols in the response, I added lsp_respond_with_already_json_serialized_result_data, which lets you specify the result as already serialized json, puts that in the complete response and sends it back to the lsp client.
Additionally, the number of workspace symbols returned can be limited with MAX_NUMBER_OF_WORKSPACE_SYMBOLS_TO_RETURN_TO_PREVENT_VSCODE_FROM_BEING_SUPER_SLOW, because in my codebase, there were 80,000 symbols, and while generating the response with the cached json symbols was pretty quick, visual studio code takes like half a second to handle the response, which feels horrible. This shouldn't be a problem, because when you type to narrow down the search, the LSP still searches all symbols without the limit.
For the search query, we consider a symbol to match in the following case:
Each part of the search query that is separated by a space is considered its own search term. (Currently VSCode doesn't even include the space and anything after it, so this is not strictly useful, but this is sublime text 3 behavior that I like and want to replicate with another extension maybe, and since it is just "inactive" currently, I added it). All search terms have to match a symbol name for the symbol to be considered to match. A search term matches a symbol name, if all characters of the search term appear in the same order in the name.
This is a very loose matching system, but vscode actively advocates for this in favor of search for sub-strings, so it has the most options when displaying search results to you, which is reasonable I think.