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
10 changes: 6 additions & 4 deletions cli/src/commands/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use crate::artifacts::ArtifactManager;
use crate::exit_code::ExitCode;
use std::fmt::Write;
use std::path::{Path, PathBuf};
use techscript_package_manager::DocExtractor;

Expand Down Expand Up @@ -55,14 +56,15 @@ pub fn execute(path_str: Option<&str>) -> ExitCode {

// Build structured output
let mut md_content = String::new();
md_content.push_str(&format!(
let _ = write!(
md_content,
"# API Documentation β€” {}\n\n",
path.file_name().unwrap_or_default().to_string_lossy()
));
);

for item in &doc_items {
md_content.push_str(&format!("## {}\n\n", item.name));
md_content.push_str(&format!("{}\n\n", item.doc));
let _ = write!(md_content, "## {}\n\n", item.name);
let _ = write!(md_content, "{}\n\n", item.doc);
md_content.push_str("---\n\n");
}

Expand Down
3 changes: 2 additions & 1 deletion cli/src/commands/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! Automatically migrates legacy TechScript 1.0.8 code to TechScript 2.0 canonical syntax.

use crate::exit_code::ExitCode;
use std::fmt::Write;
use std::path::PathBuf;

pub fn execute(path_str: Option<&str>) -> ExitCode {
Expand Down Expand Up @@ -263,7 +264,7 @@ fn replace_call(source: &str, prefix: &str, keyword: &str) -> String {
remaining = &remaining[pos + full.len()..];
if let Some(close) = remaining.find(')') {
let args = &remaining[..close];
result.push_str(&format!("{keyword} {args}"));
let _ = write!(result, "{keyword} {args}");
remaining = &remaining[close + 1..];
} else {
result.push_str(remaining);
Expand Down
11 changes: 6 additions & 5 deletions cli/src/crash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! and write structured crash reports.

use crate::exit_code::ExitCode;
use std::fmt::Write;
use std::panic;
use std::path::{Path, PathBuf};
use std::time::SystemTime;
Expand Down Expand Up @@ -33,12 +34,12 @@ impl CrashReport {
out.push_str(
"================================================================================\n",
);
out.push_str(&format!("Compiler Version: {}\n", self.compiler_version));
out.push_str(&format!("CLI Command: {}\n", self.command));
out.push_str(&format!("Timestamp: {}\n", self.timestamp));
out.push_str(&format!("OS Info: {}\n", self.os_info));
let _ = write!(out, "Compiler Version: {}\n", self.compiler_version);
let _ = write!(out, "CLI Command: {}\n", self.command);
let _ = write!(out, "Timestamp: {}\n", self.timestamp);
let _ = write!(out, "OS Info: {}\n", self.os_info);
if let Some(file) = &self.source_file {
out.push_str(&format!("Active File: {}\n", file));
let _ = write!(out, "Active File: {}\n", file);
}
out.push_str(
"--------------------------------------------------------------------------------\n",
Expand Down
73 changes: 34 additions & 39 deletions cli/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! and accumulates post-compilation statistics.

use colored::Colorize;
use std::fmt::Write;
use std::sync::Arc;
use std::time::Duration;

Expand Down Expand Up @@ -229,29 +230,32 @@ impl<'a> DiagnosticRenderer<'a> {

if self.output == DiagnosticOutput::Colored {
if header.is_empty() {
out.push_str(&format!(
let _ = write!(
out,
"{}: {}\n",
diag.severity.colored_label(),
diag.message.bold()
));
);
} else {
out.push_str(&format!(
let _ = write!(
out,
"{}[{}]: {}\n",
diag.severity.colored_label(),
header.white(),
diag.message.bold()
));
);
}
} else {
if header.is_empty() {
out.push_str(&format!("{}: {}\n", diag.severity.label(), diag.message));
let _ = write!(out, "{}: {}\n", diag.severity.label(), diag.message);
} else {
out.push_str(&format!(
let _ = write!(
out,
"{}[{}]: {}\n",
diag.severity.label(),
header,
diag.message
));
);
}
}

Expand All @@ -262,26 +266,21 @@ impl<'a> DiagnosticRenderer<'a> {

let file_ref = format!(" --> {}:{}:{}", file.path().display(), line, col);
if self.output == DiagnosticOutput::Colored {
out.push_str(&format!("{}\n", file_ref.cyan()));
let _ = write!(out, "{}\n", file_ref.cyan());
} else {
out.push_str(&format!("{}\n", file_ref));
let _ = write!(out, "{}\n", file_ref);
}

// Source line
if let Some(line_text) = file.line_content(line) {
let line_num = format!("{:>4}", line);
let bar = "|";
if self.output == DiagnosticOutput::Colored {
out.push_str(&format!("{} {}\n", line_num.cyan(), bar.cyan()));
out.push_str(&format!(
"{} {} {}\n",
line_num.cyan(),
bar.cyan(),
line_text
));
let _ = write!(out, "{} {}\n", line_num.cyan(), bar.cyan());
let _ = write!(out, "{} {} {}\n", line_num.cyan(), bar.cyan(), line_text);
} else {
out.push_str(&format!("{} {}\n", line_num, bar));
out.push_str(&format!("{} {} {}\n", line_num, bar, line_text));
let _ = write!(out, "{} {}\n", line_num, bar);
let _ = write!(out, "{} {} {}\n", line_num, bar, line_text);
}

// Caret underline β€” Unicode-safe (count chars, not bytes)
Expand All @@ -298,13 +297,9 @@ impl<'a> DiagnosticRenderer<'a> {
format!("{}{}", spaces, carets)
};
if self.output == DiagnosticOutput::Colored {
out.push_str(&format!(
" {} {}\n",
bar.cyan(),
caret_line.red().bold()
));
let _ = write!(out, " {} {}\n", bar.cyan(), caret_line.red().bold());
} else {
out.push_str(&format!(" {} {}\n", bar, caret_line));
let _ = write!(out, " {} {}\n", bar, caret_line);
}
}
}
Expand All @@ -313,54 +308,54 @@ impl<'a> DiagnosticRenderer<'a> {
// Related diagnostics (help, notes)
for related in &diag.related {
if self.output == DiagnosticOutput::Colored {
out.push_str(&format!(
let _ = write!(
out,
" {}: {}\n",
related.severity.colored_label(),
related.message
));
);
} else {
out.push_str(&format!(
" {}: {}\n",
related.severity.label(),
related.message
));
let _ = write!(out, " {}: {}\n", related.severity.label(), related.message);
}
}

// Fix suggestions
for suggestion in &diag.suggestions {
if self.output == DiagnosticOutput::Colored {
out.push_str(&format!(
let _ = write!(
out,
" {}: {} β†’ `{}`\n",
"suggestion".green().bold(),
suggestion.message,
suggestion.replacement.green()
));
);
} else {
out.push_str(&format!(
let _ = write!(
out,
" suggestion: {} β†’ `{}`\n",
suggestion.message, suggestion.replacement
));
);
}
}

// Documentation link if code is present
if let Some(code) = diag.code {
if self.output == DiagnosticOutput::Colored {
out.push_str(&format!(
let _ = write!(
out,
" {}: For more details see: {}\n",
"note".cyan().bold(),
format!(
"https://github.com/Tcode-Motion/techscript/blob/main/docs/errors.md#{:?}",
code
)
.underline()
));
);
} else {
out.push_str(&format!(
let _ = write!(out,
" note: For more details see: https://github.com/Tcode-Motion/techscript/blob/main/docs/errors.md#{:?}\n",
code
));
);
}
}

Expand Down
57 changes: 32 additions & 25 deletions cli/src/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! The `TimingProfiler` is an `EventListener` so it receives events
//! automatically from the compilation pipeline.

use std::fmt::Write;
use std::time::{Duration, Instant};

use colored::Colorize;
Expand Down Expand Up @@ -97,75 +98,81 @@ impl TimingProfiler {
let total: Duration = self.stages.iter().map(|s| s.duration).sum();
let mut out = String::new();

out.push_str(&format!(
let _ = write!(
out,
"{}\n",
"─── Compilation Timings ────────────────────────────────".dimmed()
));
out.push_str(&format!(
);
let _ = write!(
out,
"{:<24} {:>10} {}\n",
"Stage".bold(),
"Duration".bold(),
"Items".bold()
));
out.push_str(&format!("{}\n", "─".repeat(50).dimmed()));
);
let _ = write!(out, "{}\n", "─".repeat(50).dimmed());

for s in &self.stages {
out.push_str(&format!(
let _ = write!(
out,
"{:<24} {:>10} {} {}\n",
s.stage,
format_duration(s.duration).cyan().to_string(),
s.item_count,
s.item_label.dimmed()
));
);
}

out.push_str(&format!("{}\n", "─".repeat(50).dimmed()));
out.push_str(&format!(
let _ = write!(out, "{}\n", "─".repeat(50).dimmed());
let _ = write!(
out,
"{:<24} {:>10}\n\n",
"Total".bold(),
format_duration(total).green().bold().to_string()
));
);

// Memory section
let mem = &self.memory;
if mem.peak_memory_bytes > 0 || mem.ast_node_count > 0 {
out.push_str(&format!(
let _ = write!(
out,
"{}\n",
"─── Memory Statistics ──────────────────────────────────".dimmed()
));
out.push_str(&format!(
);
let _ = write!(
out,
"{:<24} {:>10}\n",
"Peak memory",
format_bytes(mem.peak_memory_bytes).cyan().to_string()
));
);
if mem.ir_size_bytes > 0 {
out.push_str(&format!(
let _ = write!(
out,
"{:<24} {:>10}\n",
"IR module",
format_bytes(mem.ir_size_bytes).cyan().to_string()
));
);
}
if mem.bytecode_size_bytes > 0 {
out.push_str(&format!(
let _ = write!(
out,
"{:<24} {:>10}\n",
"Bytecode",
format_bytes(mem.bytecode_size_bytes).cyan().to_string()
));
);
}
if mem.ast_node_count > 0 {
out.push_str(&format!("{:<24} {:>10}\n", "AST nodes", mem.ast_node_count));
let _ = write!(out, "{:<24} {:>10}\n", "AST nodes", mem.ast_node_count);
}
if mem.function_count > 0 {
out.push_str(&format!(
"{:<24} {:>10}\n",
"IR functions", mem.function_count
));
let _ = write!(out, "{:<24} {:>10}\n", "IR functions", mem.function_count);
}
if mem.basic_block_count > 0 {
out.push_str(&format!(
let _ = write!(
out,
"{:<24} {:>10}\n",
"Basic blocks", mem.basic_block_count
));
);
}
}

Expand Down
Loading
Loading