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
28 changes: 21 additions & 7 deletions rust/src/analyzer/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ pub(crate) fn process_needs_child(
} => {
let recv_vtx = super::install::install_node(genv, lenv, changes, source, &receiver)?;
process_method_call_common(
genv, lenv, changes, source, recv_vtx, method_name, location, block, arguments,
genv, lenv, changes, source,
MethodCallContext { recv_vtx, method_name, location, block, arguments },
)
}
NeedsChildKind::ImplicitSelfCall {
Expand All @@ -253,7 +254,8 @@ pub(crate) fn process_needs_child(
genv.new_source(Type::instance("Object"))
};
process_method_call_common(
genv, lenv, changes, source, recv_vtx, method_name, location, block, arguments,
genv, lenv, changes, source,
MethodCallContext { recv_vtx, method_name, location, block, arguments },
)
}
NeedsChildKind::AttrDeclaration { kind, attr_names } => {
Expand All @@ -279,19 +281,31 @@ fn finish_local_var_write(
install_local_var_write(genv, lenv, changes, var_name, value_vtx)
}

/// Bundled parameters for method call processing
struct MethodCallContext<'a> {
recv_vtx: VertexId,
method_name: String,
location: SourceLocation,
block: Option<Node<'a>>,
arguments: Vec<Node<'a>>,
}

/// MethodCall / ImplicitSelfCall common processing:
/// Handles argument processing, block processing, and MethodCallBox creation after recv_vtx is obtained
fn process_method_call_common<'a>(
genv: &mut GlobalEnv,
lenv: &mut LocalEnv,
changes: &mut ChangeSet,
source: &str,
recv_vtx: VertexId,
method_name: String,
location: SourceLocation,
block: Option<Node<'a>>,
arguments: Vec<Node<'a>>,
ctx: MethodCallContext<'a>,
) -> Option<VertexId> {
let MethodCallContext {
recv_vtx,
method_name,
location,
block,
arguments,
} = ctx;
if method_name == "!" {
return Some(super::operators::process_not_operator(genv));
}
Expand Down
1 change: 0 additions & 1 deletion rust/src/cache/rbs_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ impl SerializableMethodInfo {
}
}

