lutaml-model 0.8.186 → 0.8.188
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/dependent-repos-tools-informational.json +8 -0
- data/.github/workflows/dependent-repos-tools.json +1 -5
- data/.github/workflows/dependent-tests.yml +26 -2
- data/Gemfile +2 -0
- data/Rakefile +6 -0
- data/exe/lutaml-lml-lsp +11 -0
- data/lib/compat/opal/generate_boot.rb +12 -5
- data/lib/compat/opal/lutaml_model_boot.rb +96 -4
- data/lib/lutaml/lml/association_label_resolver.rb +52 -0
- data/lib/lutaml/lml/data_processor/attribute_processing.rb +133 -0
- data/lib/lutaml/lml/data_processor/collection_processing.rb +37 -0
- data/lib/lutaml/lml/data_processor/instance_processing.rb +77 -0
- data/lib/lutaml/lml/data_processor/value_declaration_processing.rb +70 -0
- data/lib/lutaml/lml/data_processor/value_processing.rb +103 -0
- data/lib/lutaml/lml/data_processor/view_processing.rb +26 -0
- data/lib/lutaml/lml/data_processor.rb +66 -0
- data/lib/lutaml/lml/diagnostic.rb +149 -0
- data/lib/lutaml/lml/document_builder.rb +486 -0
- data/lib/lutaml/lml/entity_types.rb +31 -0
- data/lib/lutaml/lml/executor/adapter_helpers.rb +45 -0
- data/lib/lutaml/lml/executor/condition_evaluator.rb +175 -0
- data/lib/lutaml/lml/executor/csv_adapter.rb +89 -0
- data/lib/lutaml/lml/executor/format_adapter.rb +54 -0
- data/lib/lutaml/lml/executor/xml_adapter.rb +102 -0
- data/lib/lutaml/lml/executor.rb +96 -0
- data/lib/lutaml/lml/format/adapter/document.rb +11 -0
- data/lib/lutaml/lml/format/adapter/mapping.rb +31 -0
- data/lib/lutaml/lml/format/adapter/standard_adapter.rb +164 -0
- data/lib/lutaml/lml/format/adapter/transform.rb +11 -0
- data/lib/lutaml/lml/format.rb +34 -0
- data/lib/lutaml/lml/formatter/base.rb +81 -0
- data/lib/lutaml/lml/formatter/canonical.rb +738 -0
- data/lib/lutaml/lml/formatter.rb +11 -0
- data/lib/lutaml/lml/grammar/lml.artifact.json +14993 -0
- data/lib/lutaml/lml/grammar/lml.parg +389 -0
- data/lib/lutaml/lml/grammar.rb +60 -0
- data/lib/lutaml/lml/has_attributes.rb +14 -0
- data/lib/lutaml/lml/import_resolver.rb +96 -0
- data/lib/lutaml/lml/layout/engine.rb +17 -0
- data/lib/lutaml/lml/layout.rb +9 -0
- data/lib/lutaml/lml/literal_value.rb +32 -0
- data/lib/lutaml/lml/lsp/conversions.rb +78 -0
- data/lib/lutaml/lml/lsp/keywords.rb +43 -0
- data/lib/lutaml/lml/lsp/server.rb +380 -0
- data/lib/lutaml/lml/lsp/store.rb +68 -0
- data/lib/lutaml/lml/lsp/transport.rb +53 -0
- data/lib/lutaml/lml/lsp.rb +16 -0
- data/lib/lutaml/lml/model_compiler/enums.rb +170 -0
- data/lib/lutaml/lml/model_compiler/hydration.rb +122 -0
- data/lib/lutaml/lml/model_compiler/serialization_mappings.rb +188 -0
- data/lib/lutaml/lml/model_compiler/string_formats.rb +42 -0
- data/lib/lutaml/lml/model_compiler/validation.rb +65 -0
- data/lib/lutaml/lml/model_compiler.rb +329 -0
- data/lib/lutaml/lml/models/action.rb +10 -0
- data/lib/lutaml/lml/models/association.rb +31 -0
- data/lib/lutaml/lml/models/cardinality.rb +10 -0
- data/lib/lutaml/lml/models/collection.rb +11 -0
- data/lib/lutaml/lml/models/constraint.rb +25 -0
- data/lib/lutaml/lml/models/data_type.rb +43 -0
- data/lib/lutaml/lml/models/derived_field.rb +14 -0
- data/lib/lutaml/lml/models/diagram.rb +22 -0
- data/lib/lutaml/lml/models/document.rb +86 -0
- data/lib/lutaml/lml/models/enum.rb +40 -0
- data/lib/lutaml/lml/models/fidelity.rb +10 -0
- data/lib/lutaml/lml/models/group.rb +11 -0
- data/lib/lutaml/lml/models/instance.rb +28 -0
- data/lib/lutaml/lml/models/instance_collection.rb +18 -0
- data/lib/lutaml/lml/models/instances_export.rb +10 -0
- data/lib/lutaml/lml/models/instances_import.rb +11 -0
- data/lib/lutaml/lml/models/mapping.rb +15 -0
- data/lib/lutaml/lml/models/mapping_rule.rb +16 -0
- data/lib/lutaml/lml/models/member_field.rb +16 -0
- data/lib/lutaml/lml/models/namespace.rb +18 -0
- data/lib/lutaml/lml/models/operation.rb +28 -0
- data/lib/lutaml/lml/models/operation_parameter.rb +12 -0
- data/lib/lutaml/lml/models/package.rb +28 -0
- data/lib/lutaml/lml/models/primitive_type.rb +35 -0
- data/lib/lutaml/lml/models/reference.rb +23 -0
- data/lib/lutaml/lml/models/serialization_mapping.rb +21 -0
- data/lib/lutaml/lml/models/string_format.rb +16 -0
- data/lib/lutaml/lml/models/top_element_attribute.rb +118 -0
- data/lib/lutaml/lml/models/uml_class.rb +87 -0
- data/lib/lutaml/lml/models/value.rb +17 -0
- data/lib/lutaml/lml/models/view_filter.rb +11 -0
- data/lib/lutaml/lml/models/view_import.rb +11 -0
- data/lib/lutaml/lml/parser.rb +19 -0
- data/lib/lutaml/lml/pipeline.rb +73 -0
- data/lib/lutaml/lml/positioned.rb +13 -0
- data/lib/lutaml/lml/preprocessor.rb +132 -0
- data/lib/lutaml/lml/quoting.rb +60 -0
- data/lib/lutaml/lml/source.rb +49 -0
- data/lib/lutaml/lml/source_position.rb +20 -0
- data/lib/lutaml/lml/symbol_index.rb +202 -0
- data/lib/lutaml/lml/transform.rb +119 -0
- data/lib/lutaml/lml/types/text_type.rb +28 -0
- data/lib/lutaml/lml/types.rb +10 -0
- data/lib/lutaml/lml/validator.rb +460 -0
- data/lib/lutaml/lml/view_resolution.rb +32 -0
- data/lib/lutaml/lml/view_resolver.rb +48 -0
- data/lib/lutaml/lml/yaml_parser.rb +17 -0
- data/lib/lutaml/lml.rb +130 -0
- data/lib/lutaml/model/adapter_resolver.rb +21 -2
- data/lib/lutaml/model/config.rb +22 -0
- data/lib/lutaml/model/serialize/format_conversion.rb +8 -6
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/adapter/base_adapter.rb +26 -0
- data/lib/lutaml/xml/adapter/moxml_adapter.rb +49 -0
- data/lib/lutaml/xml/adapter/xml_parser.rb +4 -4
- data/lib/lutaml/xml/adapter/xml_serializer.rb +1 -1
- data/lib/lutaml/xml/adapter.rb +5 -0
- data/lib/lutaml/xml/adapter_loader.rb +5 -0
- data/lib/lutaml/xml/format.rb +23 -2
- data/lib/lutaml/xml/leptris/native_emission.rb +6 -1
- data/lib/lutaml/xml/leptris/plan_serializer.rb +5 -1
- data/lib/lutaml/xml/parse_session.rb +8 -1
- data/lib/lutaml/xml/schema/builder/moxml.rb +1 -1
- data/lib/lutaml/xml/schema/builder.rb +1 -1
- data/lib/lutaml/xml/schema/relaxng_schema.rb +1 -1
- data/lib/lutaml/xml/schema/vc_namespace.rb +24 -0
- data/lib/lutaml/xml/schema/xsd/any.rb +4 -0
- data/lib/lutaml/xml/schema/xsd/any_attribute.rb +4 -0
- data/lib/lutaml/xml/schema/xsd/base.rb +7 -0
- data/lib/lutaml/xml/schema/xsd/open_content.rb +2 -0
- data/lib/lutaml/xml/schema/xsd/restriction_simple_type.rb +3 -0
- data/lib/lutaml/xml/schema/xsd/schema.rb +38 -0
- data/lib/lutaml/xml/schema/xsd/schema_validator.rb +1 -1
- data/lib/lutaml/xml/schema/xsd.rb +1 -0
- data/lib/lutaml/xml/schema/xsd_schema.rb +1 -1
- data/lib/lutaml/xml/serialization/format_conversion.rb +6 -0
- data/lib/lutaml/xml/xsd_validator.rb +1 -1
- data/lutaml-model.gemspec +2 -0
- data/spec/lml/fixtures/dsl/broken_diagram.lutaml +34 -0
- data/spec/lml/fixtures/dsl/diagram.lutaml +4 -0
- data/spec/lml/fixtures/dsl/diagram_attributes.lutaml +6 -0
- data/spec/lml/fixtures/dsl/diagram_blank_definion.lutaml +6 -0
- data/spec/lml/fixtures/dsl/diagram_blank_entities.lutaml +8 -0
- data/spec/lml/fixtures/dsl/diagram_class_assocation.lutaml +29 -0
- data/spec/lml/fixtures/dsl/diagram_class_fields.lutaml +25 -0
- data/spec/lml/fixtures/dsl/diagram_commented_includes.lutaml +5 -0
- data/spec/lml/fixtures/dsl/diagram_comments.lutaml +28 -0
- data/spec/lml/fixtures/dsl/diagram_concept_model.lutaml +132 -0
- data/spec/lml/fixtures/dsl/diagram_data_types.lutaml +44 -0
- data/spec/lml/fixtures/dsl/diagram_definitions.lutaml +25 -0
- data/spec/lml/fixtures/dsl/diagram_includes.lutaml +6 -0
- data/spec/lml/fixtures/dsl/diagram_multiply_classes.lutaml +7 -0
- data/spec/lml/fixtures/dsl/diagram_non_existing_include.lutaml +6 -0
- data/spec/lml/fixtures/dsl/shared.lutaml +5 -0
- data/spec/lml/fixtures/dsl/shared1.lutaml +4 -0
- data/spec/lml/fixtures/generated_dot/AddressClassProfile.dot +170 -0
- data/spec/lml/fixtures/generated_dot/AddressProfile.dot +34 -0
- data/spec/lml/fixtures/generated_dot/address_class_profile_with_associations.dot +127 -0
- data/spec/lml/fixtures/generated_dot/address_profile_with_associations.dot +28 -0
- data/spec/lml/fixtures/generated_dot/document.dot +28 -0
- data/spec/lml/fixtures/generated_dot/document.dot.backup +33 -0
- data/spec/lml/fixtures/generated_dot/document_with_fidelity.dot +27 -0
- data/spec/lml/fixtures/lml/data_s102_check.lml +79 -0
- data/spec/lml/fixtures/lml/data_s158_metadata.lml +28 -0
- data/spec/lml/fixtures/lml/iho_data_models.lml +59 -0
- data/spec/lml/fixtures/lml/iho_s102_check.lml +101 -0
- data/spec/lml/fixtures/mixed_lml/diagram.lml +26 -0
- data/spec/lml/fixtures/mixed_lml/instances.lml +72 -0
- data/spec/lml/fixtures/mixed_lml/model.lml +30 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/AdmonitionType.lutaml +32 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/BasicBlock.lutaml +11 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/BasicDocument.lutaml +41 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/BasicSection.lutaml +38 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/BibliographicItem.lutaml +6 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/FigureBlock.lutaml +65 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/FormattedString.lutaml +12 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/List.lutaml +12 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/OrderedListType.lutaml +32 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/Signature.lutaml +22 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/String.lutaml +2 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/TableBlock.lutaml +60 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/TextElement.lutaml +13 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/Uri.lutaml +7 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/BibliographicItem.lutaml +4 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoAdmonitionType.lutaml +31 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoBibDataExtensionType.lutaml +40 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoSections.lutaml +30 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoStandardDocument.lutaml +46 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoTerm.lutaml +20 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/StandardBibDataExtensionType.lutaml +2 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/StandardDocument.lutaml +2 -0
- data/spec/lml/fixtures/rs3001/01_class_tail_comment.lml +5 -0
- data/spec/lml/fixtures/rs3001/02_definition_block.lml +9 -0
- data/spec/lml/fixtures/rs3001/03_package_ceramics.lml +20 -0
- data/spec/lml/fixtures/rs3001/04_attribute_definition_form.lml +10 -0
- data/spec/lml/fixtures/rs3001/05_attribute_cardinality_unbounded.lml +10 -0
- data/spec/lml/fixtures/rs3001/06_attribute_values_set.lml +10 -0
- data/spec/lml/fixtures/rs3001/07_attribute_pattern.lml +10 -0
- data/spec/lml/fixtures/rs3001/08_attribute_default_colon.lml +15 -0
- data/spec/lml/fixtures/rs3001/09_value_porcelain.lml +9 -0
- data/spec/lml/fixtures/rs3001/10_enum_glaze_technique.lml +19 -0
- data/spec/lml/fixtures/rs3001/11_enum_values_as_instances.lml +29 -0
- data/spec/lml/fixtures/rs3001/12_instance_named.lml +13 -0
- data/spec/lml/fixtures/rs3001/13_instances_collection_refs.lml +11 -0
- data/spec/lml/fixtures/rs3001/14_require_models.lml +7 -0
- data/spec/lml/fixtures/rs3001/15_comment_line.lml +1 -0
- data/spec/lml/fixtures/rs3001/16_comment_tail.lml +5 -0
- data/spec/lml/fixtures/rs3001/17_comment_documented_class.lml +5 -0
- data/spec/lml/fixtures/rs3001/18_comment_block.lml +4 -0
- data/spec/lml/fixtures/rs3001/19_top_level_instance_definition.lml +21 -0
- data/spec/lml/fixtures/rs3001/20_instance_typed_definition.lml +22 -0
- data/spec/lml/fixtures/rs3001/21_instance_collection_studios.lml +19 -0
- data/spec/lml/fixtures/rs3001/22_instance_collection_tiles.lml +15 -0
- data/spec/lml/fixtures/rs3001/23_reference_cross_collection.lml +11 -0
- data/spec/lml/fixtures/rs3001/24_null_and_empty.lml +15 -0
- data/spec/lml/fixtures/rs3001/25_string_escapes.lml +23 -0
- data/spec/lml/fixtures/rs3001/26_quoted_keys.lml +7 -0
- data/spec/lml/fixtures/test.lutaml +20 -0
- data/spec/lml/fixtures/test_data/components.csv +4 -0
- data/spec/lml/fixtures/test_data/products.xml +18 -0
- data/spec/lml/fixtures/uml/address_class_profile_with_associations.yml +58 -0
- data/spec/lml/fixtures/uml/address_profile_with_associations.yml +31 -0
- data/spec/lml/fixtures/uml/association.yml +11 -0
- data/spec/lml/fixtures/uml/class.yml +28 -0
- data/spec/lml/fixtures/uml/data_type.yml +30 -0
- data/spec/lml/fixtures/uml/diagram.yml +7 -0
- data/spec/lml/fixtures/uml/document.yml +44 -0
- data/spec/lml/fixtures/uml/document_with_fidelity.yml +47 -0
- data/spec/lml/fixtures/uml/enum.yml +14 -0
- data/spec/lml/fixtures/uml/operation.yml +8 -0
- data/spec/lml/fixtures/uml/package.yml +10 -0
- data/spec/lml/fixtures/uml/top_element.yml +11 -0
- data/spec/lml/fixtures/uml/top_element_attribute.yml +10 -0
- data/spec/lml/fixtures/uml/trigger.yml +12 -0
- data/spec/lml/fixtures/uml/value.yml +8 -0
- data/spec/lml/fixtures/view/cycle_a.lutaml +3 -0
- data/spec/lml/fixtures/view/cycle_b.lutaml +3 -0
- data/spec/lml/fixtures/view/import_model.lutaml +3 -0
- data/spec/lml/fixtures/view/import_view.lutaml +3 -0
- data/spec/lml/fixtures/view/import_with_hide.lutaml +4 -0
- data/spec/lml/fixtures/view/import_with_show.lutaml +4 -0
- data/spec/lml/fixtures/view/models/bar.lutaml +3 -0
- data/spec/lml/fixtures/view/models/baz.lutaml +3 -0
- data/spec/lml/fixtures/view/models/foo.lutaml +4 -0
- data/spec/lml/integration/instance_import_export_spec.rb +102 -0
- data/spec/lml/lml_spec_setup.rb +25 -0
- data/spec/lml/lutaml/lml/association_label_resolver_spec.rb +139 -0
- data/spec/lml/lutaml/lml/data_processor_spec.rb +274 -0
- data/spec/lml/lutaml/lml/declarations_spec.rb +337 -0
- data/spec/lml/lutaml/lml/document_builder_registry_spec.rb +52 -0
- data/spec/lml/lutaml/lml/document_builder_spec.rb +99 -0
- data/spec/lml/lutaml/lml/element_visibility_spec.rb +128 -0
- data/spec/lml/lutaml/lml/entity_types_spec.rb +56 -0
- data/spec/lml/lutaml/lml/enum_spec.rb +77 -0
- data/spec/lml/lutaml/lml/executor/adapter_helpers_spec.rb +96 -0
- data/spec/lml/lutaml/lml/executor/condition_evaluator_spec.rb +393 -0
- data/spec/lml/lutaml/lml/executor/csv_adapter_spec.rb +151 -0
- data/spec/lml/lutaml/lml/executor/format_adapter_spec.rb +31 -0
- data/spec/lml/lutaml/lml/executor/xml_adapter_spec.rb +201 -0
- data/spec/lml/lutaml/lml/executor_spec.rb +71 -0
- data/spec/lml/lutaml/lml/format_adapter_spec.rb +272 -0
- data/spec/lml/lutaml/lml/format_autoload_spec.rb +31 -0
- data/spec/lml/lutaml/lml/grammar_spec.rb +581 -0
- data/spec/lml/lutaml/lml/has_attributes_spec.rb +54 -0
- data/spec/lml/lutaml/lml/import_resolver_spec.rb +116 -0
- data/spec/lml/lutaml/lml/instance_hydration_spec.rb +178 -0
- data/spec/lml/lutaml/lml/lsp/server_spec.rb +285 -0
- data/spec/lml/lutaml/lml/model_compiler_spec.rb +406 -0
- data/spec/lml/lutaml/lml/models/association_spec.rb +40 -0
- data/spec/lml/lutaml/lml/models/collection_spec.rb +27 -0
- data/spec/lml/lutaml/lml/models/data_type_spec.rb +34 -0
- data/spec/lml/lutaml/lml/models/diagram_spec.rb +18 -0
- data/spec/lml/lutaml/lml/models/document_spec.rb +64 -0
- data/spec/lml/lutaml/lml/models/enum_spec.rb +42 -0
- data/spec/lml/lutaml/lml/models/inheritance_spec.rb +77 -0
- data/spec/lml/lutaml/lml/models/instance_collection_spec.rb +62 -0
- data/spec/lml/lutaml/lml/models/instance_spec.rb +81 -0
- data/spec/lml/lutaml/lml/models/instances_export_spec.rb +23 -0
- data/spec/lml/lutaml/lml/models/instances_import_spec.rb +28 -0
- data/spec/lml/lutaml/lml/models/package_spec.rb +26 -0
- data/spec/lml/lutaml/lml/models/primitive_type_spec.rb +34 -0
- data/spec/lml/lutaml/lml/models/top_element_attribute_spec.rb +153 -0
- data/spec/lml/lutaml/lml/models/uml_class_spec.rb +70 -0
- data/spec/lml/lutaml/lml/models_version_spec.rb +27 -0
- data/spec/lml/lutaml/lml/operations_spec.rb +59 -0
- data/spec/lml/lutaml/lml/parser_spec.rb +348 -0
- data/spec/lml/lutaml/lml/pipeline_spec.rb +93 -0
- data/spec/lml/lutaml/lml/preprocessor_spec.rb +174 -0
- data/spec/lml/lutaml/lml/property_laws_spec.rb +344 -0
- data/spec/lml/lutaml/lml/real_world_spec.rb +191 -0
- data/spec/lml/lutaml/lml/reference_spec.rb +64 -0
- data/spec/lml/lutaml/lml/round_trip_spec.rb +457 -0
- data/spec/lml/lutaml/lml/rs3001_corpus_spec.rb +83 -0
- data/spec/lml/lutaml/lml/rs3001_syntax_spec.rb +77 -0
- data/spec/lml/lutaml/lml/serialization_mapping_spec.rb +127 -0
- data/spec/lml/lutaml/lml/source_spec.rb +62 -0
- data/spec/lml/lutaml/lml/transform_spec.rb +37 -0
- data/spec/lml/lutaml/lml/types/text_type_spec.rb +43 -0
- data/spec/lml/lutaml/lml/validator_spec.rb +238 -0
- data/spec/lml/lutaml/lml/view_resolver_spec.rb +78 -0
- data/spec/lml/lutaml/lml/view_spec.rb +112 -0
- data/spec/lml/lutaml/parsers/dsl_spec.rb +275 -0
- data/spec/lml/lutaml/parsers/yaml_spec.rb +52 -0
- data/spec/lml/lutaml/qualified_type_spec.rb +33 -0
- data/spec/lutaml/model/adapter_type_unset_restore_spec.rb +61 -0
- data/spec/lutaml/model/custom_bibtex_adapter_spec.rb +4 -1
- data/spec/lutaml/xml/adapter/moxml_lane_spec.rb +112 -0
- data/spec/lutaml/xml/adapter_metadata_default_spec.rb +21 -2
- data/spec/lutaml/xml/adapter_moxml_engine_spec.rb +57 -0
- data/spec/lutaml/xml/leptris/native_emission_plain_model_spec.rb +50 -0
- data/spec/lutaml/xml/plain_model_mapping_resolution_spec.rb +88 -0
- data/spec/lutaml/xml/schema/xsd/vc_versioning_spec.rb +49 -0
- data/spec/lutaml/xml/schema/xsd/xsd_11_constructs_spec.rb +83 -0
- metadata +286 -2
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "cgi"
|
|
4
|
+
|
|
5
|
+
module Lutaml
|
|
6
|
+
module Lml
|
|
7
|
+
module Lsp
|
|
8
|
+
# Conversions between the parser's 1-based positions and LSP's
|
|
9
|
+
# 0-based positions, plus diagnostic records.
|
|
10
|
+
module Conversions
|
|
11
|
+
module_function
|
|
12
|
+
|
|
13
|
+
def position(source_position)
|
|
14
|
+
return { line: 0, character: 0 } unless source_position
|
|
15
|
+
|
|
16
|
+
{
|
|
17
|
+
line: source_position.line.to_i - 1,
|
|
18
|
+
character: source_position.column.to_i - 1,
|
|
19
|
+
}
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def range(source_position)
|
|
23
|
+
start = position(source_position)
|
|
24
|
+
{
|
|
25
|
+
start: start,
|
|
26
|
+
end: {
|
|
27
|
+
line: start[:line],
|
|
28
|
+
character: start[:character] + source_position.length.to_i,
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def diagnostic(record)
|
|
34
|
+
{
|
|
35
|
+
range: diagnostic_range(record),
|
|
36
|
+
severity: severity(record.severity),
|
|
37
|
+
code: record.code,
|
|
38
|
+
source: "lutaml-lml",
|
|
39
|
+
message: diagnostic_message(record),
|
|
40
|
+
}
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def diagnostic_range(record)
|
|
44
|
+
line = [record.line.to_i - 1, 0].max
|
|
45
|
+
character = [record.column.to_i - 1, 0].max
|
|
46
|
+
length = record.length.to_i
|
|
47
|
+
length = 1 if length.zero?
|
|
48
|
+
{
|
|
49
|
+
start: { line: line, character: character },
|
|
50
|
+
end: { line: line, character: character + length },
|
|
51
|
+
}
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def diagnostic_message(record)
|
|
55
|
+
return record.message.to_s if record.remedy.to_s.empty?
|
|
56
|
+
|
|
57
|
+
"#{record.message}\nremedy: #{record.remedy}"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def severity(value)
|
|
61
|
+
value.to_s == "warning" ? 2 : 1
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# file:///path → local path. Windows drive paths lose the leading
|
|
65
|
+
# slash (file:///C:/x → C:/x).
|
|
66
|
+
def uri_to_path(uri)
|
|
67
|
+
path = uri.to_s.delete_prefix("file://")
|
|
68
|
+
path = CGI.unescape(path)
|
|
69
|
+
path.sub(%r{\A/([A-Za-z]:/)}, '\1')
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def path_to_uri(path)
|
|
73
|
+
"file://#{CGI.escape(path.to_s).gsub('+', '%20')}"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
5
|
+
module Lutaml
|
|
6
|
+
module Lml
|
|
7
|
+
module Lsp
|
|
8
|
+
# The completion keyword list, read from the compiled grammar
|
|
9
|
+
# artifact so it cannot drift from the language.
|
|
10
|
+
module Keywords
|
|
11
|
+
ARTIFACT = File.expand_path("../grammar/lml.artifact.json", __dir__)
|
|
12
|
+
|
|
13
|
+
module_function
|
|
14
|
+
|
|
15
|
+
def all
|
|
16
|
+
@all ||= begin
|
|
17
|
+
artifact = JSON.parse(File.read(ARTIFACT))
|
|
18
|
+
literals = []
|
|
19
|
+
collect(artifact["entries"], literals)
|
|
20
|
+
literals.grep(/\A[a-z][a-z0-9_]*\z/)
|
|
21
|
+
.uniq
|
|
22
|
+
.sort
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def collect(node, literals)
|
|
27
|
+
case node
|
|
28
|
+
when Hash
|
|
29
|
+
node.each do |key, value|
|
|
30
|
+
if key.to_s == "Str" && value.is_a?(Hash)
|
|
31
|
+
literals << value["pattern"].to_s
|
|
32
|
+
else
|
|
33
|
+
collect(value, literals)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
when Array
|
|
37
|
+
node.each { |item| collect(item, literals) }
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
module Lsp
|
|
6
|
+
# The stdio JSON-RPC server. One message at a time; every document
|
|
7
|
+
# change reparses the full text. Errors are contained per message
|
|
8
|
+
# so a broken document never crashes the server.
|
|
9
|
+
class Server
|
|
10
|
+
WORD = /[A-Za-z0-9_:.-]/
|
|
11
|
+
|
|
12
|
+
CAPABILITIES = {
|
|
13
|
+
textDocumentSync: 1,
|
|
14
|
+
documentSymbolProvider: true,
|
|
15
|
+
definitionProvider: true,
|
|
16
|
+
referencesProvider: true,
|
|
17
|
+
hoverProvider: true,
|
|
18
|
+
completionProvider: { triggerCharacters: [" ", ":"] },
|
|
19
|
+
documentFormattingProvider: true,
|
|
20
|
+
diagnosticProvider: {
|
|
21
|
+
interFileDependencies: false,
|
|
22
|
+
workspaceDiagnostics: false,
|
|
23
|
+
},
|
|
24
|
+
}.freeze
|
|
25
|
+
|
|
26
|
+
def initialize(transport: Transport.new, store: Store.new)
|
|
27
|
+
@transport = transport
|
|
28
|
+
@store = store
|
|
29
|
+
@shutdown = false
|
|
30
|
+
@stopped = false
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Runs the message loop; returns the process exit code.
|
|
34
|
+
def run
|
|
35
|
+
until @stopped
|
|
36
|
+
message = @transport.read_message
|
|
37
|
+
break if message.nil?
|
|
38
|
+
|
|
39
|
+
dispatch(message)
|
|
40
|
+
end
|
|
41
|
+
@shutdown ? 0 : 1
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def dispatch(message)
|
|
47
|
+
id = message["id"]
|
|
48
|
+
method = message["method"]
|
|
49
|
+
params = message["params"] || {}
|
|
50
|
+
|
|
51
|
+
case method
|
|
52
|
+
when "initialize" then respond(id, initialize_result)
|
|
53
|
+
when "initialized" then nil
|
|
54
|
+
when "shutdown"
|
|
55
|
+
@shutdown = true
|
|
56
|
+
respond(id, nil)
|
|
57
|
+
when "exit"
|
|
58
|
+
@stopped = true
|
|
59
|
+
when "textDocument/didOpen" then did_open(params)
|
|
60
|
+
when "textDocument/didChange" then did_change(params)
|
|
61
|
+
when "textDocument/didClose" then did_close(params)
|
|
62
|
+
when "textDocument/diagnostic" then respond(id, diagnostic_report(params))
|
|
63
|
+
when "textDocument/documentSymbol" then respond(id, document_symbols(params))
|
|
64
|
+
when "textDocument/definition" then respond(id, definition(params))
|
|
65
|
+
when "textDocument/references" then respond(id, references(params))
|
|
66
|
+
when "textDocument/hover" then respond(id, hover(params))
|
|
67
|
+
when "textDocument/completion" then respond(id, completion(params))
|
|
68
|
+
when "textDocument/formatting" then respond(id, formatting(params))
|
|
69
|
+
else
|
|
70
|
+
respond_error(id, -32_601, "Method not found: #{method}") unless id.nil?
|
|
71
|
+
end
|
|
72
|
+
rescue StandardError => e
|
|
73
|
+
respond_error(id, -32_603, e.message) unless id.nil?
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def initialize_result
|
|
77
|
+
{
|
|
78
|
+
capabilities: CAPABILITIES,
|
|
79
|
+
# The LML namespace ships inside lutaml-model: the gem version is
|
|
80
|
+
# the LML version (the standalone gem is retired).
|
|
81
|
+
serverInfo: { name: "lutaml-lml-lsp", version: Lutaml::Model::VERSION },
|
|
82
|
+
}
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# ---- documents ----
|
|
86
|
+
|
|
87
|
+
def did_open(params)
|
|
88
|
+
document = params["textDocument"] || {}
|
|
89
|
+
entry = @store.open(
|
|
90
|
+
uri: document["uri"], text: document["text"].to_s,
|
|
91
|
+
version: document["version"]
|
|
92
|
+
)
|
|
93
|
+
publish(entry)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def did_change(params)
|
|
97
|
+
document = params["textDocument"] || {}
|
|
98
|
+
changes = params["contentChanges"] || []
|
|
99
|
+
text = changes.last.is_a?(Hash) ? changes.last["text"].to_s : ""
|
|
100
|
+
entry = @store.change(
|
|
101
|
+
uri: document["uri"], text: text, version: document["version"],
|
|
102
|
+
)
|
|
103
|
+
publish(entry) if entry
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def did_close(params)
|
|
107
|
+
document = params["textDocument"] || {}
|
|
108
|
+
uri = document["uri"]
|
|
109
|
+
@store.close(uri)
|
|
110
|
+
@transport.write_message(
|
|
111
|
+
jsonrpc: "2.0", method: "textDocument/publishDiagnostics",
|
|
112
|
+
params: { uri: uri, diagnostics: [] }
|
|
113
|
+
)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def publish(entry)
|
|
117
|
+
@transport.write_message(
|
|
118
|
+
jsonrpc: "2.0", method: "textDocument/publishDiagnostics",
|
|
119
|
+
params: {
|
|
120
|
+
uri: entry.uri,
|
|
121
|
+
diagnostics: entry.diagnostics.map { |record| Conversions.diagnostic(record) },
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def diagnostic_report(params)
|
|
127
|
+
entry = entry_for(params)
|
|
128
|
+
return { kind: "full", items: [] } unless entry
|
|
129
|
+
|
|
130
|
+
{
|
|
131
|
+
kind: "full",
|
|
132
|
+
items: entry.diagnostics.map { |record| Conversions.diagnostic(record) },
|
|
133
|
+
}
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# ---- symbols ----
|
|
137
|
+
|
|
138
|
+
def document_symbols(params)
|
|
139
|
+
entry = entry_for(params)
|
|
140
|
+
return [] unless entry&.model
|
|
141
|
+
|
|
142
|
+
SymbolIndex.new(entry.model).entries.map do |symbol|
|
|
143
|
+
{
|
|
144
|
+
name: symbol.name,
|
|
145
|
+
kind: SymbolIndex::KINDS.fetch(symbol.kind),
|
|
146
|
+
location: location(entry.uri, symbol.position),
|
|
147
|
+
containerName: symbol.container,
|
|
148
|
+
}.compact
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def definition(params)
|
|
153
|
+
entry = entry_for(params)
|
|
154
|
+
return nil unless entry&.model
|
|
155
|
+
|
|
156
|
+
token = token_at(entry, params["position"])
|
|
157
|
+
return nil if token.empty?
|
|
158
|
+
|
|
159
|
+
index = SymbolIndex.new(entry.model)
|
|
160
|
+
locations = resolve(index, token).map { |symbol| location(entry.uri, symbol.position) }
|
|
161
|
+
locations.empty? ? nil : locations
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def references(params)
|
|
165
|
+
entry = entry_for(params)
|
|
166
|
+
return [] unless entry&.model
|
|
167
|
+
|
|
168
|
+
token = token_at(entry, params["position"])
|
|
169
|
+
return [] if token.empty?
|
|
170
|
+
|
|
171
|
+
index = SymbolIndex.new(entry.model)
|
|
172
|
+
symbols = index.uses(token)
|
|
173
|
+
symbols += index.definitions(token) if params.dig("context", "includeDeclaration")
|
|
174
|
+
|
|
175
|
+
symbols.map { |symbol| location(entry.uri, symbol.position) }.uniq
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def hover(params)
|
|
179
|
+
entry = entry_for(params)
|
|
180
|
+
return nil unless entry&.model
|
|
181
|
+
|
|
182
|
+
position = params["position"]
|
|
183
|
+
token = token_at(entry, position)
|
|
184
|
+
return nil if token.empty?
|
|
185
|
+
|
|
186
|
+
symbol = resolve(SymbolIndex.new(entry.model), token).first
|
|
187
|
+
return nil unless symbol
|
|
188
|
+
|
|
189
|
+
{
|
|
190
|
+
contents: { kind: "markdown", value: hover_markdown(symbol) },
|
|
191
|
+
range: token_range(entry, position, token),
|
|
192
|
+
}
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def hover_markdown(symbol)
|
|
196
|
+
case symbol.kind
|
|
197
|
+
when :class then class_markdown(symbol.record)
|
|
198
|
+
when :enum then enum_markdown(symbol.record)
|
|
199
|
+
when :field then field_markdown(symbol.record)
|
|
200
|
+
when :instance then instance_markdown(symbol.record)
|
|
201
|
+
when :enum_member then enum_member_markdown(symbol.record)
|
|
202
|
+
else "**#{symbol.name}**"
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def class_markdown(klass)
|
|
207
|
+
text = "```lml\nclass #{klass.name}"
|
|
208
|
+
text << " < #{klass.parent_class}" unless klass.parent_class.to_s.empty?
|
|
209
|
+
text << "\n```"
|
|
210
|
+
append_definition(text, klass.definition)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def enum_markdown(enum)
|
|
214
|
+
members = Array(enum.attributes).map { |member| member.name.to_s }
|
|
215
|
+
text = "```lml\nenum #{enum.name}\n```"
|
|
216
|
+
text << "\n\nMembers: #{members.join(', ')}" unless members.empty?
|
|
217
|
+
append_definition(text, enum.definition)
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def field_markdown(attribute)
|
|
221
|
+
label = attribute.name.to_s
|
|
222
|
+
type = attribute.type.to_s
|
|
223
|
+
text = "```lml\n#{label}"
|
|
224
|
+
text << ": #{type}" unless type.empty?
|
|
225
|
+
cardinality = attribute.cardinality
|
|
226
|
+
if cardinality
|
|
227
|
+
max = cardinality.max.to_s
|
|
228
|
+
text << " [#{cardinality.min}#{"..#{max}" unless max.empty?}]"
|
|
229
|
+
end
|
|
230
|
+
text << "\n```"
|
|
231
|
+
text << "\n\ndefault: `#{attribute.default}`" if attribute.default
|
|
232
|
+
text << "\npattern: `#{attribute.pattern}`" if attribute.pattern
|
|
233
|
+
text << "\nvalues: #{attribute.value_set.join(', ')}" if Array(attribute.value_set).any?
|
|
234
|
+
append_definition(text, attribute.definition)
|
|
235
|
+
text << "\n\n`null`, `\"\"`, and an unassigned attribute are distinct." if type == "String"
|
|
236
|
+
text
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def instance_markdown(instance)
|
|
240
|
+
label = instance.type.to_s.empty? ? instance.name.to_s : instance.type.to_s
|
|
241
|
+
text = "```lml\ninstance #{label}\n```"
|
|
242
|
+
text << "\n\n#{Array(instance.attributes).size} assignment(s)"
|
|
243
|
+
text
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
def enum_member_markdown(member)
|
|
247
|
+
text = "**value #{member.name}**"
|
|
248
|
+
description = Array(member.attributes).find { |attribute| attribute.name == "description" }
|
|
249
|
+
text << "\n\n#{description.type}" if description
|
|
250
|
+
text
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
def append_definition(text, definition)
|
|
254
|
+
value = definition.to_s
|
|
255
|
+
text << "\n\n#{value}" unless value.empty?
|
|
256
|
+
text
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
# ---- completion ----
|
|
260
|
+
|
|
261
|
+
def completion(params)
|
|
262
|
+
entry = entry_for(params)
|
|
263
|
+
prefix = completion_prefix(entry, params["position"])
|
|
264
|
+
items = completion_items(entry)
|
|
265
|
+
items = items.select { |item| item[:label].start_with?(prefix) } unless prefix.empty?
|
|
266
|
+
|
|
267
|
+
{ isIncomplete: false, items: items }
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
def completion_items(entry)
|
|
271
|
+
items = Keywords.all.map do |keyword|
|
|
272
|
+
{ label: keyword, kind: 14, detail: "LML keyword" }
|
|
273
|
+
end
|
|
274
|
+
return dedupe(items) unless entry&.model
|
|
275
|
+
|
|
276
|
+
index = SymbolIndex.new(entry.model)
|
|
277
|
+
index.entity_entries.each do |symbol|
|
|
278
|
+
items << {
|
|
279
|
+
label: symbol.name,
|
|
280
|
+
kind: SymbolIndex::KINDS.fetch(symbol.kind),
|
|
281
|
+
detail: symbol.detail || symbol.container,
|
|
282
|
+
}
|
|
283
|
+
end
|
|
284
|
+
index.attribute_entries.each do |symbol|
|
|
285
|
+
items << { label: symbol.name, kind: 8, detail: symbol.detail }
|
|
286
|
+
end
|
|
287
|
+
dedupe(items)
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
def dedupe(items)
|
|
291
|
+
seen = {}
|
|
292
|
+
items.each_with_object([]) do |item, result|
|
|
293
|
+
next if seen[item[:label]]
|
|
294
|
+
|
|
295
|
+
seen[item[:label]] = true
|
|
296
|
+
result << item.compact
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
# ---- formatting ----
|
|
301
|
+
|
|
302
|
+
def formatting(params)
|
|
303
|
+
entry = entry_for(params)
|
|
304
|
+
return nil unless entry&.model
|
|
305
|
+
|
|
306
|
+
canonical = Lutaml::Formatter::Canonical.new(entry.model).render
|
|
307
|
+
return [] if canonical == entry.text
|
|
308
|
+
|
|
309
|
+
[{ range: full_range(entry.text), newText: canonical }]
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
def full_range(text)
|
|
313
|
+
{
|
|
314
|
+
start: { line: 0, character: 0 },
|
|
315
|
+
end: { line: text.lines.length, character: 0 },
|
|
316
|
+
}
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
# ---- helpers ----
|
|
320
|
+
|
|
321
|
+
def entry_for(params)
|
|
322
|
+
document = params["textDocument"] || {}
|
|
323
|
+
@store[document["uri"]]
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
def location(uri, position)
|
|
327
|
+
{ uri: uri, range: Conversions.range(position) }
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
def resolve(index, token)
|
|
331
|
+
symbols = index.definitions(token)
|
|
332
|
+
return symbols unless symbols.empty?
|
|
333
|
+
|
|
334
|
+
token.split(".").flat_map { |segment| index.definitions(segment) }.uniq
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
def token_at(entry, position)
|
|
338
|
+
line = entry.text.lines[position["line"].to_i].to_s
|
|
339
|
+
index = [position["character"].to_i, line.length].min
|
|
340
|
+
start = index
|
|
341
|
+
start -= 1 while start.positive? && line[start - 1].match?(WORD)
|
|
342
|
+
finish = index
|
|
343
|
+
finish += 1 while finish < line.length && line[finish].match?(WORD)
|
|
344
|
+
line[start...finish].to_s
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
def token_range(entry, position, token)
|
|
348
|
+
line = entry.text.lines[position["line"].to_i].to_s
|
|
349
|
+
finish = [position["character"].to_i, line.length].min
|
|
350
|
+
start = [finish - token.length, 0].max
|
|
351
|
+
{
|
|
352
|
+
start: { line: position["line"].to_i, character: start },
|
|
353
|
+
end: { line: position["line"].to_i, character: start + token.length },
|
|
354
|
+
}
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
def completion_prefix(entry, position)
|
|
358
|
+
return "" unless entry
|
|
359
|
+
|
|
360
|
+
line = entry.text.lines[position["line"].to_i].to_s
|
|
361
|
+
before = line[0...[position["character"].to_i, line.length].min].to_s
|
|
362
|
+
before[/[A-Za-z0-9_]*\z/].to_s
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
def respond(id, result)
|
|
366
|
+
return if id.nil?
|
|
367
|
+
|
|
368
|
+
@transport.write_message(jsonrpc: "2.0", id: id, result: result)
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
def respond_error(id, code, message)
|
|
372
|
+
@transport.write_message(
|
|
373
|
+
jsonrpc: "2.0", id: id,
|
|
374
|
+
error: { code: code, message: message }
|
|
375
|
+
)
|
|
376
|
+
end
|
|
377
|
+
end
|
|
378
|
+
end
|
|
379
|
+
end
|
|
380
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
module Lsp
|
|
6
|
+
# The open-document store. Every change reparses the full text
|
|
7
|
+
# (full-document sync) and recomputes diagnostics.
|
|
8
|
+
class Store
|
|
9
|
+
Entry = Struct.new(:uri, :text, :version, :model, :diagnostics,
|
|
10
|
+
keyword_init: true)
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
@entries = {}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def open(uri:, text:, version: nil)
|
|
17
|
+
entry = Entry.new(uri: uri, text: text, version: version)
|
|
18
|
+
parse(entry)
|
|
19
|
+
@entries[uri] = entry
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def change(uri:, text:, version: nil)
|
|
23
|
+
entry = @entries[uri]
|
|
24
|
+
return nil unless entry
|
|
25
|
+
|
|
26
|
+
entry.text = text
|
|
27
|
+
entry.version = version
|
|
28
|
+
parse(entry)
|
|
29
|
+
entry
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def close(uri)
|
|
33
|
+
@entries.delete(uri)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def [](uri)
|
|
37
|
+
@entries[uri]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def parse(entry)
|
|
43
|
+
path = Conversions.uri_to_path(entry.uri)
|
|
44
|
+
entry.model = Lutaml::Lml.parse_document(entry.text)
|
|
45
|
+
entry.model.source_path = path
|
|
46
|
+
entry.diagnostics = Validator.diagnostics(entry.model)
|
|
47
|
+
rescue Lutaml::Lml::Error => e
|
|
48
|
+
entry.model = nil
|
|
49
|
+
entry.diagnostics = [diagnostic_for(e, path)]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def diagnostic_for(error, path)
|
|
53
|
+
record = error.diagnostic
|
|
54
|
+
return record if record&.file
|
|
55
|
+
|
|
56
|
+
Diagnostic.build(
|
|
57
|
+
record&.code || "parse/LML-001",
|
|
58
|
+
message: record&.message || error.message.lines.first.to_s.strip,
|
|
59
|
+
file: path,
|
|
60
|
+
line: record&.line,
|
|
61
|
+
column: record&.column,
|
|
62
|
+
length: record&.length,
|
|
63
|
+
)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
5
|
+
module Lutaml
|
|
6
|
+
module Lml
|
|
7
|
+
module Lsp
|
|
8
|
+
# LSP base protocol framing: `Content-Length: N\r\n\r\n<json>`.
|
|
9
|
+
# Reads one message at a time and writes responses to the output
|
|
10
|
+
# stream. stdout is the protocol channel; stderr is for logging.
|
|
11
|
+
class Transport
|
|
12
|
+
def initialize(input: $stdin, output: $stdout)
|
|
13
|
+
@input = input
|
|
14
|
+
@output = output
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def read_message
|
|
18
|
+
headers = read_headers
|
|
19
|
+
return nil unless headers
|
|
20
|
+
|
|
21
|
+
length = headers["content-length"]
|
|
22
|
+
return nil unless length
|
|
23
|
+
|
|
24
|
+
body = @input.read(length.to_i)
|
|
25
|
+
body.nil? || body.empty? ? nil : JSON.parse(body)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def write_message(payload)
|
|
29
|
+
body = JSON.generate(payload)
|
|
30
|
+
@output.write("Content-Length: #{body.bytesize}\r\n\r\n#{body}")
|
|
31
|
+
@output.flush
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def read_headers
|
|
37
|
+
headers = {}
|
|
38
|
+
loop do
|
|
39
|
+
line = @input.gets
|
|
40
|
+
return nil if line.nil?
|
|
41
|
+
|
|
42
|
+
line = line.chomp
|
|
43
|
+
break if line.empty?
|
|
44
|
+
|
|
45
|
+
key, value = line.split(":", 2)
|
|
46
|
+
headers[key.to_s.strip.downcase] = value.to_s.strip
|
|
47
|
+
end
|
|
48
|
+
headers
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
# Language Server Protocol support: a stdio JSON-RPC server exposing
|
|
6
|
+
# diagnostics, symbols, navigation, hover, completion, and canonical
|
|
7
|
+
# formatting over the parsed document model.
|
|
8
|
+
module Lsp
|
|
9
|
+
autoload :Transport, "lutaml/lml/lsp/transport"
|
|
10
|
+
autoload :Server, "lutaml/lml/lsp/server"
|
|
11
|
+
autoload :Store, "lutaml/lml/lsp/store"
|
|
12
|
+
autoload :Keywords, "lutaml/lml/lsp/keywords"
|
|
13
|
+
autoload :Conversions, "lutaml/lml/lsp/conversions"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|