mirror of
https://github.com/open-goal/jak-project
synced 2026-06-12 05:27:57 -04:00
53277a65ad
- Integrate the AST into the LSP, this makes parsing and tokenizing the files much easier - Consolidate most of the symbol info tracking in `goalc` to a single map. Fixed some issues where the old map would never evict symbols when re-compiling files. There is still some more to cleanup, but this now can be used as an incrementally updated source-of-truth for the LSP - re-compile files when they are saved. Ideally this would be done everytime they are changed but that: - may be too aggressive - goalc doesn't compile incrementally yet so it likely would be a worse UX Features added, see https://github.com/open-goal/opengoal-vscode/issues/256 - Hover   - LSP Status fixed - Type Hierarchy  - Document Color  - Document Symbols  - Completions  --------- Co-authored-by: Hat Kid <6624576+Hat-Kid@users.noreply.github.com>
54 lines
1.5 KiB
C++
54 lines
1.5 KiB
C++
#include "document_symbol.h"
|
|
|
|
#include "third-party/json.hpp"
|
|
|
|
using json = nlohmann::json;
|
|
|
|
std::optional<json> ir_symbols(Workspace& workspace, LSPSpec::DocumentSymbolParams params) {
|
|
json symbols = json::array();
|
|
auto maybe_tracked_file = workspace.get_tracked_ir_file(params.m_textDocument.m_uri);
|
|
if (!maybe_tracked_file) {
|
|
return symbols;
|
|
}
|
|
|
|
const auto& tracked_file = maybe_tracked_file.value().get();
|
|
for (const auto& symbol : tracked_file.m_symbols) {
|
|
symbols.push_back(symbol);
|
|
}
|
|
|
|
return symbols;
|
|
}
|
|
|
|
std::optional<json> og_symbols(Workspace& workspace, LSPSpec::DocumentSymbolParams params) {
|
|
json symbols = json::array();
|
|
auto maybe_tracked_file = workspace.get_tracked_og_file(params.m_textDocument.m_uri);
|
|
if (!maybe_tracked_file) {
|
|
return symbols;
|
|
}
|
|
|
|
const auto& tracked_file = maybe_tracked_file.value().get();
|
|
for (const auto& symbol : tracked_file.m_symbols) {
|
|
symbols.push_back(symbol);
|
|
}
|
|
|
|
return symbols;
|
|
}
|
|
|
|
namespace lsp_handlers {
|
|
|
|
std::optional<json> document_symbols(Workspace& workspace, int /*id*/, json params) {
|
|
auto converted_params = params.get<LSPSpec::DocumentSymbolParams>();
|
|
const auto file_type =
|
|
workspace.determine_filetype_from_uri(converted_params.m_textDocument.m_uri);
|
|
|
|
if (file_type == Workspace::FileType::OpenGOALIR) {
|
|
return ir_symbols(workspace, converted_params);
|
|
} else if (file_type == Workspace::FileType::OpenGOAL) {
|
|
return og_symbols(workspace, converted_params);
|
|
}
|
|
|
|
return json::array();
|
|
}
|
|
|
|
} // namespace lsp_handlers
|