diff --git a/crates/tinymist-query/src/goto_declaration.rs b/crates/tinymist-query/src/goto_declaration.rs index 840598a3..88f1c7d6 100644 --- a/crates/tinymist-query/src/goto_declaration.rs +++ b/crates/tinymist-query/src/goto_declaration.rs @@ -21,7 +21,7 @@ use crate::{ /// The [`GotoDeclarationResponse::Link`](lsp_types::GotoDefinitionResponse::Link) return value /// was introduced in specification version 3.14.0 and requires client-side /// support in order to be used. It can be returned if the client set the -/// following field to `true` in the [`initialize`](Self::initialize) method: +/// following field to `true` in the `initialize` method: /// /// ```text /// InitializeParams::capabilities::text_document::declaration::link_support diff --git a/crates/tinymist-query/src/goto_definition.rs b/crates/tinymist-query/src/goto_definition.rs index d8022dce..f16adee5 100644 --- a/crates/tinymist-query/src/goto_definition.rs +++ b/crates/tinymist-query/src/goto_definition.rs @@ -23,7 +23,7 @@ use crate::{ /// The [`GotoDefinitionResponse::Link`](lsp_types::GotoDefinitionResponse::Link) return value /// was introduced in specification version 3.14.0 and requires client-side /// support in order to be used. It can be returned if the client set the -/// following field to `true` in the [`initialize`](Self::initialize) method: +/// following field to `true` in the `initialize` method: /// /// ```text /// InitializeParams::capabilities::text_document::definition::link_support diff --git a/crates/tinymist-query/src/semantic_tokens_delta.rs b/crates/tinymist-query/src/semantic_tokens_delta.rs index 23025275..9204d86e 100644 --- a/crates/tinymist-query/src/semantic_tokens_delta.rs +++ b/crates/tinymist-query/src/semantic_tokens_delta.rs @@ -6,9 +6,9 @@ use crate::{prelude::*, SemanticTokenContext}; /// /// [`textDocument/semanticTokens/full/delta`]: https://microsoft.github.io/language-server-protocol/specification#textDocument_semanticTokens /// -/// Similar to [`semantic_tokens_full`](Self::semantic_tokens_full), except it -/// returns a sequence of [`SemanticTokensEdit`] to transform a previous result -/// into a new result. +/// Similar to [`semantic_tokens_full`](crate::SemanticTokensFullRequest), +/// except it returns a sequence of [`lsp_types::SemanticTokensEdit`] to +/// transform a previous result into a new result. /// /// # Compatibility /// diff --git a/crates/tinymist-query/src/semantic_tokens_full.rs b/crates/tinymist-query/src/semantic_tokens_full.rs index 5fc649e7..213588b0 100644 --- a/crates/tinymist-query/src/semantic_tokens_full.rs +++ b/crates/tinymist-query/src/semantic_tokens_full.rs @@ -11,7 +11,7 @@ use crate::{prelude::*, SemanticTokenContext}; /// tokens with numbers. In addition, optional support for deltas is available, /// i.e. [`semantic_tokens_full_delta`]. /// -/// [`semantic_tokens_full_delta`]: Self::semantic_tokens_full_delta +/// [`semantic_tokens_full_delta`]: crate::SemanticTokensDeltaRequest /// /// # Compatibility /// diff --git a/crates/tinymist-query/src/symbol.rs b/crates/tinymist-query/src/symbol.rs index f423fd09..29564c7d 100644 --- a/crates/tinymist-query/src/symbol.rs +++ b/crates/tinymist-query/src/symbol.rs @@ -17,7 +17,7 @@ use crate::{ /// then need to resolve the range when necessary using the `workspaceSymbol/ /// resolve` request. /// -/// [`workspaceSymbol/resolve`]: Self::symbol_resolve +/// // [`workspaceSymbol/resolve`]: Self::symbol_resolve /// /// Servers can only use this new model if clients advertise support for it via /// the `workspace.symbol.resolve_support` capability. diff --git a/crates/tinymist/src/lib.rs b/crates/tinymist/src/lib.rs index 9cb41baf..d89e7eaa 100644 --- a/crates/tinymist/src/lib.rs +++ b/crates/tinymist/src/lib.rs @@ -1,6 +1,6 @@ //! # tinymist //! -//! This crate provides an integrated service for [Typst](https://typst.app/) [taɪpst]. It provides: +//! This crate provides an integrated service for [Typst](https://typst.app/). It provides: //! + A language server following the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/). //! //! ## Architecture @@ -43,7 +43,6 @@ pub use server::compiler_init; pub use server::lsp::*; pub use server::lsp_init::*; -pub use lsp_server::Message; use lsp_server::ResponseError; type LspResult = Result; diff --git a/crates/tinymist/src/server/compiler.rs b/crates/tinymist/src/server/compiler.rs index 60636ca2..7bd79e0a 100644 --- a/crates/tinymist/src/server/compiler.rs +++ b/crates/tinymist/src/server/compiler.rs @@ -82,6 +82,17 @@ pub struct CompileServer { /// The language server client. pub client: LspHost, + // State to synchronize with the client. + /// Whether the server is shutting down. + pub shutdown_requested: bool, + + // Configurations + /// User configuration from the editor. + pub config: CompileConfig, + /// Const configuration initialized at the start of the session. + /// For example, the position encoding. + pub const_config: CompilerConstConfig, + // Command maps /// Extra commands provided with `textDocument/executeCommand`. pub exec_cmds: ExecuteCmdMap, @@ -90,25 +101,17 @@ pub struct CompileServer { /// Regular commands for dispatching. pub regular_cmds: RegularCmdMap, - // State to synchronize with the client. - /// Whether the server is shutting down. - pub shutdown_requested: bool, - // Configurations - /// User configuration from the editor. - pub config: CompileConfig, - /// Const configuration initialized at the start of the session. - /// For example, the position encoding. - pub const_config: CompilerConstConfig, - // /// The default opts for the compiler. - // pub compile_opts: CompileOnceOpts, - pub diag_tx: mpsc::UnboundedSender<(String, Option)>, - // Resources - pub font: Deferred, - pub compiler: Option, + /// The runtime handle to spawn tasks. pub handle: tokio::runtime::Handle, + /// The font resolver to use. + pub font: Deferred, /// Source synchronized with client pub memory_changes: HashMap, MemoryFileMeta>, + /// The diagnostics sender to send diagnostics to `crate::actor::cluster`. + pub diag_tx: mpsc::UnboundedSender<(String, Option)>, + /// The compiler actor. + pub compiler: Option, } impl CompileServer { diff --git a/crates/tinymist/src/server/lsp.rs b/crates/tinymist/src/server/lsp.rs index 2f0c7b3f..79319548 100644 --- a/crates/tinymist/src/server/lsp.rs +++ b/crates/tinymist/src/server/lsp.rs @@ -798,41 +798,6 @@ impl TypstLanguageServer { } } -#[derive(Debug, Clone, Serialize, Deserialize)] -struct ExportOpts { - page: PageSelection, -} - -fn parse_opts(v: Option<&JsonValue>) -> LspResult { - Ok(match v { - Some(opts) => serde_json::from_value::(opts.clone()) - .map_err(|_| invalid_params("The third argument is not a valid object"))?, - _ => ExportOpts { - page: PageSelection::First, - }, - }) -} - -fn parse_path(v: Option<&JsonValue>) -> LspResult { - let new_entry = match v { - Some(JsonValue::String(s)) => Path::new(s).clean().as_path().into(), - _ => { - return Err(invalid_params( - "The first parameter is not a valid path or null", - )) - } - }; - - Ok(new_entry) -} - -fn parse_path_or_null(v: Option<&JsonValue>) -> LspResult> { - match v { - Some(JsonValue::Null) => Ok(None), - v => Ok(Some(parse_path(v)?)), - } -} - /// Document Synchronization impl TypstLanguageServer { fn did_open(&mut self, params: DidOpenTextDocumentParams) -> LspResult<()> { @@ -848,7 +813,6 @@ impl TypstLanguageServer { let path = as_path_(params.text_document.uri); self.remove_source(path.clone()).unwrap(); - // self.client.publish_diagnostics(uri, Vec::new(), None); Ok(()) } @@ -1080,6 +1044,41 @@ impl TypstLanguageServer { } } +#[derive(Debug, Clone, Serialize, Deserialize)] +struct ExportOpts { + page: PageSelection, +} + +fn parse_opts(v: Option<&JsonValue>) -> LspResult { + Ok(match v { + Some(opts) => serde_json::from_value::(opts.clone()) + .map_err(|_| invalid_params("The third argument is not a valid object"))?, + _ => ExportOpts { + page: PageSelection::First, + }, + }) +} + +fn parse_path(v: Option<&JsonValue>) -> LspResult { + let new_entry = match v { + Some(JsonValue::String(s)) => Path::new(s).clean().as_path().into(), + _ => { + return Err(invalid_params( + "The first parameter is not a valid path or null", + )) + } + }; + + Ok(new_entry) +} + +fn parse_path_or_null(v: Option<&JsonValue>) -> LspResult> { + match v { + Some(JsonValue::Null) => Ok(None), + v => Ok(Some(parse_path(v)?)), + } +} + pub fn invalid_params(msg: impl Into) -> ResponseError { ResponseError { code: ErrorCode::InvalidParams as i32, diff --git a/crates/tinymist/src/transport.rs b/crates/tinymist/src/transport.rs index 2a069823..a56ba232 100644 --- a/crates/tinymist/src/transport.rs +++ b/crates/tinymist/src/transport.rs @@ -1,15 +1,10 @@ use std::{ - io::{self, BufRead, Write}, + io::{self, BufRead, Read, Write}, thread, }; use crossbeam_channel::{bounded, Receiver, Sender}; - -use crate::Message; - -use std::io::Read; - -use lsp_server::Connection; +use lsp_server::{Connection, Message}; #[derive(Debug, Clone, Default)] #[cfg_attr(feature = "clap", derive(clap::Parser))]