mirror of
https://github.com/open-goal/jak-project
synced 2026-08-22 07:04:29 -04:00
LSP: A bunch of new OpenGOAL language features (#3437)
- 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>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
#include "ast_util.h"
|
||||
|
||||
namespace ast_util {
|
||||
std::string get_source_code(const std::string& source, const TSNode& node) {
|
||||
uint32_t start = ts_node_start_byte(node);
|
||||
uint32_t end = ts_node_end_byte(node);
|
||||
return source.substr(start, end - start);
|
||||
}
|
||||
|
||||
void search_for_forms_that_begin_with(const std::string& source,
|
||||
const TSNode curr_node,
|
||||
const std::vector<std::string>& prefix,
|
||||
std::vector<TSNode>& results) {
|
||||
if (ts_node_child_count(curr_node) == 0) {
|
||||
return;
|
||||
}
|
||||
std::vector<std::string> node_elements;
|
||||
bool added = false;
|
||||
for (size_t i = 0; i < ts_node_child_count(curr_node); i++) {
|
||||
const auto child_node = ts_node_child(curr_node, i);
|
||||
const auto contents = get_source_code(source, child_node);
|
||||
node_elements.push_back(contents);
|
||||
// Check for a match
|
||||
if (node_elements == prefix && !added) {
|
||||
results.push_back(curr_node);
|
||||
added = true;
|
||||
}
|
||||
search_for_forms_that_begin_with(source, child_node, prefix, results);
|
||||
}
|
||||
}
|
||||
} // namespace ast_util
|
||||
Reference in New Issue
Block a user