Commit 712b8070 authored by Günther Wagner's avatar Günther Wagner

Simplify searching in a directory via gio

parent 61264fb8
Pipeline #193046 passed with stage
in 33 minutes and 19 seconds
...@@ -121,45 +121,19 @@ rust_analyzer_service_get_current_file (RustAnalyzerService *self) ...@@ -121,45 +121,19 @@ rust_analyzer_service_get_current_file (RustAnalyzerService *self)
static gboolean static gboolean
rust_analyzer_service_search_cargo_root (RustAnalyzerService *self, rust_analyzer_service_search_cargo_root (RustAnalyzerService *self,
GFile *dir, GFile *dir)
GPatternSpec *spec)
{ {
g_autoptr(GFileEnumerator) enumerator = NULL; g_autoptr(GFile) cargofile = NULL;
IDE_ENTRY; IDE_ENTRY;
g_assert (RUST_IS_ANALYZER_SERVICE (self)); g_assert (RUST_IS_ANALYZER_SERVICE (self));
enumerator = g_file_enumerate_children (dir, cargofile = g_file_get_child (dir, "Cargo.toml");
G_FILE_ATTRIBUTE_STANDARD_NAME","
G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK","
G_FILE_ATTRIBUTE_STANDARD_TYPE,
G_FILE_QUERY_INFO_NONE,
NULL,
NULL);
if (enumerator == NULL)
return FALSE;
for (;;)
{
g_autoptr(GFileInfo) info = g_file_enumerator_next_file (enumerator, NULL, NULL);
const gchar *name;
GFileType file_type;
if (info == NULL)
break;
name = g_file_info_get_name (info); if (g_file_query_exists (cargofile, NULL))
file_type = g_file_info_get_file_type (info); IDE_RETURN (TRUE);
if (g_pattern_match_string (spec, name))
{
g_file_enumerator_close (enumerator, NULL, NULL);
IDE_RETURN (TRUE);
}
}
g_file_enumerator_close (enumerator, NULL, NULL);
IDE_RETURN (FALSE); IDE_RETURN (FALSE);
} }
...@@ -168,16 +142,13 @@ rust_analyzer_service_determine_workdir (RustAnalyzerService *self) ...@@ -168,16 +142,13 @@ rust_analyzer_service_determine_workdir (RustAnalyzerService *self)
{ {
g_autoptr(GFile) workdir = NULL; g_autoptr(GFile) workdir = NULL;
g_autoptr(IdeContext) context = NULL; g_autoptr(IdeContext) context = NULL;
g_autoptr(GPatternSpec) spec = NULL;
g_assert (RUST_IS_ANALYZER_SERVICE (self)); g_assert (RUST_IS_ANALYZER_SERVICE (self));
spec = g_pattern_spec_new ("Cargo.toml");
/* Search workbench root first */ /* Search workbench root first */
context = ide_object_ref_context (IDE_OBJECT (self)); context = ide_object_ref_context (IDE_OBJECT (self));
workdir = ide_context_ref_workdir (context); workdir = ide_context_ref_workdir (context);
if (rust_analyzer_service_search_cargo_root (self, workdir, spec) == FALSE) if (rust_analyzer_service_search_cargo_root (self, workdir) == FALSE)
{ {
/* Search now from the current opened file upwards */ /* Search now from the current opened file upwards */
g_autoptr(GFile) current_file = NULL; g_autoptr(GFile) current_file = NULL;
...@@ -189,7 +160,7 @@ rust_analyzer_service_determine_workdir (RustAnalyzerService *self) ...@@ -189,7 +160,7 @@ rust_analyzer_service_determine_workdir (RustAnalyzerService *self)
while (!g_file_equal (workdir, parent)) while (!g_file_equal (workdir, parent))
{ {
if (rust_analyzer_service_search_cargo_root (self, parent, spec)) if (rust_analyzer_service_search_cargo_root (self, parent))
{ {
return g_steal_pointer (&parent); return g_steal_pointer (&parent);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment