mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-09-07 10:50:40 +00:00
org
This commit is contained in:
parent
1bf4f8390e
commit
54f19d0c37
2 changed files with 23 additions and 11 deletions
|
@ -109,11 +109,12 @@ impl From<Token> for Span {
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize)]
|
#[derive(Clone, Debug, Serialize)]
|
||||||
pub enum Node {
|
pub enum Node {
|
||||||
Text {
|
Block(Block),
|
||||||
|
Comment {
|
||||||
content: String,
|
content: String,
|
||||||
span: Span,
|
span: Span,
|
||||||
},
|
},
|
||||||
Comment {
|
Text {
|
||||||
content: String,
|
content: String,
|
||||||
span: Span,
|
span: Span,
|
||||||
},
|
},
|
||||||
|
@ -122,16 +123,15 @@ pub enum Node {
|
||||||
filters: Vec<DjangoFilter>,
|
filters: Vec<DjangoFilter>,
|
||||||
span: Span,
|
span: Span,
|
||||||
},
|
},
|
||||||
Block(Block),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Node {
|
impl Node {
|
||||||
pub fn span(&self) -> Option<&Span> {
|
pub fn span(&self) -> Option<&Span> {
|
||||||
match self {
|
match self {
|
||||||
Node::Text { span, .. } => Some(span),
|
|
||||||
Node::Comment { span, .. } => Some(span),
|
|
||||||
Node::Variable { span, .. } => Some(span),
|
|
||||||
Node::Block(block) => Some(&block.tag().span),
|
Node::Block(block) => Some(&block.tag().span),
|
||||||
|
Node::Comment { span, .. } => Some(span),
|
||||||
|
Node::Text { span, .. } => Some(span),
|
||||||
|
Node::Variable { span, .. } => Some(span),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,18 +169,18 @@ pub enum Block {
|
||||||
impl Block {
|
impl Block {
|
||||||
pub fn tag(&self) -> &Tag {
|
pub fn tag(&self) -> &Tag {
|
||||||
match self {
|
match self {
|
||||||
Self::Container { tag, .. }
|
Self::Branch { tag, .. }
|
||||||
| Self::Branch { tag, .. }
|
| Self::Container { tag, .. }
|
||||||
| Self::Single { tag }
|
| Self::Closing { tag }
|
||||||
| Self::Inclusion { tag, .. }
|
| Self::Inclusion { tag, .. }
|
||||||
| Self::Closing { tag } => tag,
|
| Self::Single { tag } => tag,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodes(&self) -> Option<&Vec<Node>> {
|
pub fn nodes(&self) -> Option<&Vec<Node>> {
|
||||||
match self {
|
match self {
|
||||||
Block::Container { nodes, .. } => Some(nodes),
|
|
||||||
Block::Branch { nodes, .. } => Some(nodes),
|
Block::Branch { nodes, .. } => Some(nodes),
|
||||||
|
Block::Container { nodes, .. } => Some(nodes),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,10 @@ impl Worker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Attempts to execute a task immediately without waiting.
|
||||||
|
/// Returns an error if the worker's channel is full.
|
||||||
|
///
|
||||||
|
/// Best for non-critical tasks where backpressure is desired.
|
||||||
pub fn execute<T>(&self, task: T) -> Result<()>
|
pub fn execute<T>(&self, task: T) -> Result<()>
|
||||||
where
|
where
|
||||||
T: Task + 'static,
|
T: Task + 'static,
|
||||||
|
@ -78,6 +82,10 @@ impl Worker {
|
||||||
.map_err(|e| anyhow::anyhow!("Failed to execute task: {}", e))
|
.map_err(|e| anyhow::anyhow!("Failed to execute task: {}", e))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Submits a task asynchronously, waiting if the channel is full.
|
||||||
|
///
|
||||||
|
/// Good for tasks that must be processed but where you don't need
|
||||||
|
/// the result immediately.
|
||||||
pub async fn submit<T>(&self, task: T) -> Result<()>
|
pub async fn submit<T>(&self, task: T) -> Result<()>
|
||||||
where
|
where
|
||||||
T: Task + 'static,
|
T: Task + 'static,
|
||||||
|
@ -89,6 +97,10 @@ impl Worker {
|
||||||
.map_err(|e| anyhow::anyhow!("Failed to submit task: {}", e))
|
.map_err(|e| anyhow::anyhow!("Failed to submit task: {}", e))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Submits a task and waits for its result.
|
||||||
|
///
|
||||||
|
/// Best when you need the output of the task. This method will
|
||||||
|
/// wait both for space to submit the task and for its completion.
|
||||||
pub async fn wait_for<T>(&self, task: T) -> Result<T::Output>
|
pub async fn wait_for<T>(&self, task: T) -> Result<T::Output>
|
||||||
where
|
where
|
||||||
T: Task + 'static,
|
T: Task + 'static,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue