tsrs 0.0.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +21 -0
- data/README.md +175 -3
- data/ext/tsrs/extconf.rb +121 -0
- data/ext/tsrs/include/tsrs.h +113 -0
- data/ext/tsrs/tsrs.c +261 -0
- data/lib/tsrs/backend.rb +66 -0
- data/lib/tsrs/check_result.rb +61 -0
- data/lib/tsrs/diagnosed.rb +21 -0
- data/lib/tsrs/diagnostic.rb +112 -0
- data/lib/tsrs/errors.rb +25 -0
- data/lib/tsrs/options.rb +62 -0
- data/lib/tsrs/session.rb +57 -0
- data/lib/tsrs/transpile_result.rb +54 -0
- data/lib/tsrs/version.rb +5 -0
- data/lib/tsrs.rb +76 -3
- data/licenses/README.md +11 -0
- data/licenses/tsrs-Apache-2.0.txt +55 -0
- data/licenses/tsrs-NOTICE.txt +416 -0
- data/rust/.cargo/config.toml +5 -0
- data/rust/Cargo.lock +1301 -0
- data/rust/Cargo.toml +39 -0
- data/rust/build.rs +77 -0
- data/rust/cbindgen.toml +25 -0
- data/rust/rust-toolchain.toml +5 -0
- data/rust/rustfmt.toml +3 -0
- data/rust/src/check.rs +136 -0
- data/rust/src/lib.rs +213 -0
- data/rust/src/options.rs +60 -0
- data/rust/src/result.rs +52 -0
- data/rust/src/session.rs +194 -0
- data/rust/src/status.rs +26 -0
- data/rust/src/transpile.rs +66 -0
- data/rust/src/worker.rs +84 -0
- data/sig/tsrs/backend.rbs +44 -0
- data/sig/tsrs/check_result.rbs +33 -0
- data/sig/tsrs/diagnosed.rbs +15 -0
- data/sig/tsrs/diagnostic.rbs +66 -0
- data/sig/tsrs/errors.rbs +37 -0
- data/sig/tsrs/options.rbs +19 -0
- data/sig/tsrs/session.rbs +26 -0
- data/sig/tsrs/transpile_result.rbs +29 -0
- data/sig/tsrs/types.rbs +5 -0
- data/sig/tsrs/version.rbs +5 -0
- data/sig/tsrs.rbs +27 -0
- data/tsrs.gemspec +45 -0
- metadata +53 -6
data/rust/src/session.rs
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
use std::sync::Arc;
|
|
2
|
+
|
|
3
|
+
use serde::{Deserialize, Serialize};
|
|
4
|
+
use serde_json::value::RawValue;
|
|
5
|
+
use tsrs_api::{Handler, Response, Session, SessionOptions};
|
|
6
|
+
use tsrs_core::context::{with_checker_lifetime, CheckerLifetime, Context};
|
|
7
|
+
use tsrs_core::json::Value;
|
|
8
|
+
use tsrs_core::tspath;
|
|
9
|
+
use tsrs_vfs::{bundled, osvfs, FS};
|
|
10
|
+
|
|
11
|
+
use tsrs_execute::tsc::ExitStatus;
|
|
12
|
+
|
|
13
|
+
use crate::result::{TsrsErrorCode, TsrsResult};
|
|
14
|
+
use crate::status::Status;
|
|
15
|
+
|
|
16
|
+
pub struct TsrsSession {
|
|
17
|
+
session: Arc<Session>,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
#[derive(Deserialize)]
|
|
21
|
+
#[serde(deny_unknown_fields)]
|
|
22
|
+
struct CheckRequest {
|
|
23
|
+
project: String,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#[derive(Serialize)]
|
|
27
|
+
struct CheckPayload {
|
|
28
|
+
status: Status,
|
|
29
|
+
diagnostics: Box<RawValue>,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
pub fn new(cwd: &str) -> TsrsSession {
|
|
33
|
+
let fs: Arc<dyn FS> = Arc::new(bundled::wrap_fs(osvfs::fs()));
|
|
34
|
+
|
|
35
|
+
let session = Session::new(SessionOptions::new(
|
|
36
|
+
tspath::normalize_path(cwd),
|
|
37
|
+
bundled::default_lib_path(),
|
|
38
|
+
fs,
|
|
39
|
+
false,
|
|
40
|
+
));
|
|
41
|
+
|
|
42
|
+
TsrsSession { session }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
impl TsrsSession {
|
|
46
|
+
pub fn session(&self) -> Arc<Session> {
|
|
47
|
+
Arc::clone(&self.session)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
pub fn retain(&self) -> TsrsSession {
|
|
51
|
+
TsrsSession {
|
|
52
|
+
session: self.session(),
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
pub fn close(&self) {
|
|
57
|
+
self.session.close();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
pub fn check(session: &Session, request_json: &str) -> TsrsResult {
|
|
62
|
+
let request: CheckRequest = match serde_json::from_str(request_json) {
|
|
63
|
+
Ok(request) => request,
|
|
64
|
+
Err(error) => return TsrsResult::error(TsrsErrorCode::Option, error.to_string()),
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
let project = tspath::get_normalized_absolute_path(&request.project, session.current_directory());
|
|
68
|
+
let params = object("openProjects", Value::Array(vec![Value::String(project.clone())]));
|
|
69
|
+
|
|
70
|
+
let created = match call(session, "createSnapshot", ¶ms) {
|
|
71
|
+
Ok(created) => created,
|
|
72
|
+
Err(message) => return TsrsResult::error(TsrsErrorCode::Check, message),
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
let Some(snapshot) = number(field(&created, "snapshot")) else {
|
|
76
|
+
return TsrsResult::error(TsrsErrorCode::Internal, "createSnapshot returned no snapshot");
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
let outcome = diagnostics(session, snapshot, &created, &project);
|
|
80
|
+
|
|
81
|
+
let _ = call(session, "release", &object("snapshot", Value::Number(snapshot as f64)));
|
|
82
|
+
|
|
83
|
+
match outcome {
|
|
84
|
+
Ok((status, diagnostics)) => {
|
|
85
|
+
let payload = CheckPayload {
|
|
86
|
+
status: status.into(),
|
|
87
|
+
diagnostics,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
match serde_json::to_string(&payload) {
|
|
91
|
+
Ok(json) => TsrsResult::value(json),
|
|
92
|
+
Err(error) => TsrsResult::error(TsrsErrorCode::Internal, error.to_string()),
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
Err(result) => result,
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fn diagnostics(
|
|
100
|
+
session: &Session,
|
|
101
|
+
snapshot: u64,
|
|
102
|
+
created: &Value,
|
|
103
|
+
project: &str,
|
|
104
|
+
) -> Result<(ExitStatus, Box<RawValue>), TsrsResult> {
|
|
105
|
+
let id = project_id(created, project)
|
|
106
|
+
.ok_or_else(|| TsrsResult::error(TsrsErrorCode::Check, format!("no project was loaded from {project}")))?;
|
|
107
|
+
|
|
108
|
+
let data = session
|
|
109
|
+
.snapshot_data(snapshot)
|
|
110
|
+
.map_err(|error| TsrsResult::error(TsrsErrorCode::Internal, error.to_string()))?;
|
|
111
|
+
|
|
112
|
+
let program = data
|
|
113
|
+
.get_program(&tsrs_project::ID(id))
|
|
114
|
+
.map_err(|error| TsrsResult::error(TsrsErrorCode::Check, error.to_string()))?;
|
|
115
|
+
|
|
116
|
+
// As tsc collects them before emitting (tsrs_execute/src/tsc/emit.rs).
|
|
117
|
+
let ctx = with_checker_lifetime(&Context::background(), CheckerLifetime::Diagnostics);
|
|
118
|
+
let all = tsrs_compiler::get_diagnostics_of_any_program(
|
|
119
|
+
&ctx,
|
|
120
|
+
program,
|
|
121
|
+
None,
|
|
122
|
+
false,
|
|
123
|
+
&mut |ctx, file| program.get_bind_diagnostics(ctx, file),
|
|
124
|
+
&mut |ctx, file| program.get_semantic_diagnostics(ctx, file),
|
|
125
|
+
);
|
|
126
|
+
let all = tsrs_compiler::sort_and_deduplicate_diagnostics(&all);
|
|
127
|
+
|
|
128
|
+
// tsc's rule (tsrs_execute/src/tsc/emit.rs) for a run that did not skip emitting, as with --noEmit.
|
|
129
|
+
let status = if all.is_empty() {
|
|
130
|
+
ExitStatus::Success
|
|
131
|
+
} else {
|
|
132
|
+
ExitStatus::DiagnosticsPresent_OutputsGenerated
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
let responses = tsrs_api::diagnostics::diagnostic_responses(&all);
|
|
136
|
+
|
|
137
|
+
drop(all);
|
|
138
|
+
drop(data);
|
|
139
|
+
|
|
140
|
+
tsrs_core::json::marshal(&responses)
|
|
141
|
+
.ok()
|
|
142
|
+
.and_then(|json| RawValue::from_string(json).ok())
|
|
143
|
+
.map(|diagnostics| (status, diagnostics))
|
|
144
|
+
.ok_or_else(|| TsrsResult::error(TsrsErrorCode::Internal, "the diagnostics could not be serialized"))
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// A snapshot also holds the projects this one references.
|
|
148
|
+
fn project_id(created: &Value, project: &str) -> Option<String> {
|
|
149
|
+
let Value::Array(projects) = field(created, "projects")? else {
|
|
150
|
+
return None;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
projects
|
|
154
|
+
.iter()
|
|
155
|
+
.find(|candidate| matches!(field(candidate, "configFileName"), Some(Value::String(name)) if name == project))
|
|
156
|
+
.or_else(|| projects.first())
|
|
157
|
+
.and_then(|candidate| match field(candidate, "id") {
|
|
158
|
+
Some(Value::String(id)) => Some(id.clone()),
|
|
159
|
+
_ => None,
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
fn call(session: &Session, method: &str, params: &Value) -> Result<Value, String> {
|
|
164
|
+
let params = tsrs_core::json::marshal(params)?;
|
|
165
|
+
|
|
166
|
+
match session.handle_request(method, params.as_bytes()) {
|
|
167
|
+
Ok(Response::Json(text)) => tsrs_core::json::unmarshal(&text),
|
|
168
|
+
Ok(Response::Binary(_)) => Err(format!("{method} returned a binary response")),
|
|
169
|
+
Err(error) => Err(error.to_string()),
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
fn object(key: &str, value: Value) -> Value {
|
|
174
|
+
let mut map = tsrs_core::collections::OrderedMap::default();
|
|
175
|
+
|
|
176
|
+
map.insert(key.to_string(), value);
|
|
177
|
+
|
|
178
|
+
Value::Object(map)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
fn field<'a>(value: &'a Value, key: &str) -> Option<&'a Value> {
|
|
182
|
+
match value {
|
|
183
|
+
Value::Object(object) => object.get(key),
|
|
184
|
+
_ => None,
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
fn number(value: Option<&Value>) -> Option<u64> {
|
|
189
|
+
match value? {
|
|
190
|
+
Value::Number(number) if *number >= 0.0 => Some(*number as u64),
|
|
191
|
+
Value::Integer(number) => u64::try_from(*number).ok(),
|
|
192
|
+
_ => None,
|
|
193
|
+
}
|
|
194
|
+
}
|
data/rust/src/status.rs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
use serde::Serialize;
|
|
2
|
+
use tsrs_execute::tsc::ExitStatus;
|
|
3
|
+
|
|
4
|
+
#[derive(Serialize)]
|
|
5
|
+
pub struct Status {
|
|
6
|
+
code: i32,
|
|
7
|
+
name: &'static str,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
impl From<ExitStatus> for Status {
|
|
11
|
+
fn from(status: ExitStatus) -> Self {
|
|
12
|
+
let name = match status {
|
|
13
|
+
ExitStatus::Success => "success",
|
|
14
|
+
ExitStatus::DiagnosticsPresent_OutputsSkipped => "diagnostics_present_outputs_skipped",
|
|
15
|
+
ExitStatus::DiagnosticsPresent_OutputsGenerated => "diagnostics_present_outputs_generated",
|
|
16
|
+
ExitStatus::InvalidProject_OutputsSkipped => "invalid_project_outputs_skipped",
|
|
17
|
+
ExitStatus::ProjectReferenceCycle_OutputsSkipped => "project_reference_cycle_outputs_skipped",
|
|
18
|
+
ExitStatus::NotImplemented => "not_implemented",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
Status {
|
|
22
|
+
code: status as i32,
|
|
23
|
+
name,
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
use serde::Serialize;
|
|
2
|
+
use serde_json::value::RawValue;
|
|
3
|
+
|
|
4
|
+
use crate::options::{self, TranspileRequest};
|
|
5
|
+
use crate::result::{TsrsErrorCode, TsrsResult};
|
|
6
|
+
|
|
7
|
+
#[derive(Serialize)]
|
|
8
|
+
struct TranspilePayload {
|
|
9
|
+
code: String,
|
|
10
|
+
map: Option<String>,
|
|
11
|
+
diagnostics: Box<RawValue>,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
pub fn transpile(source: String, request_json: String, declaration: bool) -> TsrsResult {
|
|
15
|
+
let request: TranspileRequest = match serde_json::from_str(&request_json) {
|
|
16
|
+
Ok(request) => request,
|
|
17
|
+
Err(error) => return TsrsResult::error(TsrsErrorCode::Option, error.to_string()),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Option parsing allocates in the thread's arena unless a region is entered.
|
|
21
|
+
let region = tsrs_core::arena::Region::new(64 << 10);
|
|
22
|
+
let outcome = {
|
|
23
|
+
let _scope = region.enter();
|
|
24
|
+
|
|
25
|
+
run(&source, &request, declaration)
|
|
26
|
+
};
|
|
27
|
+
drop(region);
|
|
28
|
+
|
|
29
|
+
outcome
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fn run(source: &str, request: &TranspileRequest, declaration: bool) -> TsrsResult {
|
|
33
|
+
let compiler_options = match options::compiler_options(&request.args) {
|
|
34
|
+
Ok(compiler_options) => compiler_options,
|
|
35
|
+
Err(message) => return TsrsResult::error(TsrsErrorCode::Option, message),
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
let output = match tsrs_api::transpile::transpile(
|
|
39
|
+
source,
|
|
40
|
+
Some(&compiler_options),
|
|
41
|
+
&request.file_name,
|
|
42
|
+
request.report_diagnostics,
|
|
43
|
+
declaration,
|
|
44
|
+
) {
|
|
45
|
+
Ok(output) => output,
|
|
46
|
+
Err(error) => return TsrsResult::error(TsrsErrorCode::Transpile, error.to_string()),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
let diagnostics = tsrs_core::json::Value::Array(output.diagnostics);
|
|
50
|
+
|
|
51
|
+
let diagnostics = match tsrs_core::json::marshal(&diagnostics).map(RawValue::from_string) {
|
|
52
|
+
Ok(Ok(diagnostics)) => diagnostics,
|
|
53
|
+
_ => return TsrsResult::error(TsrsErrorCode::Internal, "the diagnostics could not be serialized"),
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
let payload = TranspilePayload {
|
|
57
|
+
code: output.output_text,
|
|
58
|
+
map: (!output.source_map_text.is_empty()).then_some(output.source_map_text),
|
|
59
|
+
diagnostics,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
match serde_json::to_string(&payload) {
|
|
63
|
+
Ok(json) => TsrsResult::value(json),
|
|
64
|
+
Err(error) => TsrsResult::error(TsrsErrorCode::Internal, error.to_string()),
|
|
65
|
+
}
|
|
66
|
+
}
|
data/rust/src/worker.rs
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
use std::panic::{catch_unwind, AssertUnwindSafe};
|
|
2
|
+
use std::sync::mpsc::{channel, Receiver, Sender};
|
|
3
|
+
use std::sync::{Arc, Mutex, OnceLock};
|
|
4
|
+
use std::thread;
|
|
5
|
+
|
|
6
|
+
use crate::result::{TsrsErrorCode, TsrsResult};
|
|
7
|
+
|
|
8
|
+
// Type checking recurses deeply; tsrs's CLI uses the same stack size.
|
|
9
|
+
const STACK_SIZE: usize = 512 << 20;
|
|
10
|
+
|
|
11
|
+
type Job = Box<dyn FnOnce() + Send>;
|
|
12
|
+
|
|
13
|
+
struct Pool {
|
|
14
|
+
sender: Mutex<Sender<Job>>,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// tsrs allocates into per-thread arenas that are never freed, so a fresh thread per call would leak one each time.
|
|
18
|
+
fn pool() -> &'static Pool {
|
|
19
|
+
static POOL: OnceLock<Pool> = OnceLock::new();
|
|
20
|
+
|
|
21
|
+
POOL.get_or_init(|| {
|
|
22
|
+
let (sender, receiver) = channel::<Job>();
|
|
23
|
+
let receiver = Arc::new(Mutex::new(receiver));
|
|
24
|
+
let threads = thread::available_parallelism().map_or(1, |n| n.get()).clamp(1, 4);
|
|
25
|
+
|
|
26
|
+
for index in 0..threads {
|
|
27
|
+
let receiver = Arc::clone(&receiver);
|
|
28
|
+
|
|
29
|
+
thread::Builder::new()
|
|
30
|
+
.name(format!("tsrs-ruby-{index}"))
|
|
31
|
+
.stack_size(STACK_SIZE)
|
|
32
|
+
.spawn(move || work(&receiver))
|
|
33
|
+
.expect("spawn a tsrs worker thread");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
Pool {
|
|
37
|
+
sender: Mutex::new(sender),
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
fn work(receiver: &Mutex<Receiver<Job>>) {
|
|
43
|
+
loop {
|
|
44
|
+
let job = match receiver.lock() {
|
|
45
|
+
Ok(receiver) => receiver.recv(),
|
|
46
|
+
Err(_) => return,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
match job {
|
|
50
|
+
Ok(job) => job(),
|
|
51
|
+
Err(_) => return,
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
pub fn run<F>(job: F) -> TsrsResult
|
|
57
|
+
where
|
|
58
|
+
F: FnOnce() -> TsrsResult + Send + 'static,
|
|
59
|
+
{
|
|
60
|
+
let (reply, result) = channel::<TsrsResult>();
|
|
61
|
+
|
|
62
|
+
let task: Job = Box::new(move || {
|
|
63
|
+
let outcome = match catch_unwind(AssertUnwindSafe(job)) {
|
|
64
|
+
Ok(result) => result,
|
|
65
|
+
Err(payload) => TsrsResult::error(TsrsErrorCode::Panic, crate::panic_message(&payload)),
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
let _ = reply.send(outcome);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
let sent = pool()
|
|
72
|
+
.sender
|
|
73
|
+
.lock()
|
|
74
|
+
.map(|sender| sender.send(task).is_ok())
|
|
75
|
+
.unwrap_or(false);
|
|
76
|
+
|
|
77
|
+
if !sent {
|
|
78
|
+
return TsrsResult::error(TsrsErrorCode::Internal, "the tsrs worker threads are gone");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
result
|
|
82
|
+
.recv()
|
|
83
|
+
.unwrap_or_else(|_| TsrsResult::error(TsrsErrorCode::Internal, "a tsrs worker thread stopped without replying"))
|
|
84
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Generated from lib/tsrs/backend.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Tsrs
|
|
4
|
+
module Backend
|
|
5
|
+
module Unavailable
|
|
6
|
+
# : (String, String) -> String
|
|
7
|
+
def transpile: (String, String) -> String
|
|
8
|
+
|
|
9
|
+
# : (String, String) -> String
|
|
10
|
+
def transpile_declaration: (String, String) -> String
|
|
11
|
+
|
|
12
|
+
# : (String) -> String
|
|
13
|
+
def check: (String) -> String
|
|
14
|
+
|
|
15
|
+
# : (String) -> untyped
|
|
16
|
+
def session_new: (String) -> untyped
|
|
17
|
+
|
|
18
|
+
# : (untyped, String) -> String
|
|
19
|
+
def session_check: (untyped, String) -> String
|
|
20
|
+
|
|
21
|
+
# : (untyped) -> nil
|
|
22
|
+
def session_close: (untyped) -> nil
|
|
23
|
+
|
|
24
|
+
# : () -> String
|
|
25
|
+
def panic_for_test: () -> String
|
|
26
|
+
|
|
27
|
+
# : () -> String
|
|
28
|
+
def version: () -> String
|
|
29
|
+
|
|
30
|
+
# : () -> String
|
|
31
|
+
def tsrs_version: () -> String
|
|
32
|
+
|
|
33
|
+
# : () -> String
|
|
34
|
+
def typescript_version: () -> String
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
# : (Symbol?) -> bot
|
|
39
|
+
def unavailable: (Symbol?) -> bot
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
extend Unavailable
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Generated from lib/tsrs/check_result.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Tsrs
|
|
4
|
+
class CheckResult
|
|
5
|
+
include Diagnosed
|
|
6
|
+
|
|
7
|
+
attr_reader status: Integer
|
|
8
|
+
|
|
9
|
+
attr_reader exit_status: Symbol
|
|
10
|
+
|
|
11
|
+
attr_reader diagnostics: Array[Tsrs::Diagnostic]
|
|
12
|
+
|
|
13
|
+
attr_reader output: String
|
|
14
|
+
|
|
15
|
+
# : (String) -> Tsrs::CheckResult
|
|
16
|
+
def self.from_json: (String) -> Tsrs::CheckResult
|
|
17
|
+
|
|
18
|
+
# : (status: Integer, exit_status: Symbol, ?output: String, ?diagnostics: Array[Tsrs::Diagnostic]) -> void
|
|
19
|
+
def initialize: (status: Integer, exit_status: Symbol, ?output: String, ?diagnostics: Array[Tsrs::Diagnostic]) -> void
|
|
20
|
+
|
|
21
|
+
# : () -> bool
|
|
22
|
+
def success?: () -> bool
|
|
23
|
+
|
|
24
|
+
# : (?strict: bool) -> self
|
|
25
|
+
def validate!: (?strict: bool) -> self
|
|
26
|
+
|
|
27
|
+
# : () -> String
|
|
28
|
+
def to_s: () -> String
|
|
29
|
+
|
|
30
|
+
# : () -> String
|
|
31
|
+
def inspect: () -> String
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Generated from lib/tsrs/diagnosed.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Tsrs
|
|
4
|
+
# @rbs module-self _Diagnosed
|
|
5
|
+
module Diagnosed : _Diagnosed
|
|
6
|
+
# : () -> Array[Tsrs::Diagnostic]
|
|
7
|
+
def errors: () -> Array[Tsrs::Diagnostic]
|
|
8
|
+
|
|
9
|
+
# : () -> Array[Tsrs::Diagnostic]
|
|
10
|
+
def warnings: () -> Array[Tsrs::Diagnostic]
|
|
11
|
+
|
|
12
|
+
# : () -> bool
|
|
13
|
+
def errors?: () -> bool
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Generated from lib/tsrs/diagnostic.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Tsrs
|
|
4
|
+
# Lines and columns are 1-based. `start` and `finish` are offsets in UTF-16 code units, as TypeScript counts.
|
|
5
|
+
class Diagnostic
|
|
6
|
+
CATEGORIES: Array[Symbol]
|
|
7
|
+
|
|
8
|
+
attr_reader code: Integer
|
|
9
|
+
|
|
10
|
+
attr_reader category: Symbol
|
|
11
|
+
|
|
12
|
+
attr_reader message: String
|
|
13
|
+
|
|
14
|
+
attr_reader file: String?
|
|
15
|
+
|
|
16
|
+
attr_reader line: Integer?
|
|
17
|
+
|
|
18
|
+
attr_reader column: Integer?
|
|
19
|
+
|
|
20
|
+
attr_reader end_line: Integer?
|
|
21
|
+
|
|
22
|
+
attr_reader end_column: Integer?
|
|
23
|
+
|
|
24
|
+
attr_reader start: Integer?
|
|
25
|
+
|
|
26
|
+
attr_reader finish: Integer?
|
|
27
|
+
|
|
28
|
+
attr_reader source: String?
|
|
29
|
+
|
|
30
|
+
attr_reader message_chain: Array[Tsrs::Diagnostic]
|
|
31
|
+
|
|
32
|
+
attr_reader related_information: Array[Tsrs::Diagnostic]
|
|
33
|
+
|
|
34
|
+
# : (Hash[String, untyped]) -> Tsrs::Diagnostic
|
|
35
|
+
def self.from_hash: (Hash[String, untyped]) -> Tsrs::Diagnostic
|
|
36
|
+
|
|
37
|
+
# : (untyped) -> Integer?
|
|
38
|
+
def self.offset: (untyped) -> Integer?
|
|
39
|
+
|
|
40
|
+
# : (code: Integer, category: Symbol, message: String, ?file: String?, ?line: Integer?, ?column: Integer?, ?end_line: Integer?, ?end_column: Integer?, ?start: Integer?, ?finish: Integer?, ?source: String?, ?message_chain: Array[Tsrs::Diagnostic], ?related_information: Array[Tsrs::Diagnostic]) -> void
|
|
41
|
+
def initialize: (code: Integer, category: Symbol, message: String, ?file: String?, ?line: Integer?, ?column: Integer?, ?end_line: Integer?, ?end_column: Integer?, ?start: Integer?, ?finish: Integer?, ?source: String?, ?message_chain: Array[Tsrs::Diagnostic], ?related_information: Array[Tsrs::Diagnostic]) -> void
|
|
42
|
+
|
|
43
|
+
# : () -> bool
|
|
44
|
+
def error?: () -> bool
|
|
45
|
+
|
|
46
|
+
# : () -> bool
|
|
47
|
+
def warning?: () -> bool
|
|
48
|
+
|
|
49
|
+
# : () -> String
|
|
50
|
+
def location: () -> String
|
|
51
|
+
|
|
52
|
+
# : () -> String
|
|
53
|
+
def full_message: () -> String
|
|
54
|
+
|
|
55
|
+
# : () -> String
|
|
56
|
+
def to_s: () -> String
|
|
57
|
+
|
|
58
|
+
# : () -> String
|
|
59
|
+
def inspect: () -> String
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
# : (Array[Tsrs::Diagnostic], Integer) -> Array[String]
|
|
64
|
+
def chain_lines: (Array[Tsrs::Diagnostic], Integer) -> Array[String]
|
|
65
|
+
end
|
|
66
|
+
end
|
data/sig/tsrs/errors.rbs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Generated from lib/tsrs/errors.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Tsrs
|
|
4
|
+
class Error < StandardError
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class OptionError < Error
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class EncodingError < Error
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class TranspileError < Error
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class InternalError < Error
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class PanicError < InternalError
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class CheckError < Error
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class DiagnosticError < Error
|
|
26
|
+
attr_reader diagnostics: Array[Tsrs::Diagnostic]
|
|
27
|
+
|
|
28
|
+
# : (Array[Tsrs::Diagnostic]) -> void
|
|
29
|
+
def initialize: (Array[Tsrs::Diagnostic]) -> void
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class SyntaxError < DiagnosticError
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class TypeError < DiagnosticError
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Generated from lib/tsrs/options.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Tsrs
|
|
4
|
+
module Options
|
|
5
|
+
REFUSED: Hash[String, String]
|
|
6
|
+
|
|
7
|
+
# : (Hash[Symbol | String, untyped]) -> Array[String]
|
|
8
|
+
def self.arguments: (Hash[Symbol | String, untyped]) -> Array[String]
|
|
9
|
+
|
|
10
|
+
# : (Symbol | String) -> String
|
|
11
|
+
def self.option_name: (Symbol | String) -> String
|
|
12
|
+
|
|
13
|
+
# : (String) -> void
|
|
14
|
+
def self.refuse!: (String) -> void
|
|
15
|
+
|
|
16
|
+
# : (String, untyped) -> Array[String]
|
|
17
|
+
def self.flag: (String, untyped) -> Array[String]
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Generated from lib/tsrs/session.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Tsrs
|
|
4
|
+
# Unlike Tsrs.check, a session gives a check's memory back. Compiler options come from the tsconfig.json only.
|
|
5
|
+
class Session
|
|
6
|
+
attr_reader cwd: String
|
|
7
|
+
|
|
8
|
+
# : [T] (?cwd: String) { (Tsrs::Session) -> T } -> T
|
|
9
|
+
def self.open: [T] (?cwd: String) { (Tsrs::Session) -> T } -> T
|
|
10
|
+
|
|
11
|
+
# : (?cwd: String) -> void
|
|
12
|
+
def initialize: (?cwd: String) -> void
|
|
13
|
+
|
|
14
|
+
# : (?String) -> Tsrs::CheckResult
|
|
15
|
+
def check: (?String) -> Tsrs::CheckResult
|
|
16
|
+
|
|
17
|
+
# : () -> void
|
|
18
|
+
def close: () -> void
|
|
19
|
+
|
|
20
|
+
# : () -> bool
|
|
21
|
+
def closed?: () -> bool
|
|
22
|
+
|
|
23
|
+
# : () -> String
|
|
24
|
+
def inspect: () -> String
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Generated from lib/tsrs/transpile_result.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Tsrs
|
|
4
|
+
# A transpile ignores imports, so its diagnostics never include type errors.
|
|
5
|
+
class TranspileResult
|
|
6
|
+
include Diagnosed
|
|
7
|
+
|
|
8
|
+
attr_reader code: String
|
|
9
|
+
|
|
10
|
+
attr_reader map: String?
|
|
11
|
+
|
|
12
|
+
attr_reader diagnostics: Array[Tsrs::Diagnostic]
|
|
13
|
+
|
|
14
|
+
# : (String) -> Tsrs::TranspileResult
|
|
15
|
+
def self.from_json: (String) -> Tsrs::TranspileResult
|
|
16
|
+
|
|
17
|
+
# : (code: String, ?map: String?, ?diagnostics: Array[Tsrs::Diagnostic]) -> void
|
|
18
|
+
def initialize: (code: String, ?map: String?, ?diagnostics: Array[Tsrs::Diagnostic]) -> void
|
|
19
|
+
|
|
20
|
+
# : (?strict: bool) -> self
|
|
21
|
+
def validate!: (?strict: bool) -> self
|
|
22
|
+
|
|
23
|
+
# : () -> String
|
|
24
|
+
def to_s: () -> String
|
|
25
|
+
|
|
26
|
+
# : () -> String
|
|
27
|
+
def inspect: () -> String
|
|
28
|
+
end
|
|
29
|
+
end
|
data/sig/tsrs/types.rbs
ADDED
data/sig/tsrs.rbs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Generated from lib/tsrs.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Tsrs
|
|
4
|
+
# : (String, ?file_name: String?, ?report_diagnostics: bool, ?strict: bool, **untyped) -> Tsrs::TranspileResult
|
|
5
|
+
def self.transpile: (String, ?file_name: String?, ?report_diagnostics: bool, ?strict: bool, **untyped) -> Tsrs::TranspileResult
|
|
6
|
+
|
|
7
|
+
# : (String, ?file_name: String?, ?report_diagnostics: bool, ?strict: bool, **untyped) -> Tsrs::TranspileResult
|
|
8
|
+
def self.transpile_declaration: (String, ?file_name: String?, ?report_diagnostics: bool, ?strict: bool, **untyped) -> Tsrs::TranspileResult
|
|
9
|
+
|
|
10
|
+
# : (*String, ?project: String?, ?cwd: String, **untyped) -> Tsrs::CheckResult
|
|
11
|
+
def self.check: (*String, ?project: String?, ?cwd: String, **untyped) -> Tsrs::CheckResult
|
|
12
|
+
|
|
13
|
+
# : (*String, ?project: String?, ?cwd: String, **untyped) -> Tsrs::CheckResult
|
|
14
|
+
def self.compile: (*String, ?project: String?, ?cwd: String, **untyped) -> Tsrs::CheckResult
|
|
15
|
+
|
|
16
|
+
# : (*String, ?cwd: String) -> Tsrs::CheckResult
|
|
17
|
+
def self.tsc: (*String, ?cwd: String) -> Tsrs::CheckResult
|
|
18
|
+
|
|
19
|
+
# : () -> String
|
|
20
|
+
def self.tsrs_version: () -> String
|
|
21
|
+
|
|
22
|
+
# : () -> String
|
|
23
|
+
def self.typescript_version: () -> String
|
|
24
|
+
|
|
25
|
+
# : (String?, bool, Hash[Symbol, untyped]) -> String
|
|
26
|
+
def self.transpile_request: (String?, bool, Hash[Symbol, untyped]) -> String
|
|
27
|
+
end
|