Skip to content

Commit

Permalink
Move SyntaxTree to syntax module
Browse files Browse the repository at this point in the history
  • Loading branch information
pfoerster committed May 13, 2019
1 parent 90e512e commit f60b0f5
Show file tree
Hide file tree
Showing 23 changed files with 68 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/completion/latex/citation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::completion::latex::combinators::LatexCombinators;
use crate::feature::FeatureRequest;
use crate::syntax::bibtex::BibtexDeclaration;
use crate::syntax::latex::CITATION_COMMANDS;
use crate::workspace::SyntaxTree;
use crate::syntax::SyntaxTree;
use lsp_types::{CompletionItem, CompletionParams};

pub struct LatexCitationCompletionProvider;
Expand Down
3 changes: 1 addition & 2 deletions src/completion/latex/combinators.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::feature::FeatureRequest;
use crate::syntax::latex::*;
use crate::syntax::text::SyntaxNode;
use crate::workspace::SyntaxTree;
use crate::syntax::SyntaxTree;
use lsp_types::{CompletionItem, CompletionParams};

pub struct LatexCombinators;
Expand Down
3 changes: 2 additions & 1 deletion src/completion/latex/data/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::syntax::latex::{LatexIncludeAnalyzer, LatexVisitor};
use crate::workspace::{Document, SyntaxTree};
use crate::syntax::SyntaxTree;
use crate::workspace::Document;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion src/completion/latex/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::completion::factory;
use crate::completion::latex::combinators::LatexCombinators;
use crate::feature::FeatureRequest;
use crate::syntax::latex::*;
use crate::workspace::SyntaxTree;
use crate::syntax::SyntaxTree;
use lsp_types::{CompletionItem, CompletionParams};
use std::borrow::Cow;

Expand Down
2 changes: 1 addition & 1 deletion src/completion/latex/user_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::completion::latex::combinators::LatexCombinators;
use crate::feature::FeatureRequest;
use crate::syntax::latex::{LatexCommandAnalyzer, LatexVisitor};
use crate::syntax::text::SyntaxNode;
use crate::workspace::SyntaxTree;
use crate::syntax::SyntaxTree;
use itertools::Itertools;
use lsp_types::{CompletionItem, CompletionParams};
use std::borrow::Cow;
Expand Down
3 changes: 2 additions & 1 deletion src/completion/quality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::feature::FeatureRequest;
use crate::syntax::bibtex::*;
use crate::syntax::latex::*;
use crate::syntax::text::SyntaxNode;
use crate::workspace::{Document, SyntaxTree};
use crate::syntax::SyntaxTree;
use crate::workspace::Document;
use lsp_types::{CompletionItem, CompletionParams, Position};

pub struct OrderByQualityCompletionProvider;
Expand Down
3 changes: 2 additions & 1 deletion src/definition/latex_citation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::feature::FeatureRequest;
use crate::syntax::bibtex::BibtexDeclaration;
use crate::syntax::latex::{LatexCitationAnalyzer, LatexVisitor};
use crate::syntax::text::SyntaxNode;
use crate::workspace::{Document, SyntaxTree};
use crate::syntax::SyntaxTree;
use crate::workspace::Document;
use lsp_types::{Location, TextDocumentPositionParams};

pub struct LatexCitationDefinitionProvider;
Expand Down
3 changes: 2 additions & 1 deletion src/definition/latex_label.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::feature::FeatureRequest;
use crate::syntax::latex::*;
use crate::syntax::text::SyntaxNode;
use crate::workspace::{Document, SyntaxTree};
use crate::syntax::SyntaxTree;
use crate::workspace::Document;
use lsp_types::{Location, TextDocumentPositionParams};

pub struct LatexLabelDefinitionProvider;
Expand Down
2 changes: 1 addition & 1 deletion src/folding/bibtex_declaration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::feature::FeatureRequest;
use crate::syntax::bibtex::BibtexDeclaration;
use crate::syntax::text::SyntaxNode;
use crate::workspace::SyntaxTree;
use crate::syntax::SyntaxTree;
use lsp_types::{FoldingRange, FoldingRangeKind, FoldingRangeParams};

