mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-03 09:52:27 +00:00
fix: documentation issues (#131)
This commit is contained in:
parent
edd21deaca
commit
c32e6e3097
9 changed files with 63 additions and 67 deletions
|
@ -21,7 +21,7 @@ use crate::{
|
||||||
/// The [`GotoDeclarationResponse::Link`](lsp_types::GotoDefinitionResponse::Link) return value
|
/// The [`GotoDeclarationResponse::Link`](lsp_types::GotoDefinitionResponse::Link) return value
|
||||||
/// was introduced in specification version 3.14.0 and requires client-side
|
/// 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
|
/// 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
|
/// ```text
|
||||||
/// InitializeParams::capabilities::text_document::declaration::link_support
|
/// InitializeParams::capabilities::text_document::declaration::link_support
|
||||||
|
|
|
@ -23,7 +23,7 @@ use crate::{
|
||||||
/// The [`GotoDefinitionResponse::Link`](lsp_types::GotoDefinitionResponse::Link) return value
|
/// The [`GotoDefinitionResponse::Link`](lsp_types::GotoDefinitionResponse::Link) return value
|
||||||
/// was introduced in specification version 3.14.0 and requires client-side
|
/// 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
|
/// 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
|
/// ```text
|
||||||
/// InitializeParams::capabilities::text_document::definition::link_support
|
/// InitializeParams::capabilities::text_document::definition::link_support
|
||||||
|
|
|
@ -6,9 +6,9 @@ use crate::{prelude::*, SemanticTokenContext};
|
||||||
///
|
///
|
||||||
/// [`textDocument/semanticTokens/full/delta`]: https://microsoft.github.io/language-server-protocol/specification#textDocument_semanticTokens
|
/// [`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
|
/// Similar to [`semantic_tokens_full`](crate::SemanticTokensFullRequest),
|
||||||
/// returns a sequence of [`SemanticTokensEdit`] to transform a previous result
|
/// except it returns a sequence of [`lsp_types::SemanticTokensEdit`] to
|
||||||
/// into a new result.
|
/// transform a previous result into a new result.
|
||||||
///
|
///
|
||||||
/// # Compatibility
|
/// # Compatibility
|
||||||
///
|
///
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::{prelude::*, SemanticTokenContext};
|
||||||
/// tokens with numbers. In addition, optional support for deltas is available,
|
/// tokens with numbers. In addition, optional support for deltas is available,
|
||||||
/// i.e. [`semantic_tokens_full_delta`].
|
/// i.e. [`semantic_tokens_full_delta`].
|
||||||
///
|
///
|
||||||
/// [`semantic_tokens_full_delta`]: Self::semantic_tokens_full_delta
|
/// [`semantic_tokens_full_delta`]: crate::SemanticTokensDeltaRequest
|
||||||
///
|
///
|
||||||
/// # Compatibility
|
/// # Compatibility
|
||||||
///
|
///
|
||||||
|
|
|
@ -17,7 +17,7 @@ use crate::{
|
||||||
/// then need to resolve the range when necessary using the `workspaceSymbol/
|
/// then need to resolve the range when necessary using the `workspaceSymbol/
|
||||||
/// resolve` request.
|
/// 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
|
/// Servers can only use this new model if clients advertise support for it via
|
||||||
/// the `workspace.symbol.resolve_support` capability.
|
/// the `workspace.symbol.resolve_support` capability.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! # tinymist
|
//! # 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/).
|
//! + A language server following the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/).
|
||||||
//!
|
//!
|
||||||
//! ## Architecture
|
//! ## Architecture
|
||||||
|
@ -43,7 +43,6 @@ pub use server::compiler_init;
|
||||||
pub use server::lsp::*;
|
pub use server::lsp::*;
|
||||||
pub use server::lsp_init::*;
|
pub use server::lsp_init::*;
|
||||||
|
|
||||||
pub use lsp_server::Message;
|
|
||||||
use lsp_server::ResponseError;
|
use lsp_server::ResponseError;
|
||||||
|
|
||||||
type LspResult<Res> = Result<Res, ResponseError>;
|
type LspResult<Res> = Result<Res, ResponseError>;
|
||||||
|
|
|
@ -82,6 +82,17 @@ pub struct CompileServer {
|
||||||
/// The language server client.
|
/// The language server client.
|
||||||
pub client: LspHost<CompileServer>,
|
pub client: LspHost<CompileServer>,
|
||||||
|
|
||||||
|
// 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
|
// Command maps
|
||||||
/// Extra commands provided with `textDocument/executeCommand`.
|
/// Extra commands provided with `textDocument/executeCommand`.
|
||||||
pub exec_cmds: ExecuteCmdMap,
|
pub exec_cmds: ExecuteCmdMap,
|
||||||
|
@ -90,25 +101,17 @@ pub struct CompileServer {
|
||||||
/// Regular commands for dispatching.
|
/// Regular commands for dispatching.
|
||||||
pub regular_cmds: RegularCmdMap,
|
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<DiagnosticsMap>)>,
|
|
||||||
|
|
||||||
// Resources
|
// Resources
|
||||||
pub font: Deferred<SharedFontResolver>,
|
/// The runtime handle to spawn tasks.
|
||||||
pub compiler: Option<CompileClientActor>,
|
|
||||||
pub handle: tokio::runtime::Handle,
|
pub handle: tokio::runtime::Handle,
|
||||||
|
/// The font resolver to use.
|
||||||
|
pub font: Deferred<SharedFontResolver>,
|
||||||
/// Source synchronized with client
|
/// Source synchronized with client
|
||||||
pub memory_changes: HashMap<Arc<Path>, MemoryFileMeta>,
|
pub memory_changes: HashMap<Arc<Path>, MemoryFileMeta>,
|
||||||
|
/// The diagnostics sender to send diagnostics to `crate::actor::cluster`.
|
||||||
|
pub diag_tx: mpsc::UnboundedSender<(String, Option<DiagnosticsMap>)>,
|
||||||
|
/// The compiler actor.
|
||||||
|
pub compiler: Option<CompileClientActor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CompileServer {
|
impl CompileServer {
|
||||||
|
|
|
@ -798,41 +798,6 @@ impl TypstLanguageServer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
struct ExportOpts {
|
|
||||||
page: PageSelection,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_opts(v: Option<&JsonValue>) -> LspResult<ExportOpts> {
|
|
||||||
Ok(match v {
|
|
||||||
Some(opts) => serde_json::from_value::<ExportOpts>(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<ImmutPath> {
|
|
||||||
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<Option<ImmutPath>> {
|
|
||||||
match v {
|
|
||||||
Some(JsonValue::Null) => Ok(None),
|
|
||||||
v => Ok(Some(parse_path(v)?)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Document Synchronization
|
/// Document Synchronization
|
||||||
impl TypstLanguageServer {
|
impl TypstLanguageServer {
|
||||||
fn did_open(&mut self, params: DidOpenTextDocumentParams) -> LspResult<()> {
|
fn did_open(&mut self, params: DidOpenTextDocumentParams) -> LspResult<()> {
|
||||||
|
@ -848,7 +813,6 @@ impl TypstLanguageServer {
|
||||||
let path = as_path_(params.text_document.uri);
|
let path = as_path_(params.text_document.uri);
|
||||||
|
|
||||||
self.remove_source(path.clone()).unwrap();
|
self.remove_source(path.clone()).unwrap();
|
||||||
// self.client.publish_diagnostics(uri, Vec::new(), None);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1080,6 +1044,41 @@ impl TypstLanguageServer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
struct ExportOpts {
|
||||||
|
page: PageSelection,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_opts(v: Option<&JsonValue>) -> LspResult<ExportOpts> {
|
||||||
|
Ok(match v {
|
||||||
|
Some(opts) => serde_json::from_value::<ExportOpts>(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<ImmutPath> {
|
||||||
|
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<Option<ImmutPath>> {
|
||||||
|
match v {
|
||||||
|
Some(JsonValue::Null) => Ok(None),
|
||||||
|
v => Ok(Some(parse_path(v)?)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn invalid_params(msg: impl Into<String>) -> ResponseError {
|
pub fn invalid_params(msg: impl Into<String>) -> ResponseError {
|
||||||
ResponseError {
|
ResponseError {
|
||||||
code: ErrorCode::InvalidParams as i32,
|
code: ErrorCode::InvalidParams as i32,
|
||||||
|
|
|
@ -1,15 +1,10 @@
|
||||||
use std::{
|
use std::{
|
||||||
io::{self, BufRead, Write},
|
io::{self, BufRead, Read, Write},
|
||||||
thread,
|
thread,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crossbeam_channel::{bounded, Receiver, Sender};
|
use crossbeam_channel::{bounded, Receiver, Sender};
|
||||||
|
use lsp_server::{Connection, Message};
|
||||||
use crate::Message;
|
|
||||||
|
|
||||||
use std::io::Read;
|
|
||||||
|
|
||||||
use lsp_server::Connection;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
#[cfg_attr(feature = "clap", derive(clap::Parser))]
|
#[cfg_attr(feature = "clap", derive(clap::Parser))]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue