mirror of
https://github.com/open-goal/jak-project
synced 2026-07-10 23:22:17 -04:00
lsp: improve LSP IR2 hovers (#1891)
Some new hover features: docstrings (`@param/@return` syntax is not yet supported, nor is a syntax-highlighted preview, will do later)  better MIPs instruction descriptions  numeric hovers convert to different bases / tell you the OpenGOAL method id (i can't tell you the amount of times ive done -16 / 4 manually myself...)  Closes https://github.com/open-goal/opengoal-vscode/issues/33 Closes https://github.com/open-goal/opengoal-vscode/issues/31 Related to https://github.com/open-goal/opengoal-vscode/issues/29
This commit is contained in:
+9
-18
@@ -61,7 +61,7 @@ std::optional<WorkspaceIRFile> Workspace::get_tracked_ir_file(const LSPSpec::URI
|
||||
return m_tracked_ir_files[file_uri];
|
||||
}
|
||||
|
||||
std::optional<goos::TextDb::ShortInfo> Workspace::get_symbol_info_from_all_types(
|
||||
std::optional<DefinitionMetadata> Workspace::get_definition_info_from_all_types(
|
||||
const std::string& symbol_name,
|
||||
const LSPSpec::DocumentUri& all_types_uri) {
|
||||
if (m_tracked_all_types_files.count(all_types_uri) == 0) {
|
||||
@@ -71,7 +71,7 @@ std::optional<goos::TextDb::ShortInfo> Workspace::get_symbol_info_from_all_types
|
||||
if (dts.symbol_metadata_map.count(symbol_name) == 0) {
|
||||
return {};
|
||||
}
|
||||
return dts.symbol_metadata_map.at(symbol_name).definition_info;
|
||||
return dts.symbol_metadata_map.at(symbol_name);
|
||||
}
|
||||
|
||||
void Workspace::start_tracking_file(const LSPSpec::DocumentUri& file_uri,
|
||||
@@ -163,12 +163,11 @@ void WorkspaceIRFile::find_all_types_path(const std::string& line) {
|
||||
|
||||
if (std::regex_search(line, matches, regex)) {
|
||||
if (matches.size() == 3) {
|
||||
auto game_version = matches[1];
|
||||
auto all_types_path = matches[2];
|
||||
const auto& game_version = matches[1];
|
||||
const auto& all_types_path = matches[2];
|
||||
lg::debug("Found DTS Path - {} : {}", game_version.str(), all_types_path.str());
|
||||
auto all_types_uri = uri_from_path(fs::path(all_types_path.str()));
|
||||
lg::debug("DTS URI - {}", all_types_uri);
|
||||
|
||||
if (valid_game_version(game_version.str())) {
|
||||
m_game_version = game_name_to_version(game_version.str());
|
||||
m_all_types_uri = all_types_uri;
|
||||
@@ -188,7 +187,7 @@ void WorkspaceIRFile::find_function_symbol(const uint32_t line_num_zero_based,
|
||||
if (std::regex_search(line, matches, regex)) {
|
||||
// NOTE - assumes we can only find 1 function per line
|
||||
if (matches.size() == 2) {
|
||||
auto match = matches[1];
|
||||
const auto& match = matches[1];
|
||||
lg::info("Adding Symbol - {}", match.str());
|
||||
LSPSpec::DocumentSymbol new_symbol;
|
||||
new_symbol.m_name = match.str();
|
||||
@@ -209,7 +208,6 @@ void WorkspaceIRFile::find_function_symbol(const uint32_t line_num_zero_based,
|
||||
|
||||
std::regex end_function("^;; \\.endfunction\\s*$");
|
||||
if (std::regex_match(line, end_function)) {
|
||||
lg::debug("Found end of previous function on line - {}", line);
|
||||
// Set the previous symbols end-line
|
||||
if (!m_symbols.empty()) {
|
||||
m_symbols[m_symbols.size() - 1].m_range.m_end.m_line = line_num_zero_based - 1;
|
||||
@@ -234,8 +232,7 @@ void WorkspaceIRFile::identify_diagnostics(const uint32_t line_num_zero_based,
|
||||
if (std::regex_search(line, info_matches, info_regex)) {
|
||||
// NOTE - assumes we can only find 1 function per line
|
||||
if (info_matches.size() == 2) {
|
||||
auto match = info_matches[1];
|
||||
lg::debug("Found info-level diagnostic - {}", match.str());
|
||||
const auto& match = info_matches[1];
|
||||
LSPSpec::Diagnostic new_diag;
|
||||
new_diag.m_severity = LSPSpec::DiagnosticSeverity::Information;
|
||||
new_diag.m_message = match.str();
|
||||
@@ -249,8 +246,7 @@ void WorkspaceIRFile::identify_diagnostics(const uint32_t line_num_zero_based,
|
||||
if (std::regex_search(line, warn_matches, warn_regex)) {
|
||||
// NOTE - assumes we can only find 1 function per line
|
||||
if (warn_matches.size() == 2) {
|
||||
auto match = warn_matches[1];
|
||||
lg::debug("Found warn-level diagnostic - {}", match.str());
|
||||
const auto& match = warn_matches[1];
|
||||
LSPSpec::Diagnostic new_diag;
|
||||
new_diag.m_severity = LSPSpec::DiagnosticSeverity::Warning;
|
||||
new_diag.m_message = match.str();
|
||||
@@ -264,8 +260,7 @@ void WorkspaceIRFile::identify_diagnostics(const uint32_t line_num_zero_based,
|
||||
if (std::regex_search(line, error_matches, error_regex)) {
|
||||
// NOTE - assumes we can only find 1 function per line
|
||||
if (error_matches.size() == 2) {
|
||||
auto match = error_matches[1];
|
||||
lg::debug("Found error-level diagnostic - {}", match.str());
|
||||
const auto& match = error_matches[1];
|
||||
LSPSpec::Diagnostic new_diag;
|
||||
new_diag.m_severity = LSPSpec::DiagnosticSeverity::Error;
|
||||
new_diag.m_message = match.str();
|
||||
@@ -285,8 +280,7 @@ std::optional<std::string> WorkspaceIRFile::get_mips_instruction_at_position(
|
||||
std::regex regex("[\\w\\.]+");
|
||||
|
||||
if (std::regex_search(line, matches, regex)) {
|
||||
auto match = matches[0];
|
||||
lg::info("hover first match - {}", match.str());
|
||||
const auto& match = matches[0];
|
||||
auto match_start = matches.position(0);
|
||||
auto match_end = match_start + match.length();
|
||||
if (position.m_character >= match_start && position.m_character <= match_end) {
|
||||
@@ -301,18 +295,15 @@ std::optional<std::string> WorkspaceIRFile::get_symbol_at_position(
|
||||
const LSPSpec::Position position) {
|
||||
// Split the line on typical word boundaries
|
||||
std::string line = m_lines.at(position.m_line);
|
||||
lg::debug("symbol checking - '{}'", line);
|
||||
std::smatch matches;
|
||||
std::regex regex("[\\w\\.\\-_!<>*]+");
|
||||
std::regex_token_iterator<std::string::iterator> rend;
|
||||
|
||||
std::regex_token_iterator<std::string::iterator> match(line.begin(), line.end(), regex);
|
||||
while (match != rend) {
|
||||
lg::debug("match - '{}'", match->str());
|
||||
auto match_start = std::distance(line.begin(), match->first);
|
||||
auto match_end = match_start + match->length();
|
||||
if (position.m_character >= match_start && position.m_character <= match_end) {
|
||||
lg::debug("returning");
|
||||
return match->str();
|
||||
}
|
||||
match++;
|
||||
|
||||
Reference in New Issue
Block a user