fix: documentation issues (#131)

This commit is contained in:
Myriad-Dreamin 2024-03-30 18:51:30 +08:00 committed by GitHub
parent edd21deaca
commit c32e6e3097
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 63 additions and 67 deletions

View file

@ -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

View file

@ -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

View file

@ -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
///

View file

@ -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
///

View file

@ -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.

View file

@ -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<Res> = Result<Res, ResponseError>;

View file

@ -82,6 +82,17 @@ pub struct CompileServer {
/// The language server client.
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
/// 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<DiagnosticsMap>)>,
// Resources
pub font: Deferred<SharedFontResolver>,
pub compiler: Option<CompileClientActor>,
/// The runtime handle to spawn tasks.
pub handle: tokio::runtime::Handle,
/// The font resolver to use.
pub font: Deferred<SharedFontResolver>,
/// Source synchronized with client
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 {

View file

@ -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
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<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 {
ResponseError {
code: ErrorCode::InvalidParams as i32,

View file

@ -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))]