Skip to content
Draft
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
5 changes: 3 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
{
"version": "1.0.0",
"configurations": [

{
"name": "Launch Server (lldb)",
"type": "lldb",
"request": "launch",
"args": ["--use-tcp"],
"args": ["--use-tcp", "--spy"],
"cargo": {
"args": [
"build"
Expand All @@ -33,7 +34,7 @@
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceRoot}/server/target/debug/odoo_ls_server.exe",
"args": ["--use-tcp"],
"args": ["--use-tcp", "--spy"],
"cwd": "${workspaceFolder}/server",
"console": "externalTerminal",
"preLaunchTask": "cargo build"
Expand Down
3 changes: 3 additions & 0 deletions server/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ pub struct Cli {
#[arg(long)]
pub config_path: Option<String>,

//enable connection on localhost:8072 for odoo-ls-spy debugging tool
#[arg(long)]
pub spy: bool,
}

#[derive(ValueEnum, Clone, Debug)]
Expand Down
12 changes: 12 additions & 0 deletions server/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ impl From<i32> for BuildSteps {
}
}

impl fmt::Display for BuildSteps {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}

#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum BuildStatus {
PENDING,
Expand All @@ -105,6 +111,12 @@ pub enum BuildStatus {
DONE
}

impl fmt::Display for BuildStatus {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}

pub const BUILT_IN_LIBS: &[&str] = &["string", "re", "difflib", "textwrap", "unicodedata", "stringprep", "readline", "rlcompleter",
"datetime", "zoneinfo", "calendar", "collections", "heapq", "bisect", "array", "weakref", "types", "copy", "pprint",
"reprlib", "enum", "graphlib", "numbers", "math", "cmath", "decimal", "fractions", "random", "statistics", "itertools",
Expand Down
4 changes: 4 additions & 0 deletions server/src/core/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ impl Model {
res
}

pub fn get_name(&self) -> String {
self.name.to_string()
}

pub fn add_symbol(&mut self, session: &mut SessionInfo, symbol: Rc<RefCell<Symbol>>) {
if self.symbols.contains(&symbol) {
return;
Expand Down
13 changes: 13 additions & 0 deletions server/src/core/symbols/class_symbol.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use ruff_text_size::{TextRange, TextSize};
use serde_json::json;
use std::collections::HashMap;
use std::rc::{Rc, Weak};
use std::cell::RefCell;
Expand Down Expand Up @@ -122,4 +123,16 @@ impl ClassSymbol {
result
}

pub fn to_json(&self) -> serde_json::Value {
json!({
"type": SymType::CLASS.to_string(),
"doc_string": self.doc_string,
"is_external": self.is_external,
"range": json!({
"start": self.range.start().to_u32(),
"end": self.range.end().to_u32(),
})
})
}

}
18 changes: 17 additions & 1 deletion server/src/core/symbols/compiled_symbol.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::{cell::RefCell, collections::HashMap, rc::{Rc, Weak}};

use serde_json::json;
use weak_table::PtrWeakHashSet;

use crate::constants::OYarn;
use crate::constants::{OYarn, SymType};

use super::symbol::Symbol;

Expand Down Expand Up @@ -35,4 +36,19 @@ impl CompiledSymbol {
self.module_symbols.insert(compiled.borrow().name().clone(), compiled.clone());
}

pub fn to_json(&self) -> serde_json::Value {
let module_sym: Vec<serde_json::Value> = self.module_symbols.values().map(|sym| {
json!({
"name": sym.borrow().name().to_string(),
"type": sym.borrow().typ().to_string(),
})
}).collect();
json!({
"type": SymType::COMPILED.to_string(),
"path": self.path,
"is_external": self.is_external,
"module_symbols": module_sym,
})
}

}
49 changes: 48 additions & 1 deletion server/src/core/symbols/csv_file_symbol.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use serde_json::json;
use weak_table::PtrWeakHashSet;

use crate::{constants::{BuildStatus, BuildSteps, OYarn}, core::{file_mgr::NoqaInfo, model::Model, xml_data::OdooData}, oyarn};
use crate::{constants::{BuildStatus, BuildSteps, OYarn, SymType}, core::{file_mgr::NoqaInfo, model::Model, xml_data::OdooData}, oyarn, tool_api::to_json::{dependencies_to_json, dependents_to_json}};
use std::{cell::RefCell, collections::HashMap, rc::{Rc, Weak}};

use super::{symbol::Symbol, symbol_mgr::SectionRange};
Expand Down Expand Up @@ -142,4 +143,50 @@ impl CsvFileSymbol {
self.in_workspace
}

pub fn to_json(&self) -> serde_json::Value {
json!({
"type": SymType::CSV_FILE.to_string(),
"path": self.path,
"is_external": self.is_external,
"in_workspace": self.in_workspace,
"arch_status": self.arch_status.to_string(),
"validation_status": self.validation_status.to_string(),
"not_found_paths": self.not_found_paths.iter().map(|(step, paths)| {
json!({
"step": step.to_string(),
"paths": paths.into_iter().map(|x| x.to_string()).collect::<Vec<String>>(),
})
}).collect::<Vec<serde_json::Value>>(),
"self_import": self.self_import,
"model_dependencies": self.model_dependencies.iter().map(|x| json!(x.borrow().get_name())).collect::<Vec<serde_json::Value>>(),
"dependencies": dependencies_to_json(&self.dependencies),
"dependents": dependents_to_json(&self.dependents),
"processed_text_hash": self.processed_text_hash,

"sections": self.sections.iter().map(|x| {
json!({
"start": x.start,
"index": x.index,
})
}).collect::<Vec<serde_json::Value>>(),
"symbols": self.symbols.iter().map(|(name, sections)| {
json!({
"name": name.to_string(),
"sections": sections.iter().map(|(section, symbols)| {
json!({
"section": section,
"symbols": symbols.iter().map(|sym| json!(sym.borrow().name().to_string())).collect::<Vec<serde_json::Value>>(),
})
}).collect::<Vec<serde_json::Value>>(),
})
}).collect::<Vec<serde_json::Value>>(),
"ext_symbols": self.ext_symbols.iter().map(|(name, symbols)| {
json!({
"name": name.to_string(),
"symbols": symbols.iter().map(|sym| json!(sym.borrow().name().to_string())).collect::<Vec<serde_json::Value>>(),
})
}).collect::<Vec<serde_json::Value>>(),
})
}

}
20 changes: 19 additions & 1 deletion server/src/core/symbols/disk_dir_symbol.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

use std::{cell::RefCell, collections::HashMap, path::PathBuf, rc::{Rc, Weak}};

use crate::{constants::OYarn, oyarn, utils::PathSanitizer};
use serde_json::json;

use crate::{constants::{OYarn, SymType}, oyarn, utils::PathSanitizer};

use super::symbol::Symbol;

Expand Down Expand Up @@ -40,4 +42,20 @@ impl DiskDirSymbol {
/*pub fn load(sesion: &mut SessionInfo, dir: &Rc<RefCell<Symbol>>) -> Rc<RefCell<Symbol>> {
let path = dir.borrow().as_disk_dir_sym().path.clone();
}*/

pub fn to_json(&self) -> serde_json::Value {
let module_sym: Vec<serde_json::Value> = self.module_symbols.values().map(|sym| {
json!({
"name": sym.borrow().name().to_string(),
"type": sym.borrow().typ().to_string(),
})
}).collect();
json!({
"type": SymType::DISK_DIR.to_string(),
"path": self.path,
"is_external": self.is_external,
"in_workspace": self.in_workspace,
"module_symbols": module_sym,
})
}
}
50 changes: 49 additions & 1 deletion server/src/core/symbols/file_symbol.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use serde_json::json;
use weak_table::{PtrWeakHashSet, PtrWeakKeyHashMap};

use crate::{constants::{BuildStatus, BuildSteps, OYarn}, core::{file_mgr::NoqaInfo, model::Model, xml_data::OdooData}, oyarn};
use crate::{constants::{BuildStatus, BuildSteps, OYarn, SymType}, core::{file_mgr::NoqaInfo, model::Model, xml_data::OdooData}, oyarn, tool_api::to_json::{dependencies_to_json, dependents_to_json}};
use std::{cell::RefCell, collections::HashMap, rc::{Rc, Weak}};

use super::{symbol::Symbol, symbol_mgr::{SectionRange, SymbolMgr}};
Expand Down Expand Up @@ -169,4 +170,51 @@ impl FileSymbol {
result
}

pub fn to_json(&self) -> serde_json::Value {
json!({
"type": SymType::FILE.to_string(),
"path": self.path,
"is_external": self.is_external,
"in_workspace": self.in_workspace,
"arch_status": self.arch_status.to_string(),
"arch_eval_status": self.arch_eval_status.to_string(),
"validation_status": self.validation_status.to_string(),
"not_found_paths": self.not_found_paths.iter().map(|(step, paths)| {
json!({
"step": step.to_string(),
"paths": paths.into_iter().map(|x| x.to_string()).collect::<Vec<String>>(),
})
}).collect::<Vec<serde_json::Value>>(),
"self_import": self.self_import,
"model_dependencies": self.model_dependencies.iter().map(|x| json!(x.borrow().get_name())).collect::<Vec<serde_json::Value>>(),
"dependencies": dependencies_to_json(&self.dependencies),
"dependents": dependents_to_json(&self.dependents),
"processed_text_hash": self.processed_text_hash,

"sections": self.sections.iter().map(|x| {
json!({
"start": x.start,
"index": x.index,
})
}).collect::<Vec<serde_json::Value>>(),
"symbols": self.symbols.iter().map(|(name, sections)| {
json!({
"name": name.to_string(),
"sections": sections.iter().map(|(section, symbols)| {
json!({
"section": section,
"symbols": symbols.iter().map(|sym| json!(sym.borrow().name().to_string())).collect::<Vec<serde_json::Value>>(),
})
}).collect::<Vec<serde_json::Value>>(),
})
}).collect::<Vec<serde_json::Value>>(),
"ext_symbols": self.ext_symbols.iter().map(|(name, symbols)| {
json!({
"name": name.to_string(),
"symbols": symbols.iter().map(|sym| json!(sym.borrow().name().to_string())).collect::<Vec<serde_json::Value>>(),
})
}).collect::<Vec<serde_json::Value>>(),
})
}

}
14 changes: 14 additions & 0 deletions server/src/core/symbols/function_symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{cell::RefCell, collections::HashMap, rc::{Rc, Weak}};
use lsp_types::Diagnostic;
use ruff_python_ast::{AtomicNodeIndex, Expr, ExprCall};
use ruff_text_size::{TextRange, TextSize};
use serde_json::json;
use weak_table::{PtrWeakHashSet, PtrWeakKeyHashMap};

use crate::{constants::{BuildStatus, BuildSteps, OYarn, SymType}, core::{evaluation::{Context, Evaluation}, file_mgr::NoqaInfo, model::Model}, oyarn, threads::SessionInfo};
Expand Down Expand Up @@ -210,4 +211,17 @@ impl FunctionSymbol {
}
result
}

pub fn to_json(&self) -> serde_json::Value {
json!({
"type": SymType::FUNCTION.to_string(),
"doc_string": self.doc_string,
"is_external": self.is_external,
"range": json!({
"start": self.range.start().to_u32(),
"end": self.range.end().to_u32(),
}),
"evaluations": self.evaluations.iter().map(|eval| json!("to implement")).collect::<Vec<serde_json::Value>>(),
})
}
}
17 changes: 17 additions & 0 deletions server/src/core/symbols/module_symbol.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use lsp_types::{Diagnostic, DiagnosticTag, Position, Range};
use ruff_python_ast::{Expr, Stmt};
use ruff_text_size::{Ranged, TextRange};
use serde_json::json;
use tracing::{error, info};
use weak_table::{PtrWeakHashSet, PtrWeakKeyHashMap};
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -589,4 +590,20 @@ impl ModuleSymbol {
res
}

