mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:38:13 +00:00
HackStudio: User-definable documentation search paths
This resolves a 3+ year old FIXME related to tooltip documentation search paths. By default we now search man3 in addition to man2 that we previously only searched.
This commit is contained in:
parent
aba7f11a50
commit
38a882ddfa
1 changed files with 27 additions and 6 deletions
|
@ -12,7 +12,9 @@
|
|||
#include "Language.h"
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/Debug.h>
|
||||
#include <AK/JsonParser.h>
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/Timer.h>
|
||||
|
@ -78,6 +80,10 @@ Editor::Editor()
|
|||
add_custom_context_menu_action(*m_move_execution_to_line_action);
|
||||
|
||||
set_gutter_visible(true);
|
||||
|
||||
if (Config::read_string("HackStudio"sv, "Global"sv, "DocumentationSearchPaths"sv).is_empty()) {
|
||||
Config::write_string("HackStudio"sv, "Global"sv, "DocumentationSearchPaths"sv, "[\"/usr/share/man/man2\", \"/usr/share/man/man3\"]"sv);
|
||||
}
|
||||
}
|
||||
|
||||
ErrorOr<void> Editor::initialize_tooltip_window()
|
||||
|
@ -181,12 +187,27 @@ static HashMap<String, String>& man_paths()
|
|||
{
|
||||
static HashMap<String, String> paths;
|
||||
if (paths.is_empty()) {
|
||||
// FIXME: This should also search man3, possibly other places..
|
||||
Core::DirIterator it("/usr/share/man/man2", Core::DirIterator::Flags::SkipDots);
|
||||
while (it.has_next()) {
|
||||
auto path = it.next_full_path();
|
||||
auto title = LexicalPath::title(path);
|
||||
paths.set(title, path);
|
||||
auto json = Config::read_string("HackStudio"sv, "Global"sv, "DocumentationSearchPaths"sv);
|
||||
AK::JsonParser parser(json);
|
||||
|
||||
auto value_or_error = parser.parse();
|
||||
if (value_or_error.is_error())
|
||||
return paths;
|
||||
|
||||
auto value = value_or_error.release_value();
|
||||
if (!value.is_array())
|
||||
return paths;
|
||||
|
||||
for (auto& json_value : value.as_array().values()) {
|
||||
if (!json_value.is_string())
|
||||
continue;
|
||||
|
||||
Core::DirIterator it(json_value.as_string(), Core::DirIterator::Flags::SkipDots);
|
||||
while (it.has_next()) {
|
||||
auto path = it.next_full_path();
|
||||
auto title = LexicalPath::title(path);
|
||||
paths.set(title, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue