Skip to content

Commit

Permalink
move server capaibiltiies into lazy static for shared use between nor…
Browse files Browse the repository at this point in the history
…mal operation and tests
  • Loading branch information
WillLillis committed Nov 27, 2024
1 parent 51fd672 commit 9b72dfd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 40 deletions.
31 changes: 16 additions & 15 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 @@ -331,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
32 changes: 7 additions & 25 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ mod tests {
use std::sync::RwLock;
use tower_lsp::{
lsp_types::{
ClientCapabilities, CompletionOptions, DidChangeConfigurationParams,
DidChangeTextDocumentParams, DidOpenTextDocumentParams, InitializeParams,
InitializeResult, OneOf, PartialResultParams, Position, Range, ReferenceContext,
ReferenceParams, ServerCapabilities, TextDocumentContentChangeEvent,
TextDocumentIdentifier, TextDocumentItem, TextDocumentPositionParams,
TextDocumentSyncCapability, TextDocumentSyncKind, Url, VersionedTextDocumentIdentifier,
WorkDoneProgressParams,
ClientCapabilities, DidChangeConfigurationParams, DidChangeTextDocumentParams,
DidOpenTextDocumentParams, InitializeParams, InitializeResult, PartialResultParams,
Position, Range, ReferenceContext, ReferenceParams, TextDocumentContentChangeEvent,
TextDocumentIdentifier, TextDocumentItem, TextDocumentPositionParams, Url,
VersionedTextDocumentIdentifier, WorkDoneProgressParams,
},
LanguageServer, LspService,
};

use crate::{Backend, Options, QUERY_LANGUAGE};
use crate::{Backend, Options, QUERY_LANGUAGE, SERVER_CAPABILITIES};

lazy_static! {
static ref TEST_URI: Url = Url::parse("file:///tmp/test.scm").unwrap();
Expand Down Expand Up @@ -330,23 +328,7 @@ mod tests {
assert_eq!(
resp,
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

0 comments on commit 9b72dfd

Please sign in to comment.