pub struct BibtexDeclarationFoldingProvider;
Expand Down
2 changes: 1 addition & 1 deletion src/folding/latex_environment.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::feature::FeatureRequest;
use crate::syntax::latex::{LatexEnvironmentAnalyzer, LatexVisitor};
use crate::syntax::text::SyntaxNode;
use crate::workspace::SyntaxTree;
use crate::syntax::SyntaxTree;
use lsp_types::{FoldingRange, FoldingRangeKind, FoldingRangeParams};

pub struct LatexEnvironmentFoldingProvider;
Expand Down
2 changes: 1 addition & 1 deletion src/folding/latex_section.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::feature::FeatureRequest;
use crate::syntax::latex::{LatexSectionAnalyzer, LatexVisitor};
use crate::syntax::text::SyntaxNode;
use crate::workspace::SyntaxTree;
use crate::syntax::SyntaxTree;
use lsp_types::{FoldingRange, FoldingRangeKind, FoldingRangeParams};

pub struct LatexSectionFoldingProvider;
Expand Down
2 changes: 1 addition & 1 deletion src/highlight/latex_label.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::feature::FeatureRequest;
use crate::syntax::latex::*;
use crate::syntax::text::SyntaxNode;
use crate::workspace::SyntaxTree;
use crate::syntax::SyntaxTree;
use lsp_types::{DocumentHighlight, DocumentHighlightKind, TextDocumentPositionParams};

pub struct LatexLabelHighlightProvider;
Expand Down
2 changes: 1 addition & 1 deletion src/hover/bibtex_field.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::feature::FeatureRequest;
use crate::metadata::bibtex_field;
use crate::syntax::bibtex::*;
use crate::workspace::SyntaxTree;
use crate::syntax::SyntaxTree;
use lsp_types::*;
use std::borrow::Cow;

Expand Down
2 changes: 1 addition & 1 deletion src/hover/latex_citation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::formatting::{BibtexFormatter, BibtexFormattingOptions};
use crate::syntax::bibtex::{BibtexDeclaration, BibtexEntry};
use crate::syntax::latex::{LatexCitationAnalyzer, LatexToken, LatexVisitor};
use crate::syntax::text::SyntaxNode;
use crate::workspace::SyntaxTree;
use crate::syntax::SyntaxTree;
use lsp_types::{Hover, HoverContents, MarkupContent, MarkupKind, TextDocumentPositionParams};
use std::borrow::Cow;

Expand Down
2 changes: 1 addition & 1 deletion src/link/latex_include.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::feature::FeatureRequest;
use crate::syntax::latex::*;
use crate::syntax::text::SyntaxNode;
use crate::workspace::SyntaxTree;
use crate::syntax::SyntaxTree;
use lsp_types::{DocumentLink, DocumentLinkParams};

pub struct LatexIncludeLinkProvider;
Expand Down
2 changes: 1 addition & 1 deletion src/reference/bibtex_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::feature::FeatureRequest;
use crate::syntax::bibtex::BibtexDeclaration;
use crate::syntax::latex::{LatexCitationAnalyzer, LatexVisitor};
use crate::syntax::text::SyntaxNode;
use crate::workspace::SyntaxTree;
use crate::syntax::SyntaxTree;
use lsp_types::{Location, ReferenceParams};

pub struct BibtexEntryReferenceProvider;
Expand Down
2 changes: 1 addition & 1 deletion src/reference/latex_label.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::feature::FeatureRequest;
use crate::syntax::latex::{LatexLabelAnalyzer, LatexLabelKind, LatexVisitor};
use crate::workspace::SyntaxTree;
use crate::syntax::SyntaxTree;
use lsp_types::{Location, ReferenceParams};