pub fn to_json(&self) -> serde_json::Value {
let module_sym: Vec<serde_json::Value> = self.module_symbols.values().map(|sym| {
json!({
"name": sym.borrow().name().to_string(),
"type": sym.borrow().typ().to_string(),
})
}).collect();
json!({
"type": "MODULE_PACKAGE",
"path": self.path,
"is_external": self.is_external,
"in_workspace": self.in_workspace,
"module_symbols": module_sym,
})
}

}
27 changes: 26 additions & 1 deletion server/src/core/symbols/namespace_symbol.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use serde_json::json;
use weak_table::PtrWeakHashSet;

use std::{cell::RefCell, collections::HashMap, path::PathBuf, rc::{Rc, Weak}};

use crate::constants::OYarn;
use crate::{constants::{OYarn, SymType}, tool_api::to_json::{dependencies_to_json, dependents_to_json}};

use super::symbol::Symbol;

Expand Down Expand Up @@ -144,6 +145,30 @@ impl NamespaceSymbol {
pub fn is_in_workspace(&self) -> bool {
self.in_workspace
}

pub fn to_json(&self) -> serde_json::Value {
let mut directories = vec![];
for directory in self.directories.iter() {
let module_sym: Vec<serde_json::Value> = directory.module_symbols.values().map(|sym| {
json!({
"name": sym.borrow().name().to_string(),
"type": sym.borrow().typ().to_string(),
})
}).collect();
directories.push(json!({
"path": directory.path,
"module_symbols": module_sym,
}));
}
json!({
"type": SymType::NAMESPACE.to_string(),
"is_external": self.is_external,
"in_workspace": self.in_workspace,
"directories": directories,
"dependencies": dependencies_to_json(&self.dependencies),
"dependents": dependents_to_json(&self.dependents),
})
}

pub fn get_ext_symbol(&self, name: &OYarn) -> Vec<Rc<RefCell<Symbol>>> {
let mut result = vec![];
Expand Down
Loading