Skip to content

Commit

Permalink
test: add tests (#11)
Browse files Browse the repository at this point in the history
Adds tests for most LSP handler methods. Not all are tested, and not all code paths are tested either (e.g. utility functions, shared object language loading, etc.) but the suite is pretty comprehensive other than that. They are about as E2E as possible without mocking an entire LSP client.

Co-authored-by: Riley Bruins <[email protected]>
  • Loading branch information
WillLillis and ribru17 authored Dec 2, 2024
1 parent d4f86d0 commit cccb4e0
Show file tree
Hide file tree
Showing 5 changed files with 1,044 additions and 28 deletions.
21 changes: 10 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ jobs:
components: rustfmt
- run: cargo fmt --check

# TODO: Run this once tests are added
# test:
# name: Test
# runs-on: ubuntu-latest
# timeout-minutes: 10
# needs: build
# steps:
# - uses: actions/checkout@v3
# - uses: dtolnay/[email protected]
# id: toolchain
# - run: cargo test
test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 10
needs: build
steps:
- uses: actions/checkout@v3
- uses: dtolnay/[email protected]
id: toolchain
- run: cargo test
151 changes: 150 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ tree-sitter-query = { git = "https://github.com/tree-sitter-grammars/tree-sitter

[build-dependencies]
cc = "1.1.30"

[dev-dependencies]
pretty_assertions = "1.4.1"
rstest = "0.23.0"
tower = { version = "0.5.1", features = ["util"] }
34 changes: 18 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ use util::{
};

lazy_static! {
static ref SERVER_CAPABILITIES: ServerCapabilities = ServerCapabilities {
text_document_sync: Some(TextDocumentSyncCapability::Kind(
TextDocumentSyncKind::INCREMENTAL,
)),
references_provider: Some(OneOf::Left(true)),
rename_provider: Some(OneOf::Left(true)),
definition_provider: Some(OneOf::Left(true)),
document_formatting_provider: Some(OneOf::Left(true)),
completion_provider: Some(CompletionOptions {
trigger_characters: Some(["@", "\"", "\\", "("].map(ToOwned::to_owned).into()),
..CompletionOptions::default()
}),
document_highlight_provider: Some(OneOf::Left(true)),
..Default::default()
};
static ref ENGINE: Engine = Engine::default();
static ref QUERY_LANGUAGE: Language = tree_sitter_query::LANGUAGE.into();
static ref FORMAT_QUERY: Query = Query::new(
Expand Down Expand Up @@ -309,13 +324,14 @@ struct Backend {
options: Arc<RwLock<Options>>,
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
struct Options {
parser_install_directories: Option<Vec<String>>,
parser_aliases: Option<BTreeMap<String, String>>,
language_retrieval_patterns: Option<Vec<String>>,
}

mod test;
mod util;

#[tower_lsp::async_trait]
Expand All @@ -330,21 +346,7 @@ impl LanguageServer for Backend {
}

Ok(InitializeResult {
capabilities: ServerCapabilities {
text_document_sync: Some(TextDocumentSyncCapability::Kind(
TextDocumentSyncKind::INCREMENTAL,
)),
references_provider: Some(OneOf::Left(true)),
rename_provider: Some(OneOf::Left(true)),
definition_provider: Some(OneOf::Left(true)),
document_formatting_provider: Some(OneOf::Left(true)),
completion_provider: Some(CompletionOptions {
trigger_characters: Some(["@", "\"", "\\", "("].map(ToOwned::to_owned).into()),
..CompletionOptions::default()
}),
document_highlight_provider: Some(OneOf::Left(true)),
..Default::default()
},
capabilities: SERVER_CAPABILITIES.clone(),
..Default::default()
})
}
Expand Down
Loading

0 comments on commit cccb4e0

Please sign in to comment.