feat: allow running server with loading font once and on rootless files (#94)

* dev: change system config

* docs: update config doc

* dev: clean up tightly coupled world

* dev: load font once

* docs: add more comments to tinymist-query

* dev: merge compiler layers

* feat: allow run lsp on rootless files

* build: bump ts

* fix: workspace dep

* build: bump preview

* dev: correctly check inactive state

* fix: weird cargo default features
This commit is contained in:
Myriad-Dreamin 2024-03-26 10:33:56 +08:00 committed by GitHub
parent f0a9c3e880
commit 76b4e91046
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
46 changed files with 974 additions and 638 deletions

View file

@ -1,23 +1,41 @@
use crate::prelude::*;
use crate::{prelude::*, SyntaxRequest};
/// The [`textDocument/selectionRange`] request is sent from the client to the
/// server to return suggested selection ranges at an array of given positions.
/// A selection range is a range around the cursor position which the user might
/// be interested in selecting.
///
/// [`textDocument/selectionRange`]: https://microsoft.github.io/language-server-protocol/specification#textDocument_selectionRange
///
/// A selection range in the return array is for the position in the provided
/// parameters at the same index. Therefore `params.positions[i]` must be
/// contained in `result[i].range`.
///
/// # Compatibility
///
/// This request was introduced in specification version 3.15.0.
#[derive(Debug, Clone)]
pub struct SelectionRangeRequest {
/// The path of the document to get selection ranges for.
pub path: PathBuf,
/// The positions to get selection ranges for.
pub positions: Vec<LspPosition>,
}
impl SelectionRangeRequest {
pub fn request(
impl SyntaxRequest for SelectionRangeRequest {
type Response = Vec<SelectionRange>;
fn request(
self,
source: Source,
source: &Source,
position_encoding: PositionEncoding,
) -> Option<Vec<SelectionRange>> {
) -> Option<Self::Response> {
let mut ranges = Vec::new();
for position in self.positions {
let typst_offset = lsp_to_typst::position(position, position_encoding, &source)?;
let typst_offset = lsp_to_typst::position(position, position_encoding, source)?;
let tree = LinkedNode::new(source.root());
let leaf = tree.leaf_at(typst_offset + 1)?;
ranges.push(range_for_node(&source, position_encoding, &leaf));
ranges.push(range_for_node(source, position_encoding, &leaf));
}
Some(ranges)