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: 8 additions & 2 deletions crates/wright-driver/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ use std::path::PathBuf;

pub use wright_analyzer::registry::LintConfig;

use crate::source_provider::SourceBackend;

/// The concrete input frontend to use, or automatic detection.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SourceKind {
/// Detect from the input path extension or stdin content.
Auto,
/// `.opy` source through the adapter bridge (the native frontend is the
/// default path).
/// `.opy` source through the explicitly selected backend.
Opy,
/// `.ostw` / `.del` source through the native OSTW frontend (#117).
Ostw,
Expand Down Expand Up @@ -102,6 +103,10 @@ pub struct SessionConfig {
pub input: InputSpec,
/// Frontend selection; `Auto` detects from path/stdin.
pub kind: SourceKind,
/// The source implementation selected for source-language workflows.
/// Raw Workshop is always handled in-process; the provider backend is
/// currently reserved for the first-party OPY provider.
pub source_backend: SourceBackend,
/// Workshop client-locale override (bypasses auto-detection).
pub locale: Option<String>,
/// Include root for `.opy` inputs (defaults to the input's directory).
Expand Down Expand Up @@ -137,6 +142,7 @@ impl Default for SessionConfig {
SessionConfig {
input: InputSpec::Stdin,
kind: SourceKind::Auto,
source_backend: SourceBackend::Native,
locale: None,
root: None,
output: None,
Expand Down
1 change: 1 addition & 0 deletions crates/wright-driver/src/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ fn resolved_input(
text: main_text.to_string(),
path: Some(main_path.to_path_buf()),
root: root.to_path_buf(),
cwd: std::env::current_dir().unwrap_or_else(|_| PathBuf::from(".")),
display: crate::input::display_path(main_path),
identity: crate::input_identity(main_text),
origin: origin_for(kind, locale),
Expand Down
26 changes: 22 additions & 4 deletions crates/wright-driver/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub struct ResolvedInput {
pub path: Option<PathBuf>,
/// The include root (`.opy` include base); the input's directory by default.
pub root: PathBuf,
/// The invocation working directory used to resolve a relative entry.
pub cwd: PathBuf,
/// A stable display identity used in diagnostics (`<stdin>` for stdin).
pub display: String,
/// SHA-256 hex of the input bytes (deterministic input identity).
Expand Down Expand Up @@ -55,7 +57,19 @@ pub fn resolve(config: &SessionConfig) -> Result<ResolvedInput, Diagnostic> {
}

fn resolve_path(path: &Path, config: &SessionConfig) -> Result<ResolvedInput, Diagnostic> {
let bytes = std::fs::read(path).map_err(|error| {
let cwd = std::env::current_dir().map_err(|error| {
Diagnostic::error(
"cwd-io",
Stage::Discovery,
format!("cannot determine the invocation working directory: {error}"),
)
})?;
let path = if path.is_absolute() {
path.to_path_buf()
} else {
cwd.join(path)
};
let bytes = std::fs::read(&path).map_err(|error| {
Diagnostic::error(
"input-io",
Stage::Discovery,
Expand All @@ -64,23 +78,25 @@ fn resolve_path(path: &Path, config: &SessionConfig) -> Result<ResolvedInput, Di
})?;
let text = String::from_utf8_lossy(&bytes).into_owned();
let kind = match config.kind {
SourceKind::Auto => kind_from_extension(path)?,
SourceKind::Auto => kind_from_extension(&path)?,
other => other,
};
let root = match &config.root {
Some(root) => root.clone(),
Some(root) if root.is_absolute() => root.clone(),
Some(root) => cwd.join(root),
None => path
.parent()
.map(Path::to_path_buf)
.unwrap_or_else(|| PathBuf::from(".")),
};
let display = display_path(path);
let display = display_path(&path);
let origin = origin_for(kind, config.locale.as_deref());
Ok(ResolvedInput {
kind,
text,
path: Some(path.to_path_buf()),
root,
cwd,
display,
identity: sha256_hex(&bytes),
origin,
Expand Down Expand Up @@ -111,13 +127,15 @@ fn resolve_stdin(config: &SessionConfig) -> Result<ResolvedInput, Diagnostic> {
.root
.clone()
.unwrap_or_else(|| std::env::current_dir().unwrap_or_else(|_| PathBuf::from(".")));
let cwd = std::env::current_dir().unwrap_or_else(|_| PathBuf::from("."));
let display = "<stdin>".to_string();
let origin = origin_for(kind, config.locale.as_deref());
Ok(ResolvedInput {
kind,
text,
path: None,
root,
cwd,
display,
identity: sha256_hex(&bytes),
origin,
Expand Down
7 changes: 6 additions & 1 deletion crates/wright-driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub mod provider_edit;
pub mod result;
pub mod service;
pub mod session;
pub mod source_provider;
pub mod workshop_provider;

pub use config::{InputSpec, LintConfig, OutputFormat, SessionConfig, SourceKind};
Expand All @@ -32,7 +33,11 @@ pub use result::{
AnalyzeResult, CheckResult, CompileResult, CompiledOutput, ConvertResult, ConvertTarget,
Envelope, InspectResult, LintResult, RESULT_CONTRACT,
};
pub use session::{CompilerSession, Loaded};
pub use session::{CompilerSession, Loaded, Provenance};
pub use source_provider::{
SourceBackend, SourceCompilation, SourceLanguage, SourceProvenance, SourceProvider,
SourceProviderError, SourceTarget,
};
pub use workshop_provider::WorkshopProvider;
pub use wright_transform::Profile;

Expand Down
3 changes: 3 additions & 0 deletions crates/wright-driver/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ pub fn exit_code_from(diagnostics: &[Diagnostic]) -> u8 {
if diagnostic.code == "ostw-unsupported" {
return exit::UNSUPPORTED;
}
if diagnostic.code == "source-provider-unsupported" {
return exit::UNSUPPORTED;
}
has_source_error = true;
}
if has_source_error {
Expand Down
Loading