mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-03 17:58:17 +00:00
feat: debug lsp with mirror feature
This commit is contained in:
parent
b1d977cfbe
commit
23d6237dfe
8 changed files with 134 additions and 15 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,5 +4,6 @@ result*
|
|||
.direnv
|
||||
.envrc
|
||||
node_modules/
|
||||
/local/
|
||||
/editors/vscode/out/
|
||||
/editors/lapce/out/
|
||||
|
|
31
Cargo.lock
generated
31
Cargo.lock
generated
|
@ -471,6 +471,9 @@ dependencies = [
|
|||
"anstyle",
|
||||
"clap_lex",
|
||||
"strsim 0.11.0",
|
||||
"terminal_size",
|
||||
"unicase",
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -482,6 +485,16 @@ dependencies = [
|
|||
"clap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_complete_fig"
|
||||
version = "4.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "54b3e65f91fabdd23cac3d57d39d5d938b4daabd070c335c006dccb866a61110"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"clap_complete",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.0"
|
||||
|
@ -3314,6 +3327,16 @@ dependencies = [
|
|||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "terminal_size"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7"
|
||||
dependencies = [
|
||||
"rustix",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.57"
|
||||
|
@ -3399,6 +3422,12 @@ version = "0.11.0"
|
|||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
"cargo_metadata",
|
||||
"clap",
|
||||
"clap_builder",
|
||||
"clap_complete",
|
||||
"clap_complete_fig",
|
||||
"clap_mangen",
|
||||
"comemo",
|
||||
"env_logger",
|
||||
"futures",
|
||||
|
@ -3411,6 +3440,7 @@ dependencies = [
|
|||
"serde_json",
|
||||
"tinymist-query",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"tower",
|
||||
"tower-lsp",
|
||||
"typst",
|
||||
|
@ -3419,6 +3449,7 @@ dependencies = [
|
|||
"typst-preview",
|
||||
"typst-ts-compiler",
|
||||
"typst-ts-core",
|
||||
"vergen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -61,6 +61,7 @@ tokio = { version = "1.34.0", features = [
|
|||
"rt-multi-thread",
|
||||
"io-std",
|
||||
] }
|
||||
tokio-util = "0.7.10"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ once_cell.workspace = true
|
|||
anyhow.workspace = true
|
||||
comemo.workspace = true
|
||||
tokio.workspace = true
|
||||
tokio-util.workspace = true
|
||||
futures.workspace = true
|
||||
itertools.workspace = true
|
||||
async-trait.workspace = true
|
||||
|
@ -28,6 +29,12 @@ serde_json.workspace = true
|
|||
parking_lot.workspace = true
|
||||
paste = "1.0"
|
||||
|
||||
clap = { workspace = true, optional = true }
|
||||
clap_builder.workspace = true
|
||||
clap_complete.workspace = true
|
||||
clap_complete_fig.workspace = true
|
||||
clap_mangen.workspace = true
|
||||
|
||||
typst.workspace = true
|
||||
typst-pdf.workspace = true
|
||||
typst-assets = { workspace = true, features = ["fonts"] }
|
||||
|
@ -43,5 +50,14 @@ typst-preview.workspace = true
|
|||
tower.workspace = true
|
||||
tower-lsp.workspace = true
|
||||
|
||||
[features]
|
||||
default = ["cli"]
|
||||
cli = ["clap"]
|
||||
|
||||
[build-dependencies]
|
||||
anyhow.workspace = true
|
||||
vergen.workspace = true
|
||||
cargo_metadata = "0.18.0"
|
||||
|
||||
# [lints]
|
||||
# workspace = true
|
||||
|
|
23
crates/tinymist/build.rs
Normal file
23
crates/tinymist/build.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
use anyhow::Result;
|
||||
use vergen::EmitBuilder;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// Emit the instructions
|
||||
EmitBuilder::builder()
|
||||
.all_cargo()
|
||||
.build_timestamp()
|
||||
.git_sha(false)
|
||||
.git_describe(true, true, None)
|
||||
.all_rustc()
|
||||
.emit()?;
|
||||
|
||||
let metadata = cargo_metadata::MetadataCommand::new().exec().unwrap();
|
||||
let typst = metadata
|
||||
.packages
|
||||
.iter()
|
||||
.find(|package| package.name == "typst")
|
||||
.expect("Typst should be a dependency");
|
||||
|
||||
println!("cargo:rustc-env=TYPST_VERSION={}", typst.version);
|
||||
Ok(())
|
||||
}
|
34
crates/tinymist/src/args.rs
Normal file
34
crates/tinymist/src/args.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
use once_cell::sync::Lazy;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(feature = "clap", derive(clap::Parser))]
|
||||
#[cfg_attr(feature = "clap", clap(name = "tinymist", author, version, about, long_version(LONG_VERSION.as_str())))]
|
||||
pub struct CliArguments {
|
||||
/// Mirror the stdin to the specified file
|
||||
#[cfg_attr(feature = "clap", clap(long, default_value = "", value_name = "FILE"))]
|
||||
pub mirror: String,
|
||||
/// Mirror input from the file
|
||||
#[cfg_attr(feature = "clap", clap(long, default_value = "", value_name = "FILE"))]
|
||||
pub mirror_input: String,
|
||||
}
|
||||
|
||||
pub static LONG_VERSION: Lazy<String> = Lazy::new(|| {
|
||||
format!(
|
||||
"
|
||||
Build Timestamp: {}
|
||||
Build Git Describe: {}
|
||||
Commit SHA: {}
|
||||
Commit Date: {}
|
||||
Commit Branch: {}
|
||||
Cargo Target Triple: {}
|
||||
Typst Version: {}
|
||||
",
|
||||
env!("VERGEN_BUILD_TIMESTAMP"),
|
||||
env!("VERGEN_GIT_DESCRIBE"),
|
||||
option_env!("VERGEN_GIT_SHA").unwrap_or("None"),
|
||||
option_env!("VERGEN_GIT_COMMIT_TIMESTAMP").unwrap_or("None"),
|
||||
option_env!("VERGEN_GIT_BRANCH").unwrap_or("None"),
|
||||
env!("VERGEN_CARGO_TARGET_TRIPLE"),
|
||||
env!("TYPST_VERSION"),
|
||||
)
|
||||
});
|
|
@ -2,30 +2,23 @@
|
|||
|
||||
use core::fmt;
|
||||
use core::task::{Context, Poll};
|
||||
use std::io::Write;
|
||||
use std::time::Instant;
|
||||
|
||||
use clap::Parser;
|
||||
use futures::future::BoxFuture;
|
||||
use log::info;
|
||||
use tinymist::TypstServer;
|
||||
use tokio::io::AsyncRead;
|
||||
use tokio_util::io::InspectReader;
|
||||
use tower_lsp::{
|
||||
jsonrpc::{Request, Response},
|
||||
LspService, Server,
|
||||
};
|
||||
|
||||
// #[derive(Debug, Clone)]
|
||||
// struct Args {}
|
||||
use crate::args::CliArguments;
|
||||
|
||||
// fn arg_parser() -> OptionParser<Args> {
|
||||
// construct!(Args {}).to_options().version(
|
||||
// format!(
|
||||
// "{}, commit {} (Typst version {TYPST_VERSION})",
|
||||
// env!("CARGO_PKG_VERSION"),
|
||||
// env!("GIT_COMMIT")
|
||||
// )
|
||||
// .as_str(),
|
||||
// )
|
||||
// }
|
||||
|
||||
// pub const TYPST_VERSION: &str = env!("TYPST_VERSION");
|
||||
mod args;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
|
@ -41,7 +34,20 @@ async fn main() {
|
|||
.filter_module("typst_ts_compiler::service::watch", log::LevelFilter::Debug)
|
||||
.try_init();
|
||||
|
||||
let stdin = tokio::io::stdin();
|
||||
let args = CliArguments::parse();
|
||||
info!("Arguments: {:#?}", args);
|
||||
|
||||
let stdin: Box<dyn AsyncRead + Unpin> = if !args.mirror_input.is_empty() {
|
||||
let file = tokio::fs::File::open(&args.mirror_input).await.unwrap();
|
||||
Box::new(file)
|
||||
} else if args.mirror.is_empty() {
|
||||
Box::new(tokio::io::stdin())
|
||||
} else {
|
||||
let mut file = std::fs::File::create(&args.mirror).unwrap();
|
||||
Box::new(InspectReader::new(tokio::io::stdin(), move |bytes| {
|
||||
file.write_all(bytes).unwrap();
|
||||
}))
|
||||
};
|
||||
let stdout = tokio::io::stdout();
|
||||
|
||||
let (inner, socket) = LspService::new(TypstServer::new);
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
Uri,
|
||||
WorkspaceConfiguration,
|
||||
TextEditor,
|
||||
ExtensionMode,
|
||||
} from "vscode";
|
||||
import * as path from "path";
|
||||
import * as child_process from "child_process";
|
||||
|
@ -31,6 +32,12 @@ async function startClient(context: ExtensionContext): Promise<void> {
|
|||
const serverCommand = getServer(config);
|
||||
const run = {
|
||||
command: serverCommand,
|
||||
args: [
|
||||
/// The `--mirror` flag is only used in development/test mode for testing
|
||||
...(context.extensionMode != ExtensionMode.Production
|
||||
? ["--mirror", "tinymist-lsp.log"]
|
||||
: []),
|
||||
],
|
||||
options: { env: Object.assign({}, process.env, { RUST_BACKTRACE: "1" }) },
|
||||
};
|
||||
const serverOptions: ServerOptions = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue