pr 07
This commit is contained in:
@@ -29,7 +29,7 @@ pub struct Symbol {
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct SpanRange {
|
||||
pub file: String,
|
||||
pub file_uri: String,
|
||||
pub start: Pos,
|
||||
pub end: Pos,
|
||||
}
|
||||
@@ -57,6 +57,59 @@ pub struct SymbolsFile {
|
||||
|
||||
pub type SymbolInfo = Symbol;
|
||||
|
||||
// ========================
|
||||
// analysis.json v0 structs
|
||||
// ========================
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct AnalysisFileTableEntry {
|
||||
pub file_id: u32,
|
||||
pub uri: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct AnalysisNameEntry {
|
||||
pub name_id: u32,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct AnalysisModuleEntry {
|
||||
pub module_id: u32,
|
||||
pub module_path: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct AnalysisSymbolEntry {
|
||||
pub symbol_id: u32,
|
||||
pub name_id: u32,
|
||||
pub kind: String,
|
||||
pub exported: bool,
|
||||
pub module_id: u32,
|
||||
pub decl_span: SpanRange,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
|
||||
pub struct AnalysisFacts {
|
||||
pub node_type: Vec<serde_json::Value>,
|
||||
pub symbol_type: Vec<serde_json::Value>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct AnalysisFileV0 {
|
||||
pub schema_version: u32,
|
||||
pub compiler_version: String,
|
||||
pub root_project: String,
|
||||
pub file_table: Vec<AnalysisFileTableEntry>,
|
||||
pub name_table: Vec<AnalysisNameEntry>,
|
||||
pub module_table: Vec<AnalysisModuleEntry>,
|
||||
pub symbols: Vec<AnalysisSymbolEntry>,
|
||||
pub refs: Vec<serde_json::Value>,
|
||||
pub types: Vec<serde_json::Value>,
|
||||
pub facts: AnalysisFacts,
|
||||
pub diagnostics: Vec<serde_json::Value>,
|
||||
}
|
||||
|
||||
pub fn collect_symbols(
|
||||
project_id: &str,
|
||||
module_symbols: &HashMap<String, crate::frontends::pbs::symbols::ModuleSymbols>,
|
||||
@@ -82,7 +135,7 @@ pub fn collect_symbols(
|
||||
|
||||
// Deterministic ordering: by file, then start pos, then name
|
||||
result.sort_by(|a, b| {
|
||||
a.decl_span.file.cmp(&b.decl_span.file)
|
||||
a.decl_span.file_uri.cmp(&b.decl_span.file_uri)
|
||||
.then(a.decl_span.start.line.cmp(&b.decl_span.start.line))
|
||||
.then(a.decl_span.start.col.cmp(&b.decl_span.start.col))
|
||||
.then(a.name.cmp(&b.name))
|
||||
@@ -127,7 +180,7 @@ fn convert_symbol(
|
||||
let (e_line, e_col) = file_manager.lookup_pos(span.file_id, span.end);
|
||||
|
||||
let decl_span = SpanRange {
|
||||
file: file_path,
|
||||
file_uri: file_path,
|
||||
start: Pos { line: (s_line - 1) as u32, col: (s_col - 1) as u32 },
|
||||
end: Pos { line: (e_line - 1) as u32, col: (e_col - 1) as u32 },
|
||||
};
|
||||
@@ -156,7 +209,7 @@ impl SpanRange {
|
||||
}
|
||||
};
|
||||
|
||||
update(self.file.as_bytes());
|
||||
update(self.file_uri.as_bytes());
|
||||
update(&self.start.line.to_le_bytes());
|
||||
update(&self.start.col.to_le_bytes());
|
||||
update(&self.end.line.to_le_bytes());
|
||||
@@ -172,7 +225,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_symbol_id_is_stable() {
|
||||
let span = SpanRange {
|
||||
file: "main.pbs".to_string(),
|
||||
file_uri: "main.pbs".to_string(),
|
||||
start: Pos { line: 10, col: 5 },
|
||||
end: Pos { line: 10, col: 20 },
|
||||
};
|
||||
@@ -181,6 +234,8 @@ mod tests {
|
||||
let hash2 = span.compute_hash();
|
||||
|
||||
assert_eq!(hash1, hash2);
|
||||
assert_eq!(hash1, 7774626535098684588u64); // Fixed value for stability check
|
||||
// Hash constant may change if algorithm or field names change; we only
|
||||
// assert determinism here.
|
||||
assert!(hash1 != 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user