#[allow(dead_code)]
impl RbsCache {
/// Get user cache file path (in ~/.cache/methodray/)
pub fn cache_path() -> Result<PathBuf> {
Expand Down
6 changes: 3 additions & 3 deletions rust/src/cli/commands.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//! CLI command implementations

use anyhow::Result;
use std::path::PathBuf;
use std::path::Path;

use crate::cache::RbsCache;
use crate::checker::FileChecker;
use crate::diagnostics;

/// Check a single Ruby file for type errors
/// Returns Ok(true) if no errors, Ok(false) if errors found
pub fn check_single_file(file_path: &PathBuf, verbose: bool) -> Result<bool> {
pub fn check_single_file(file_path: &Path, verbose: bool) -> Result<bool> {
let checker = FileChecker::new()?;
let diagnostics = checker.check_file(file_path)?;

Expand Down Expand Up @@ -38,7 +38,7 @@ pub fn check_project(_verbose: bool) -> Result<()> {
}

/// Watch a file for changes and re-check on modifications
pub fn watch_file(file_path: &PathBuf) -> Result<()> {
pub fn watch_file(file_path: &Path) -> Result<()> {
use notify::{Config, RecommendedWatcher, RecursiveMode, Watcher};
use std::sync::mpsc::channel;
use std::time::Duration;
Expand Down
3 changes: 0 additions & 3 deletions rust/src/diagnostics/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::path::PathBuf;

/// Diagnostic severity level (LSP compatible)
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(dead_code)]
pub enum DiagnosticLevel {
Error,
Warning,
Expand All @@ -28,15 +27,13 @@ pub struct Location {

/// Type checking diagnostic
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct Diagnostic {
pub location: Location,
pub level: DiagnosticLevel,
pub message: String,
pub code: Option<String>, // e.g., "E001"
}

#[allow(dead_code)]
impl Diagnostic {
/// Create an error diagnostic
pub fn error(location: Location, message: String) -> Self {
Expand Down
1 change: 0 additions & 1 deletion rust/src/diagnostics/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::path::Path;
/// ```text
/// app/models/user.rb:10:5: error: undefined method `upcase` for Integer
/// ```
#[allow(dead_code)]
pub fn format_diagnostics(diagnostics: &[Diagnostic]) -> String {
diagnostics
.iter()
Expand Down
6 changes: 2 additions & 4 deletions rust/src/env/box_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::graph::{BoxId, BoxTrait};
use std::collections::{HashMap, HashSet, VecDeque};

/// Manages boxes and their execution queue
#[allow(dead_code)]
pub struct BoxManager {
/// All registered boxes
pub boxes: HashMap<BoxId, Box<dyn BoxTrait>>,
Expand All @@ -24,7 +23,6 @@ impl Default for BoxManager {
}
}

#[allow(dead_code)]
impl BoxManager {
/// Create a new empty box manager
pub fn new() -> Self {
Expand All @@ -37,8 +35,8 @@ impl BoxManager {
}

/// Get a box by ID
pub fn get(&self, id: BoxId) -> Option<&Box<dyn BoxTrait>> {
self.boxes.get(&id)
pub fn get(&self, id: BoxId) -> Option<&dyn BoxTrait> {
self.boxes.get(&id).map(|b| b.as_ref())
}

/// Remove a box and return it (for temporary mutation)
Expand Down
1 change: 0 additions & 1 deletion rust/src/env/global_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ pub struct GlobalEnv {
pub scope_manager: ScopeManager,
}

#[allow(dead_code)]
impl GlobalEnv {
pub fn new() -> Self {
Self {
Expand Down
13 changes: 12 additions & 1 deletion rust/src/env/local_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ pub struct LocalEnv {
locals: HashMap<String, VertexId>,
}

#[allow(dead_code)]
impl Default for LocalEnv {
fn default() -> Self {
Self::new()
}
}

impl LocalEnv {
pub fn new() -> Self {
Self {
Expand Down Expand Up @@ -40,6 +45,12 @@ impl LocalEnv {
mod tests {
use super::*;

#[test]
fn test_local_env_default() {
let lenv = LocalEnv::default();
assert_eq!(lenv.get_var("x"), None);
}

#[test]
fn test_local_env() {
let mut lenv = LocalEnv::new();
Expand Down
17 changes: 13 additions & 4 deletions rust/src/env/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub struct ScopeId(pub usize);

/// Scope kind
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub enum ScopeKind {
TopLevel,
Class {
Expand All @@ -27,7 +26,6 @@ pub enum ScopeKind {

/// Scope information
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct Scope {
pub id: ScopeId,
pub kind: ScopeKind,
Expand All @@ -46,7 +44,6 @@ pub struct Scope {
pub constants: HashMap<String, String>,
}

#[allow(dead_code)]
impl Scope {
pub fn new(id: ScopeId, kind: ScopeKind, parent: Option<ScopeId>) -> Self {
Self {
Expand Down Expand Up @@ -89,7 +86,12 @@ pub struct ScopeManager {
current_scope: ScopeId,
}

#[allow(dead_code)]
impl Default for ScopeManager {
fn default() -> Self {
Self::new()
}
}

impl ScopeManager {
pub fn new() -> Self {
let top_level = Scope::new(ScopeId(0), ScopeKind::TopLevel, None);
Expand Down Expand Up @@ -278,6 +280,13 @@ impl ScopeManager {
mod tests {
use super::*;

#[test]
fn test_scope_manager_default() {
let sm = ScopeManager::default();
assert_eq!(sm.current_scope().id, ScopeId(0));
assert!(matches!(sm.current_scope().kind, ScopeKind::TopLevel));
}

#[test]
fn test_scope_manager_creation() {
let sm = ScopeManager::new();
Expand Down
1 change: 0 additions & 1 deletion rust/src/env/vertex_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub struct VertexManager {
next_vertex_id: usize,
}

#[allow(dead_code)]
impl VertexManager {
/// Create a new empty vertex manager
pub fn new() -> Self {
Expand Down
3 changes: 0 additions & 3 deletions rust/src/graph/box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::types::Type;
pub struct BoxId(pub usize);

/// Box trait: represents constraints such as method calls
#[allow(dead_code)]
pub trait BoxTrait: Send + Sync {
fn id(&self) -> BoxId;
fn run(&mut self, genv: &mut GlobalEnv, changes: &mut ChangeSet);
Expand Down Expand Up @@ -47,7 +46,6 @@ fn propagate_keyword_arguments(
}

/// Box representing a method call
#[allow(dead_code)]
pub struct MethodCallBox {
id: BoxId,
recv: VertexId,
Expand Down Expand Up @@ -199,7 +197,6 @@ impl BoxTrait for MethodCallBox {
/// When a method with a block is called (e.g., `str.each_char { |c| ... }`),
/// this box resolves the block parameter types from the method's RBS definition
/// and propagates them to the block parameter vertices.
#[allow(dead_code)]
pub struct BlockParameterTypeBox {
id: BoxId,
/// Receiver vertex of the method call
Expand Down
14 changes: 14 additions & 0 deletions rust/src/graph/change_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ pub struct ChangeSet {
reschedule_boxes: Vec<BoxId>,
}

impl Default for ChangeSet {
fn default() -> Self {
Self::new()
}
}

impl ChangeSet {
pub fn new() -> Self {
Self {
Expand Down Expand Up @@ -75,6 +81,14 @@ pub enum EdgeUpdate {
mod tests {
use super::*;

#[test]
fn test_change_set_default() {
let mut cs = ChangeSet::default();
cs.add_edge(VertexId(1), VertexId(2));
let updates = cs.reinstall();
assert_eq!(updates.len(), 1);
}

#[test]
fn test_change_set_add() {
let mut cs = ChangeSet::new();
Expand Down
2 changes: 1 addition & 1 deletion rust/src/lsp/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub async fn run_server() {
let stdin = tokio::io::stdin();
let stdout = tokio::io::stdout();

let (service, socket) = LspService::new(|client| MethodRayServer::new(client));
let (service, socket) = LspService::new(MethodRayServer::new);

Server::new(stdin, stdout, socket).serve(service).await;
}
3 changes: 1 addition & 2 deletions rust/src/rbs/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ pub fn register_rbs_methods(genv: &mut GlobalEnv, ruby: &Ruby) -> Result<usize,
cache.to_method_infos()
} else {
eprintln!("Cache invalid, reloading from RBS...");
let methods = load_and_cache_rbs_methods(ruby, methodray_version, &rbs_version)?;
methods
load_and_cache_rbs_methods(ruby, methodray_version, &rbs_version)?
}
} else {
eprintln!("No cache found, loading from RBS...");
Expand Down
1 change: 0 additions & 1 deletion rust/src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub struct SourceLocation {
pub length: usize,
}

#[allow(dead_code)]
impl SourceLocation {
pub fn new(line: usize, column: usize, length: usize) -> Self {
Self {
Expand Down
1 change: 0 additions & 1 deletion rust/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ impl From<String> for QualifiedName {

/// Type system for graph-based type inference
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[allow(dead_code)]
pub enum Type {
/// Instance type: String, Integer, Api::User, etc.
Instance { name: QualifiedName },
Expand Down