pub struct LatexLabelReferenceProvider;
Expand Down
2 changes: 1 addition & 1 deletion src/rename/bibtex_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::feature::FeatureRequest;
use crate::syntax::bibtex::{BibtexDeclaration, BibtexSyntaxTree};
use crate::syntax::latex::{LatexCitationAnalyzer, LatexSyntaxTree, LatexVisitor};
use crate::syntax::text::SyntaxNode;
use crate::workspace::SyntaxTree;
use crate::syntax::SyntaxTree;
use lsp_types::*;
use std::borrow::Cow;
use std::collections::HashMap;
Expand Down
2 changes: 1 addition & 1 deletion src/rename/latex_command.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::feature::FeatureRequest;
use crate::syntax::latex::{LatexCommandAnalyzer, LatexVisitor};
use crate::syntax::text::SyntaxNode;
use crate::workspace::SyntaxTree;
use crate::syntax::SyntaxTree;
use lsp_types::{RenameParams, TextEdit, WorkspaceEdit};
use std::borrow::Cow;
use std::collections::HashMap;
Expand Down
2 changes: 1 addition & 1 deletion src/rename/latex_environment.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::feature::FeatureRequest;
use crate::syntax::latex::{LatexEnvironmentAnalyzer, LatexVisitor};
use crate::syntax::text::SyntaxNode;
use crate::workspace::SyntaxTree;
use crate::syntax::SyntaxTree;
use lsp_types::{RenameParams, TextEdit, WorkspaceEdit};
use std::borrow::Cow;
use std::collections::HashMap;
Expand Down
2 changes: 1 addition & 1 deletion src/rename/latex_label.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::feature::FeatureRequest;
use crate::syntax::latex::{LatexLabelAnalyzer, LatexVisitor};
use crate::syntax::text::SyntaxNode;
use crate::workspace::SyntaxTree;
use crate::syntax::SyntaxTree;
use lsp_types::{RenameParams, TextEdit, WorkspaceEdit};
use std::borrow::Cow;
use std::collections::HashMap;
Expand Down
42 changes: 42 additions & 0 deletions src/syntax/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
pub mod bibtex;
pub mod latex;
pub mod text;

use crate::syntax::bibtex::BibtexSyntaxTree;
use crate::syntax::latex::LatexSyntaxTree;

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Language {
Latex,
Bibtex,
}

impl Language {
pub fn by_extension(extension: &str) -> Option<Self> {
match extension.to_lowercase().as_ref() {
"tex" | "sty" | "cls" => Some(Language::Latex),
"bib" => Some(Language::Bibtex),
_ => None,
}
}

pub fn by_language_id(language_id: &str) -> Option<Self> {
match language_id {
"latex" => Some(Language::Latex),
"bibtex" => Some(Language::Bibtex),
_ => None,
}
}
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum SyntaxTree {
Latex(LatexSyntaxTree),
Bibtex(BibtexSyntaxTree),
}

impl SyntaxTree {
pub fn parse(text: &str, language: Language) -> Self {
match language {
Language::Latex => SyntaxTree::Latex(LatexSyntaxTree::from(text)),
Language::Bibtex => SyntaxTree::Bibtex(BibtexSyntaxTree::from(text)),
}
}
}
41 changes: 1 addition & 40 deletions src/workspace.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::syntax::bibtex::BibtexSyntaxTree;
use crate::syntax::latex::*;
use crate::syntax::{Language, SyntaxTree};
use log::*;
use lsp_types::{TextDocumentItem, Uri};
use path_clean::PathClean;
Expand All @@ -8,45 +8,6 @@ use std::fs;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Language {
Latex,
Bibtex,
}

impl Language {
pub fn by_extension(extension: &str) -> Option<Self> {
match extension.to_lowercase().as_ref() {
"tex" | "sty" | "cls" => Some(Language::Latex),
"bib" => Some(Language::Bibtex),
_ => None,
}
}

pub fn by_language_id(language_id: &str) -> Option<Self> {
match language_id {
"latex" => Some(Language::Latex),
"bibtex" => Some(Language::Bibtex),
_ => None,
}
}
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum SyntaxTree {
Latex(LatexSyntaxTree),
Bibtex(BibtexSyntaxTree),
}

impl SyntaxTree {
pub fn parse(text: &str, language: Language) -> Self {
match language {
Language::Latex => SyntaxTree::Latex(LatexSyntaxTree::from(text)),
Language::Bibtex => SyntaxTree::Bibtex(BibtexSyntaxTree::from(text)),
}
}
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Document {
pub uri: Uri,
Expand Down

0 comments on commit f60b0f5

Please sign in to comment.