Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if (NOT "${_mapget_simfil_source_dir}" STREQUAL "")
"SIMFIL_SHARED OFF")
else()
CPMAddPackage(
URI "gh:Klebert-Engineering/simfil#schema-field-pruning@06c9fab"
URI "gh:Klebert-Engineering/simfil#issue-146-schema-enums@65482b8"
OPTIONS
"SIMFIL_WITH_MODEL_JSON ON"
"SIMFIL_SHARED OFF")
Expand Down
13 changes: 13 additions & 0 deletions libs/model/include/mapget/model/schemaregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <memory>
#include <optional>
#include <span>
#include <string>
#include <string_view>
#include <vector>
Expand Down Expand Up @@ -55,6 +56,18 @@ class SchemaRegistry
/** Return true if the schema can contain the field directly or through descendants. */
[[nodiscard]] bool canHaveField(simfil::SchemaId schemaId, std::string_view fieldName) const;

/** Return true if the schema can contain the enum-like string symbol through descendants. */
[[nodiscard]] bool canHaveEnumSymbol(simfil::SchemaId schemaId, std::string_view symbolName) const;

/** Return field names directly declared by this schema node. */
[[nodiscard]] std::span<const std::string> directFields(simfil::SchemaId schemaId) const;

/** Return field names reachable from this schema node. */
[[nodiscard]] std::span<const std::string> nestedFields(simfil::SchemaId schemaId) const;

/** Return enum-like string symbols reachable from this schema node. */
[[nodiscard]] std::span<const std::string> nestedEnumSymbols(simfil::SchemaId schemaId) const;

/** Resolve the Feature object schema for a concrete mapget feature type. */
[[nodiscard]] simfil::SchemaId featureSchema(std::string_view featureType) const;

Expand Down
6 changes: 6 additions & 0 deletions libs/model/include/mapget/model/simfilutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ void installSchemaRegistry(
std::shared_ptr<SchemaRegistry const> registry,
std::shared_ptr<simfil::StringPool const> strings);

/** Attach a completion-only SchemaRegistry callback which materializes schema strings locally. */
void installCompletionSchemaRegistry(
simfil::Environment& env,
std::shared_ptr<SchemaRegistry const> registry,
std::shared_ptr<simfil::StringPool> strings);

template <class... Args>
std::unique_ptr<simfil::Environment> makeEnvironment(Args&& ...args)
{
Expand Down
13 changes: 12 additions & 1 deletion libs/model/src/featurelayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ struct TileFeatureLayer::Impl {
return env;
}

static std::unique_ptr<simfil::Environment> makeSchemaAwareCompletionEnvironment(
std::shared_ptr<simfil::StringPool> stringPool,
std::shared_ptr<SchemaRegistry const> schemaRegistry)
{
auto env = makeEnvironment(stringPool);
installCompletionSchemaRegistry(*env, std::move(schemaRegistry), std::move(stringPool));
return env;
}

// (De-)Serialization
template<typename S>
void readWrite(S& s) {
Expand Down Expand Up @@ -1363,7 +1372,9 @@ TileFeatureLayer::collectQueryDiagnostics(std::string_view query, const simfil::
tl::expected<std::vector<simfil::CompletionCandidate>, simfil::Error>
TileFeatureLayer::complete(std::string_view query, int point, ModelNode const& node, simfil::CompletionOptions const& opts)
{
return impl_->expressionCache_.completions(query, point, node, opts);
auto completionStrings = std::make_shared<simfil::StringPool>(*strings());
auto completionEnv = Impl::makeSchemaAwareCompletionEnvironment(std::move(completionStrings), impl_->schemaRegistry_);
return simfil::complete(*completionEnv, query, point, node, opts);
}

void TileFeatureLayer::setIdPrefix(const KeyValueViewPairs& prefix)
Expand Down
Loading
Loading