Skip to main content

ontocore_refactor/
model.rs

1use serde::{Deserialize, Serialize};
2use std::path::PathBuf;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
5#[serde(rename_all = "snake_case")]
6pub enum UsageKind {
7    EntityDeclaration,
8    AxiomSubject,
9    AxiomObject,
10    AnnotationSubject,
11    AnnotationObject,
12    Import,
13    TextReference,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct Usage {
18    pub iri: String,
19    pub referenced_iri: String,
20    pub file: PathBuf,
21    pub line: Option<u64>,
22    pub column: Option<u64>,
23    pub start_byte: Option<u64>,
24    pub end_byte: Option<u64>,
25    pub kind: UsageKind,
26    pub context: String,
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct Hunk {
31    pub start_byte: u64,
32    pub end_byte: u64,
33    pub old_text: String,
34    pub new_text: String,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct FileChange {
39    pub path: PathBuf,
40    pub preview_text: String,
41    pub original_text: String,
42    #[serde(default, skip_serializing_if = "Vec::is_empty")]
43    pub hunks: Vec<Hunk>,
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct RefactorPlan {
48    pub changes: Vec<FileChange>,
49    #[serde(default, skip_serializing_if = "Vec::is_empty")]
50    pub warnings: Vec<String>,
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(tag = "kind", rename_all = "snake_case")]
55pub enum RefactorRequest {
56    RenameIri {
57        from_iri: String,
58        to_iri: String,
59    },
60    MergeEntities {
61        keep_iri: String,
62        merge_iri: String,
63    },
64    ReplaceEntity {
65        from_iri: String,
66        to_iri: String,
67    },
68    MigrateNamespace {
69        from_base: String,
70        to_base: String,
71    },
72    MoveEntity {
73        entity_iri: String,
74        target_file: PathBuf,
75    },
76    ExtractModule {
77        entity_iris: Vec<String>,
78        output_file: PathBuf,
79        #[serde(default)]
80        leave_stub: bool,
81    },
82}