mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-09-11 21:06:31 +00:00
add errors
This commit is contained in:
parent
7bb9904f81
commit
a4b6742c6a
15 changed files with 42 additions and 5 deletions
|
@ -5,6 +5,7 @@ use thiserror::Error;
|
|||
#[derive(Clone, Debug, Default, Serialize)]
|
||||
pub struct Ast {
|
||||
nodes: Vec<Node>,
|
||||
errors: Vec<AstError>,
|
||||
}
|
||||
|
||||
impl Ast {
|
||||
|
@ -12,12 +13,20 @@ impl Ast {
|
|||
&self.nodes
|
||||
}
|
||||
|
||||
pub fn errors(&self) -> &Vec<AstError> {
|
||||
&self.errors
|
||||
}
|
||||
|
||||
pub fn add_node(&mut self, node: Node) {
|
||||
self.nodes.push(node);
|
||||
}
|
||||
|
||||
pub fn add_error(&mut self, error: AstError) {
|
||||
self.errors.push(error);
|
||||
}
|
||||
|
||||
pub fn finalize(&mut self) -> Result<Ast, AstError> {
|
||||
if self.nodes.is_empty() {
|
||||
if self.nodes.is_empty() && self.errors.is_empty() {
|
||||
return Err(AstError::EmptyAst);
|
||||
}
|
||||
Ok(self.clone())
|
||||
|
@ -123,10 +132,24 @@ pub enum AttributeValue {
|
|||
|
||||
pub type Attributes = BTreeMap<String, AttributeValue>;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
#[derive(Clone, Debug, Error, Serialize)]
|
||||
pub enum AstError {
|
||||
#[error("error parsing django tag, recieved empty tag name")]
|
||||
EmptyTag,
|
||||
#[error("empty ast")]
|
||||
#[error("Empty AST")]
|
||||
EmptyAst,
|
||||
#[error("Stream error: {0}")]
|
||||
StreamError(String),
|
||||
#[error("Unclosed tag: {0}")]
|
||||
UnclosedTag(String),
|
||||
#[error("Unexpected tag: {0}")]
|
||||
UnexpectedTag(String),
|
||||
#[error("Invalid tag: {0}")]
|
||||
InvalidTag(String),
|
||||
#[error("Block error: {0} in {1}")]
|
||||
BlockError(String, String),
|
||||
#[error("Argument error: {0} - {1}")]
|
||||
ArgumentError(String, String),
|
||||
#[error("Unexpected token")]
|
||||
UnexpectedToken,
|
||||
#[error("Unexpected end of file")]
|
||||
UnexpectedEof,
|
||||
}
|
||||
|
|
|
@ -7,3 +7,4 @@ nodes:
|
|||
Comment: HTML comment
|
||||
- Django:
|
||||
Comment: Django comment
|
||||
errors: []
|
||||
|
|
|
@ -36,3 +36,4 @@ nodes:
|
|||
Closing:
|
||||
name: endif
|
||||
bits: []
|
||||
errors: []
|
||||
|
|
|
@ -30,3 +30,4 @@ nodes:
|
|||
Closing:
|
||||
name: endfor
|
||||
bits: []
|
||||
errors: []
|
||||
|
|
|
@ -17,3 +17,4 @@ nodes:
|
|||
Closing:
|
||||
name: endif
|
||||
bits: []
|
||||
errors: []
|
||||
|
|
|
@ -11,3 +11,4 @@ nodes:
|
|||
filters:
|
||||
- name: title
|
||||
arguments: []
|
||||
errors: []
|
||||
|
|
|
@ -15,3 +15,4 @@ nodes:
|
|||
arguments: []
|
||||
- name: upper
|
||||
arguments: []
|
||||
errors: []
|
||||
|
|
|
@ -107,3 +107,4 @@ nodes:
|
|||
name: endif
|
||||
bits: []
|
||||
- Text: "!"
|
||||
errors: []
|
||||
|
|
|
@ -37,3 +37,4 @@ nodes:
|
|||
Closing:
|
||||
name: endfor
|
||||
bits: []
|
||||
errors: []
|
||||
|
|
|
@ -128,3 +128,4 @@ nodes:
|
|||
Closing:
|
||||
name: endif
|
||||
bits: []
|
||||
errors: []
|
||||
|
|
|
@ -5,3 +5,4 @@ expression: ast
|
|||
nodes:
|
||||
- Html:
|
||||
Doctype: "!DOCTYPE"
|
||||
errors: []
|
||||
|
|
|
@ -11,3 +11,4 @@ nodes:
|
|||
Value: container
|
||||
children:
|
||||
- Text: Hello
|
||||
errors: []
|
||||
|
|
|
@ -9,3 +9,4 @@ nodes:
|
|||
attributes:
|
||||
type:
|
||||
Value: text
|
||||
errors: []
|
||||
|
|
|
@ -19,3 +19,4 @@ nodes:
|
|||
content: "Multi-line\n comment"
|
||||
kind: MultiLine
|
||||
- Text: console.log(x);
|
||||
errors: []
|
||||
|
|
|
@ -16,3 +16,4 @@ nodes:
|
|||
- Text: "{"
|
||||
- Text: "color: blue;"
|
||||
- Text: "}"
|
||||
errors: []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue